--- /dev/null
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ * - GNU General Public License Version 2 or later (the "GPL")\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ * http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ * - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ * http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ * FCKSpecialCombo Class: represents a special combo.\r
+ */\r
+\r
+var FCKSpecialCombo = function( caption, fieldWidth, panelWidth, panelMaxHeight, parentWindow )\r
+{\r
+ // Default properties values.\r
+ this.FieldWidth = fieldWidth || 100 ;\r
+ this.PanelWidth = panelWidth || 150 ;\r
+ this.PanelMaxHeight = panelMaxHeight || 150 ;\r
+ this.Label = ' ' ;\r
+ this.Caption = caption ;\r
+ this.Tooltip = caption ;\r
+ this.Style = FCK_TOOLBARITEM_ICONTEXT ;\r
+\r
+ this.Enabled = true ;\r
+\r
+ this.Items = new Object() ;\r
+\r
+ this._Panel = new FCKPanel( parentWindow || window ) ;\r
+ this._Panel.AppendStyleSheet( FCKConfig.SkinEditorCSS ) ;\r
+ this._PanelBox = this._Panel.MainNode.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;\r
+ this._PanelBox.className = 'SC_Panel' ;\r
+ this._PanelBox.style.width = this.PanelWidth + 'px' ;\r
+\r
+ this._PanelBox.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;\r
+\r
+ this._ItemsHolderEl = this._PanelBox.getElementsByTagName('TD')[0] ;\r
+\r
+ if ( FCK.IECleanup )\r
+ FCK.IECleanup.AddItem( this, FCKSpecialCombo_Cleanup ) ;\r
+\r
+// this._Panel.StyleSheet = FCKConfig.SkinPath + 'fck_contextmenu.css' ;\r
+// this._Panel.Create() ;\r
+// this._Panel.PanelDiv.className += ' SC_Panel' ;\r
+// this._Panel.PanelDiv.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;\r
+// this._ItemsHolderEl = this._Panel.PanelDiv.getElementsByTagName('TD')[0] ;\r
+}\r
+\r
+function FCKSpecialCombo_ItemOnMouseOver()\r
+{\r
+ this.className += ' SC_ItemOver' ;\r
+}\r
+\r
+function FCKSpecialCombo_ItemOnMouseOut()\r
+{\r
+ this.className = this.originalClass ;\r
+}\r
+\r
+function FCKSpecialCombo_ItemOnClick( ev, specialCombo, itemId )\r
+{\r
+ this.className = this.originalClass ;\r
+\r
+ specialCombo._Panel.Hide() ;\r
+\r
+ specialCombo.SetLabel( this.FCKItemLabel ) ;\r
+\r
+ if ( typeof( specialCombo.OnSelect ) == 'function' )\r
+ specialCombo.OnSelect( itemId, this ) ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.ClearItems = function ()\r
+{\r
+ if ( this.Items )\r
+ this.Items = {} ;\r
+\r
+ var itemsholder = this._ItemsHolderEl ;\r
+ while ( itemsholder.firstChild )\r
+ itemsholder.removeChild( itemsholder.firstChild ) ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.AddItem = function( id, html, label, bgColor )\r
+{\r
+ // <div class="SC_Item" onmouseover="this.className='SC_Item SC_ItemOver';" onmouseout="this.className='SC_Item';"><b>Bold 1</b></div>\r
+ var oDiv = this._ItemsHolderEl.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;\r
+ oDiv.className = oDiv.originalClass = 'SC_Item' ;\r
+ oDiv.innerHTML = html ;\r
+ oDiv.FCKItemLabel = label || id ;\r
+ oDiv.Selected = false ;\r
+\r
+ // In IE, the width must be set so the borders are shown correctly when the content overflows.\r
+ if ( FCKBrowserInfo.IsIE )\r
+ oDiv.style.width = '100%' ;\r
+\r
+ if ( bgColor )\r
+ oDiv.style.backgroundColor = bgColor ;\r
+\r
+ FCKTools.AddEventListenerEx( oDiv, 'mouseover', FCKSpecialCombo_ItemOnMouseOver ) ;\r
+ FCKTools.AddEventListenerEx( oDiv, 'mouseout', FCKSpecialCombo_ItemOnMouseOut ) ;\r
+ FCKTools.AddEventListenerEx( oDiv, 'click', FCKSpecialCombo_ItemOnClick, [ this, id ] ) ;\r
+\r
+ this.Items[ id.toString().toLowerCase() ] = oDiv ;\r
+\r
+ return oDiv ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.SelectItem = function( item )\r
+{\r
+ if ( typeof item == 'string' )\r
+ item = this.Items[ item.toString().toLowerCase() ] ;\r
+\r
+ if ( item )\r
+ {\r
+ item.className = item.originalClass = 'SC_ItemSelected' ;\r
+ item.Selected = true ;\r
+ }\r
+}\r
+\r
+FCKSpecialCombo.prototype.SelectItemByLabel = function( itemLabel, setLabel )\r
+{\r
+ for ( var id in this.Items )\r
+ {\r
+ var oDiv = this.Items[id] ;\r
+\r
+ if ( oDiv.FCKItemLabel == itemLabel )\r
+ {\r
+ oDiv.className = oDiv.originalClass = 'SC_ItemSelected' ;\r
+ oDiv.Selected = true ;\r
+\r
+ if ( setLabel )\r
+ this.SetLabel( itemLabel ) ;\r
+ }\r
+ }\r
+}\r
+\r
+FCKSpecialCombo.prototype.DeselectAll = function( clearLabel )\r
+{\r
+ for ( var i in this.Items )\r
+ {\r
+ if ( !this.Items[i] ) continue;\r
+ this.Items[i].className = this.Items[i].originalClass = 'SC_Item' ;\r
+ this.Items[i].Selected = false ;\r
+ }\r
+\r
+ if ( clearLabel )\r
+ this.SetLabel( '' ) ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.SetLabelById = function( id )\r
+{\r
+ id = id ? id.toString().toLowerCase() : '' ;\r
+\r
+ var oDiv = this.Items[ id ] ;\r
+ this.SetLabel( oDiv ? oDiv.FCKItemLabel : '' ) ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.SetLabel = function( text )\r
+{\r
+ text = ( !text || text.length == 0 ) ? ' ' : text ;\r
+\r
+ if ( text == this.Label )\r
+ return ;\r
+\r
+ this.Label = text ;\r
+\r
+ var labelEl = this._LabelEl ;\r
+ if ( labelEl )\r
+ {\r
+ labelEl.innerHTML = text ;\r
+\r
+ // It may happen that the label is some HTML, including tags. This\r
+ // would be a problem because when the user click on those tags, the\r
+ // combo will get the selection from the editing area. So we must\r
+ // disable any kind of selection here.\r
+ FCKTools.DisableSelection( labelEl ) ;\r
+ }\r
+}\r
+\r
+FCKSpecialCombo.prototype.SetEnabled = function( isEnabled )\r
+{\r
+ this.Enabled = isEnabled ;\r
+\r
+ // In IE it can happen when the page is reloaded that _OuterTable is null, so check its existence\r
+ if ( this._OuterTable )\r
+ this._OuterTable.className = isEnabled ? '' : 'SC_FieldDisabled' ;\r
+}\r
+\r
+FCKSpecialCombo.prototype.Create = function( targetElement )\r
+{\r
+ var oDoc = FCKTools.GetElementDocument( targetElement ) ;\r
+ var eOuterTable = this._OuterTable = targetElement.appendChild( oDoc.createElement( 'TABLE' ) ) ;\r
+ eOuterTable.cellPadding = 0 ;\r
+ eOuterTable.cellSpacing = 0 ;\r
+\r
+ eOuterTable.insertRow(-1) ;\r
+\r
+ var sClass ;\r
+ var bShowLabel ;\r
+\r
+ switch ( this.Style )\r
+ {\r
+ case FCK_TOOLBARITEM_ONLYICON :\r
+ sClass = 'TB_ButtonType_Icon' ;\r
+ bShowLabel = false;\r
+ break ;\r
+ case FCK_TOOLBARITEM_ONLYTEXT :\r
+ sClass = 'TB_ButtonType_Text' ;\r
+ bShowLabel = false;\r
+ break ;\r
+ case FCK_TOOLBARITEM_ICONTEXT :\r
+ bShowLabel = true;\r
+ break ;\r
+ }\r
+\r
+ if ( this.Caption && this.Caption.length > 0 && bShowLabel )\r
+ {\r
+ var oCaptionCell = eOuterTable.rows[0].insertCell(-1) ;\r
+ oCaptionCell.innerHTML = this.Caption ;\r
+ oCaptionCell.className = 'SC_FieldCaption' ;\r
+ }\r
+\r
+ // Create the main DIV element.\r
+ var oField = FCKTools.AppendElement( eOuterTable.rows[0].insertCell(-1), 'div' ) ;\r
+ if ( bShowLabel )\r
+ {\r
+ oField.className = 'SC_Field' ;\r
+ oField.style.width = this.FieldWidth + 'px' ;\r
+ oField.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldLabel"><label> </label></td><td class="SC_FieldButton"> </td></tr></tbody></table>' ;\r
+\r
+ this._LabelEl = oField.getElementsByTagName('label')[0] ; // Memory Leak\r
+ this._LabelEl.innerHTML = this.Label ;\r
+ }\r
+ else\r
+ {\r
+ oField.className = 'TB_Button_Off' ;\r
+ //oField.innerHTML = '<span className="SC_FieldCaption">' + this.Caption + '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;"> </td></tr></tbody></table>' ;\r
+ //oField.innerHTML = '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;"> </td></tr></tbody></table>' ;\r
+\r
+ // Gets the correct CSS class to use for the specified style (param).\r
+ oField.innerHTML = '<table title="' + this.Tooltip + '" class="' + sClass + '" cellspacing="0" cellpadding="0" border="0">' +\r
+ '<tr>' +\r
+ //'<td class="TB_Icon"><img src="' + FCKConfig.SkinPath + 'toolbar/' + this.Command.Name.toLowerCase() + '.gif" width="21" height="21"></td>' +\r
+ '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +\r
+ '<td class="TB_Text">' + this.Caption + '</td>' +\r
+ '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +\r
+ '<td class="TB_ButtonArrow"><img src="' + FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif" width="5" height="3"></td>' +\r
+ '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +\r
+ '</tr>' +\r
+ '</table>' ;\r
+ }\r
+\r
+\r
+ // Events Handlers\r
+\r
+ FCKTools.AddEventListenerEx( oField, 'mouseover', FCKSpecialCombo_OnMouseOver, this ) ;\r
+ FCKTools.AddEventListenerEx( oField, 'mouseout', FCKSpecialCombo_OnMouseOut, this ) ;\r
+ FCKTools.AddEventListenerEx( oField, 'click', FCKSpecialCombo_OnClick, this ) ;\r
+\r
+ FCKTools.DisableSelection( this._Panel.Document.body ) ;\r
+}\r
+\r
+function FCKSpecialCombo_Cleanup()\r
+{\r
+ this._LabelEl = null ;\r
+ this._OuterTable = null ;\r
+ this._ItemsHolderEl = null ;\r
+ this._PanelBox = null ;\r
+\r
+ if ( this.Items )\r
+ {\r
+ for ( var key in this.Items )\r
+ this.Items[key] = null ;\r
+ }\r
+}\r
+\r
+function FCKSpecialCombo_OnMouseOver( ev, specialCombo )\r
+{\r
+ if ( specialCombo.Enabled )\r
+ {\r
+ switch ( specialCombo.Style )\r
+ {\r
+ case FCK_TOOLBARITEM_ONLYICON :\r
+ this.className = 'TB_Button_On_Over';\r
+ break ;\r
+ case FCK_TOOLBARITEM_ONLYTEXT :\r
+ this.className = 'TB_Button_On_Over';\r
+ break ;\r
+ case FCK_TOOLBARITEM_ICONTEXT :\r
+ this.className = 'SC_Field SC_FieldOver' ;\r
+ break ;\r
+ }\r
+ }\r
+}\r
+\r
+function FCKSpecialCombo_OnMouseOut( ev, specialCombo )\r
+{\r
+ switch ( specialCombo.Style )\r
+ {\r
+ case FCK_TOOLBARITEM_ONLYICON :\r
+ this.className = 'TB_Button_Off';\r
+ break ;\r
+ case FCK_TOOLBARITEM_ONLYTEXT :\r
+ this.className = 'TB_Button_Off';\r
+ break ;\r
+ case FCK_TOOLBARITEM_ICONTEXT :\r
+ this.className='SC_Field' ;\r
+ break ;\r
+ }\r
+}\r
+\r
+function FCKSpecialCombo_OnClick( e, specialCombo )\r
+{\r
+ // For Mozilla we must stop the event propagation to avoid it hiding\r
+ // the panel because of a click outside of it.\r
+// if ( e )\r
+// {\r
+// e.stopPropagation() ;\r
+// FCKPanelEventHandlers.OnDocumentClick( e ) ;\r
+// }\r
+\r
+ if ( specialCombo.Enabled )\r
+ {\r
+ var oPanel = specialCombo._Panel ;\r
+ var oPanelBox = specialCombo._PanelBox ;\r
+ var oItemsHolder = specialCombo._ItemsHolderEl ;\r
+ var iMaxHeight = specialCombo.PanelMaxHeight ;\r
+\r
+ if ( specialCombo.OnBeforeClick )\r
+ specialCombo.OnBeforeClick( specialCombo ) ;\r
+\r
+ // This is a tricky thing. We must call the "Load" function, otherwise\r
+ // it will not be possible to retrieve "oItemsHolder.offsetHeight" (IE only).\r
+ if ( FCKBrowserInfo.IsIE )\r
+ oPanel.Preload( 0, this.offsetHeight, this ) ;\r
+\r
+ if ( oItemsHolder.offsetHeight > iMaxHeight )\r
+// {\r
+ oPanelBox.style.height = iMaxHeight + 'px' ;\r
+\r
+// if ( FCKBrowserInfo.IsGecko )\r
+// oPanelBox.style.overflow = '-moz-scrollbars-vertical' ;\r
+// }\r
+ else\r
+ oPanelBox.style.height = '' ;\r
+\r
+// oPanel.PanelDiv.style.width = specialCombo.PanelWidth + 'px' ;\r
+\r
+ oPanel.Show( 0, this.offsetHeight, this ) ;\r
+ }\r
+\r
+// return false ;\r
+}\r
+\r
+/*\r
+Sample Combo Field HTML output:\r
+\r
+<div class="SC_Field" style="width: 80px;">\r
+ <table width="100%" cellpadding="0" cellspacing="0" style="table-layout: fixed;">\r
+ <tbody>\r
+ <tr>\r
+ <td class="SC_FieldLabel"><label> </label></td>\r
+ <td class="SC_FieldButton"> </td>\r
+ </tr>\r
+ </tbody>\r
+ </table>\r
+</div>\r
+*/\r