--- /dev/null
+/*\r
+ * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
+ * Copyright (C) 2003-2008 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
+ * FCKTextColorCommand Class: represents the text color comand. It shows the\r
+ * color selection panel.\r
+ */\r
+\r
+// FCKTextColorCommand Constructor\r
+// type: can be 'ForeColor' or 'BackColor'.\r
+var FCKTextColorCommand = function( type )\r
+{\r
+ this.Name = type == 'ForeColor' ? 'TextColor' : 'BGColor' ;\r
+ this.Type = type ;\r
+\r
+ var oWindow ;\r
+\r
+ if ( FCKBrowserInfo.IsIE )\r
+ oWindow = window ;\r
+ else if ( FCK.ToolbarSet._IFrame )\r
+ oWindow = FCKTools.GetElementWindow( FCK.ToolbarSet._IFrame ) ;\r
+ else\r
+ oWindow = window.parent ;\r
+\r
+ this._Panel = new FCKPanel( oWindow ) ;\r
+ this._Panel.AppendStyleSheet( FCKConfig.SkinEditorCSS ) ;\r
+ this._Panel.MainNode.className = 'FCK_Panel' ;\r
+ this._CreatePanelBody( this._Panel.Document, this._Panel.MainNode ) ;\r
+ FCK.ToolbarSet.ToolbarItems.GetItem( this.Name ).RegisterPanel( this._Panel ) ;\r
+\r
+ FCKTools.DisableSelection( this._Panel.Document.body ) ;\r
+}\r
+\r
+FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement )\r
+{\r
+ // Show the Color Panel at the desired position.\r
+ this._Panel.Show( panelX, panelY, relElement ) ;\r
+}\r
+\r
+FCKTextColorCommand.prototype.SetColor = function( color )\r
+{\r
+ FCKUndo.SaveUndoStep() ;\r
+\r
+ var style = FCKStyles.GetStyle( '_FCK_' +\r
+ ( this.Type == 'ForeColor' ? 'Color' : 'BackColor' ) ) ;\r
+\r
+ if ( !color || color.length == 0 )\r
+ FCK.Styles.RemoveStyle( style ) ;\r
+ else\r
+ {\r
+ style.SetVariable( 'Color', color ) ;\r
+ FCKStyles.ApplyStyle( style ) ;\r
+ }\r
+\r
+ FCKUndo.SaveUndoStep() ;\r
+\r
+ FCK.Focus() ;\r
+ FCK.Events.FireEvent( 'OnSelectionChange' ) ;\r
+}\r
+\r
+FCKTextColorCommand.prototype.GetState = function()\r
+{\r
+ if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
+ return FCK_TRISTATE_DISABLED ;\r
+ return FCK_TRISTATE_OFF ;\r
+}\r
+\r
+function FCKTextColorCommand_OnMouseOver()\r
+{\r
+ this.className = 'ColorSelected' ;\r
+}\r
+\r
+function FCKTextColorCommand_OnMouseOut()\r
+{\r
+ this.className = 'ColorDeselected' ;\r
+}\r
+\r
+function FCKTextColorCommand_OnClick( ev, command, color )\r
+{\r
+ this.className = 'ColorDeselected' ;\r
+ command.SetColor( color ) ;\r
+ command._Panel.Hide() ;\r
+}\r
+\r
+function FCKTextColorCommand_AutoOnClick( ev, command )\r
+{\r
+ this.className = 'ColorDeselected' ;\r
+ command.SetColor( '' ) ;\r
+ command._Panel.Hide() ;\r
+}\r
+\r
+function FCKTextColorCommand_MoreOnClick( ev, command )\r
+{\r
+ this.className = 'ColorDeselected' ;\r
+ command._Panel.Hide() ;\r
+ FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 410, 320,\r
+ FCKTools.Bind( command, command.SetColor ) ) ;\r
+}\r
+\r
+FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv )\r
+{\r
+ function CreateSelectionDiv()\r
+ {\r
+ var oDiv = targetDocument.createElement( "DIV" ) ;\r
+ oDiv.className = 'ColorDeselected' ;\r
+ FCKTools.AddEventListenerEx( oDiv, 'mouseover', FCKTextColorCommand_OnMouseOver ) ;\r
+ FCKTools.AddEventListenerEx( oDiv, 'mouseout', FCKTextColorCommand_OnMouseOut ) ;\r
+\r
+ return oDiv ;\r
+ }\r
+\r
+ // Create the Table that will hold all colors.\r
+ var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ;\r
+ oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug.\r
+ oTable.style.tableLayout = 'fixed' ;\r
+ oTable.cellPadding = 0 ;\r
+ oTable.cellSpacing = 0 ;\r
+ oTable.border = 0 ;\r
+ oTable.width = 150 ;\r
+\r
+ var oCell = oTable.insertRow(-1).insertCell(-1) ;\r
+ oCell.colSpan = 8 ;\r
+\r
+ // Create the Button for the "Automatic" color selection.\r
+ var oDiv = oCell.appendChild( CreateSelectionDiv() ) ;\r
+ oDiv.innerHTML =\r
+ '<table cellspacing="0" cellpadding="0" width="100%" border="0">\\r
+ <tr>\\r
+ <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\\r
+ <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\\r
+ </tr>\\r
+ </table>' ;\r
+\r
+ FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_AutoOnClick, this ) ;\r
+\r
+ // Dirty hack for Opera, Safari and Firefox 3.\r
+ if ( !FCKBrowserInfo.IsIE )\r
+ oDiv.style.width = '96%' ;\r
+\r
+ // Create an array of colors based on the configuration file.\r
+ var aColors = FCKConfig.FontColors.toString().split(',') ;\r
+\r
+ // Create the colors table based on the array.\r
+ var iCounter = 0 ;\r
+ while ( iCounter < aColors.length )\r
+ {\r
+ var oRow = oTable.insertRow(-1) ;\r
+\r
+ for ( var i = 0 ; i < 8 ; i++, iCounter++ )\r
+ {\r
+ // The div will be created even if no more colors are available.\r
+ // Extra divs will be hidden later in the code. (#1597)\r
+ if ( iCounter < aColors.length )\r
+ {\r
+ var colorParts = aColors[iCounter].split('/') ;\r
+ var colorValue = '#' + colorParts[0] ;\r
+ var colorName = colorParts[1] || colorValue ;\r
+ }\r
+\r
+ oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ;\r
+ oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: ' + colorValue + '"></div></div>' ;\r
+\r
+ if ( iCounter >= aColors.length )\r
+ oDiv.style.visibility = 'hidden' ;\r
+ else\r
+ FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_OnClick, [ this, colorName ] ) ;\r
+ }\r
+ }\r
+\r
+ // Create the Row and the Cell for the "More Colors..." button.\r
+ if ( FCKConfig.EnableMoreFontColors )\r
+ {\r
+ oCell = oTable.insertRow(-1).insertCell(-1) ;\r
+ oCell.colSpan = 8 ;\r
+\r
+ oDiv = oCell.appendChild( CreateSelectionDiv() ) ;\r
+ oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ;\r
+\r
+ FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_MoreOnClick, this ) ;\r
+ }\r
+\r
+ // Dirty hack for Opera, Safari and Firefox 3.\r
+ if ( !FCKBrowserInfo.IsIE )\r
+ oDiv.style.width = '96%' ;\r
+}\r