2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * FCKTextColorCommand Class: represents the text color comand. It shows the
\r
22 * color selection panel.
\r
25 // FCKTextColorCommand Constructor
\r
26 // type: can be 'ForeColor' or 'BackColor'.
\r
27 var FCKTextColorCommand = function( type )
\r
29 this.Name = type == 'ForeColor' ? 'TextColor' : 'BGColor' ;
\r
34 if ( FCKBrowserInfo.IsIE )
\r
36 else if ( FCK.ToolbarSet._IFrame )
\r
37 oWindow = FCKTools.GetElementWindow( FCK.ToolbarSet._IFrame ) ;
\r
39 oWindow = window.parent ;
\r
41 this._Panel = new FCKPanel( oWindow ) ;
\r
42 this._Panel.AppendStyleSheet( FCKConfig.SkinEditorCSS ) ;
\r
43 this._Panel.MainNode.className = 'FCK_Panel' ;
\r
44 this._CreatePanelBody( this._Panel.Document, this._Panel.MainNode ) ;
\r
45 FCK.ToolbarSet.ToolbarItems.GetItem( this.Name ).RegisterPanel( this._Panel ) ;
\r
47 FCKTools.DisableSelection( this._Panel.Document.body ) ;
\r
50 FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement )
\r
52 // Show the Color Panel at the desired position.
\r
53 this._Panel.Show( panelX, panelY, relElement ) ;
\r
56 FCKTextColorCommand.prototype.SetColor = function( color )
\r
58 FCKUndo.SaveUndoStep() ;
\r
60 var style = FCKStyles.GetStyle( '_FCK_' +
\r
61 ( this.Type == 'ForeColor' ? 'Color' : 'BackColor' ) ) ;
\r
63 if ( !color || color.length == 0 )
\r
64 FCK.Styles.RemoveStyle( style ) ;
\r
67 style.SetVariable( 'Color', color ) ;
\r
68 FCKStyles.ApplyStyle( style ) ;
\r
71 FCKUndo.SaveUndoStep() ;
\r
74 FCK.Events.FireEvent( 'OnSelectionChange' ) ;
\r
77 FCKTextColorCommand.prototype.GetState = function()
\r
79 if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
\r
80 return FCK_TRISTATE_DISABLED ;
\r
81 return FCK_TRISTATE_OFF ;
\r
84 function FCKTextColorCommand_OnMouseOver()
\r
86 this.className = 'ColorSelected' ;
\r
89 function FCKTextColorCommand_OnMouseOut()
\r
91 this.className = 'ColorDeselected' ;
\r
94 function FCKTextColorCommand_OnClick( ev, command, color )
\r
96 this.className = 'ColorDeselected' ;
\r
97 command.SetColor( color ) ;
\r
98 command._Panel.Hide() ;
\r
101 function FCKTextColorCommand_AutoOnClick( ev, command )
\r
103 this.className = 'ColorDeselected' ;
\r
104 command.SetColor( '' ) ;
\r
105 command._Panel.Hide() ;
\r
108 function FCKTextColorCommand_MoreOnClick( ev, command )
\r
110 this.className = 'ColorDeselected' ;
\r
111 command._Panel.Hide() ;
\r
112 FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 410, 320,
\r
113 FCKTools.Bind( command, command.SetColor ) ) ;
\r
116 FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv )
\r
118 function CreateSelectionDiv()
\r
120 var oDiv = targetDocument.createElement( "DIV" ) ;
\r
121 oDiv.className = 'ColorDeselected' ;
\r
122 FCKTools.AddEventListenerEx( oDiv, 'mouseover', FCKTextColorCommand_OnMouseOver ) ;
\r
123 FCKTools.AddEventListenerEx( oDiv, 'mouseout', FCKTextColorCommand_OnMouseOut ) ;
\r
128 // Create the Table that will hold all colors.
\r
129 var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ;
\r
130 oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug.
\r
131 oTable.style.tableLayout = 'fixed' ;
\r
132 oTable.cellPadding = 0 ;
\r
133 oTable.cellSpacing = 0 ;
\r
134 oTable.border = 0 ;
\r
135 oTable.width = 150 ;
\r
137 var oCell = oTable.insertRow(-1).insertCell(-1) ;
\r
138 oCell.colSpan = 8 ;
\r
140 // Create the Button for the "Automatic" color selection.
\r
141 var oDiv = oCell.appendChild( CreateSelectionDiv() ) ;
\r
143 '<table cellspacing="0" cellpadding="0" width="100%" border="0">\
\r
145 <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\
\r
146 <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\
\r
150 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_AutoOnClick, this ) ;
\r
152 // Dirty hack for Opera, Safari and Firefox 3.
\r
153 if ( !FCKBrowserInfo.IsIE )
\r
154 oDiv.style.width = '96%' ;
\r
156 // Create an array of colors based on the configuration file.
\r
157 var aColors = FCKConfig.FontColors.toString().split(',') ;
\r
159 // Create the colors table based on the array.
\r
161 while ( iCounter < aColors.length )
\r
163 var oRow = oTable.insertRow(-1) ;
\r
165 for ( var i = 0 ; i < 8 ; i++, iCounter++ )
\r
167 // The div will be created even if no more colors are available.
\r
168 // Extra divs will be hidden later in the code. (#1597)
\r
169 if ( iCounter < aColors.length )
\r
171 var colorParts = aColors[iCounter].split('/') ;
\r
172 var colorValue = '#' + colorParts[0] ;
\r
173 var colorName = colorParts[1] || colorValue ;
\r
176 oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ;
\r
177 oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: ' + colorValue + '"></div></div>' ;
\r
179 if ( iCounter >= aColors.length )
\r
180 oDiv.style.visibility = 'hidden' ;
\r
182 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_OnClick, [ this, colorName ] ) ;
\r
186 // Create the Row and the Cell for the "More Colors..." button.
\r
187 if ( FCKConfig.EnableMoreFontColors )
\r
189 oCell = oTable.insertRow(-1).insertCell(-1) ;
\r
190 oCell.colSpan = 8 ;
\r
192 oDiv = oCell.appendChild( CreateSelectionDiv() ) ;
\r
193 oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ;
\r
195 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_MoreOnClick, this ) ;
\r
198 // Dirty hack for Opera, Safari and Firefox 3.
\r
199 if ( !FCKBrowserInfo.IsIE )
\r
200 oDiv.style.width = '96%' ;
\r