1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 4 * 5 * == BEGIN LICENSE == 6 * 7 * Licensed under the terms of any of the following licenses at your 8 * choice: 9 * 10 * - GNU General Public License Version 2 or later (the "GPL") 11 * http://www.gnu.org/licenses/gpl.html 12 * 13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 14 * http://www.gnu.org/licenses/lgpl.html 15 * 16 * - Mozilla Public License Version 1.1 or later (the "MPL") 17 * http://www.mozilla.org/MPL/MPL-1.1.html 18 * 19 * == END LICENSE == 20 * 21 * FCKTextColorCommand Class: represents the text color comand. It shows the 22 * color selection panel. 23 */ 24 25// FCKTextColorCommand Constructor 26// type: can be 'ForeColor' or 'BackColor'. 27var FCKTextColorCommand = function( type ) 28{ 29 this.Name = type == 'ForeColor' ? 'TextColor' : 'BGColor' ; 30 this.Type = type ; 31 32 var oWindow ; 33 34 if ( FCKBrowserInfo.IsIE ) 35 oWindow = window ; 36 else if ( FCK.ToolbarSet._IFrame ) 37 oWindow = FCKTools.GetElementWindow( FCK.ToolbarSet._IFrame ) ; 38 else 39 oWindow = window.parent ; 40 41 this._Panel = new FCKPanel( oWindow ) ; 42 this._Panel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ; 43 this._Panel.MainNode.className = 'FCK_Panel' ; 44 this._CreatePanelBody( this._Panel.Document, this._Panel.MainNode ) ; 45 46 FCKTools.DisableSelection( this._Panel.Document.body ) ; 47} 48 49FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement ) 50{ 51 // Show the Color Panel at the desired position. 52 this._Panel.Show( panelX, panelY, relElement ) ; 53} 54 55FCKTextColorCommand.prototype.SetColor = function( color ) 56{ 57 var style = FCKStyles.GetStyle( '_FCK_' + 58 ( this.Type == 'ForeColor' ? 'Color' : 'BackColor' ) ) ; 59 60 if ( !color || color.length == 0 ) 61 FCK.Styles.RemoveStyle( style ) ; 62 else 63 { 64 style.SetVariable( 'Color', color ) ; 65 FCKStyles.ApplyStyle( style ) ; 66 } 67 68 FCK.Focus() ; 69 FCK.Events.FireEvent( 'OnSelectionChange' ) ; 70} 71 72FCKTextColorCommand.prototype.GetState = function() 73{ 74 return FCK_TRISTATE_OFF ; 75} 76 77function FCKTextColorCommand_OnMouseOver() 78{ 79 this.className = 'ColorSelected' ; 80} 81 82function FCKTextColorCommand_OnMouseOut() 83{ 84 this.className = 'ColorDeselected' ; 85} 86 87function FCKTextColorCommand_OnClick( ev, command, color ) 88{ 89 this.className = 'ColorDeselected' ; 90 command.SetColor( color ) ; 91 command._Panel.Hide() ; 92} 93 94function FCKTextColorCommand_AutoOnClick( ev, command ) 95{ 96 this.className = 'ColorDeselected' ; 97 command.SetColor( '' ) ; 98 command._Panel.Hide() ; 99} 100 101function FCKTextColorCommand_MoreOnClick( ev, command ) 102{ 103 this.className = 'ColorDeselected' ; 104 command._Panel.Hide() ; 105 FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 400, 330, FCKTools.Hitch(command, 'SetColor') ) ; 106} 107 108FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv ) 109{ 110 function CreateSelectionDiv() 111 { 112 var oDiv = targetDocument.createElement( "DIV" ) ; 113 oDiv.className = 'ColorDeselected' ; 114 FCKTools.AddEventListenerEx( oDiv, 'mouseover', FCKTextColorCommand_OnMouseOver ) ; 115 FCKTools.AddEventListenerEx( oDiv, 'mouseout', FCKTextColorCommand_OnMouseOut ) ; 116 117 return oDiv ; 118 } 119 120 // Create the Table that will hold all colors. 121 var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ; 122 oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug. 123 oTable.style.tableLayout = 'fixed' ; 124 oTable.cellPadding = 0 ; 125 oTable.cellSpacing = 0 ; 126 oTable.border = 0 ; 127 oTable.width = 150 ; 128 129 var oCell = oTable.insertRow(-1).insertCell(-1) ; 130 oCell.colSpan = 8 ; 131 132 // Create the Button for the "Automatic" color selection. 133 var oDiv = oCell.appendChild( CreateSelectionDiv() ) ; 134 oDiv.innerHTML = 135 '<table cellspacing="0" cellpadding="0" width="100%" border="0">\ 136 <tr>\ 137 <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\ 138 <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\ 139 </tr>\ 140 </table>' ; 141 142 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_AutoOnClick, this ) ; 143 144 if ( FCKBrowserInfo.IsSafari ) 145 oDiv.style.width = '96%' ; 146 147 // Create an array of colors based on the configuration file. 148 var aColors = FCKConfig.FontColors.toString().split(',') ; 149 150 // Create the colors table based on the array. 151 var iCounter = 0 ; 152 while ( iCounter < aColors.length ) 153 { 154 var oRow = oTable.insertRow(-1) ; 155 156 for ( var i = 0 ; i < 8 && iCounter < aColors.length ; i++, iCounter++ ) 157 { 158 var colorParts = aColors[iCounter].split('/') ; 159 var colorValue = '#' + colorParts[0] ; 160 var colorName = colorParts[1] || colorValue ; 161 162 oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ; 163 oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: ' + colorValue + '"></div></div>' ; 164 165 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_OnClick, [ this, colorName ] ) ; 166 } 167 } 168 169 // Create the Row and the Cell for the "More Colors..." button. 170 if ( FCKConfig.EnableMoreFontColors ) 171 { 172 oCell = oTable.insertRow(-1).insertCell(-1) ; 173 oCell.colSpan = 8 ; 174 175 oDiv = oCell.appendChild( CreateSelectionDiv() ) ; 176 oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ; 177 178 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_MoreOnClick, this ) ; 179 } 180 181 if ( FCKBrowserInfo.IsSafari ) 182 oDiv.style.width = '96%' ; 183} 184