1 | /*
|
---|
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
3 | * Copyright (C) 2003-2009 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'.
|
---|
27 | var 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.SkinEditorCSS ) ;
|
---|
43 | this._Panel.MainNode.className = 'FCK_Panel' ;
|
---|
44 | this._CreatePanelBody( this._Panel.Document, this._Panel.MainNode ) ;
|
---|
45 | FCK.ToolbarSet.ToolbarItems.GetItem( this.Name ).RegisterPanel( this._Panel ) ;
|
---|
46 |
|
---|
47 | FCKTools.DisableSelection( this._Panel.Document.body ) ;
|
---|
48 | }
|
---|
49 |
|
---|
50 | FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement )
|
---|
51 | {
|
---|
52 | // Show the Color Panel at the desired position.
|
---|
53 | this._Panel.Show( panelX, panelY, relElement ) ;
|
---|
54 | }
|
---|
55 |
|
---|
56 | FCKTextColorCommand.prototype.SetColor = function( color )
|
---|
57 | {
|
---|
58 | FCKUndo.SaveUndoStep() ;
|
---|
59 |
|
---|
60 | var style = FCKStyles.GetStyle( '_FCK_' +
|
---|
61 | ( this.Type == 'ForeColor' ? 'Color' : 'BackColor' ) ) ;
|
---|
62 |
|
---|
63 | if ( !color || color.length == 0 )
|
---|
64 | FCK.Styles.RemoveStyle( style ) ;
|
---|
65 | else
|
---|
66 | {
|
---|
67 | style.SetVariable( 'Color', color ) ;
|
---|
68 | FCKStyles.ApplyStyle( style ) ;
|
---|
69 | }
|
---|
70 |
|
---|
71 | FCKUndo.SaveUndoStep() ;
|
---|
72 |
|
---|
73 | FCK.Focus() ;
|
---|
74 | FCK.Events.FireEvent( 'OnSelectionChange' ) ;
|
---|
75 | }
|
---|
76 |
|
---|
77 | FCKTextColorCommand.prototype.GetState = function()
|
---|
78 | {
|
---|
79 | if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
|
---|
80 | return FCK_TRISTATE_DISABLED ;
|
---|
81 | return FCK_TRISTATE_OFF ;
|
---|
82 | }
|
---|
83 |
|
---|
84 | function FCKTextColorCommand_OnMouseOver()
|
---|
85 | {
|
---|
86 | this.className = 'ColorSelected' ;
|
---|
87 | }
|
---|
88 |
|
---|
89 | function FCKTextColorCommand_OnMouseOut()
|
---|
90 | {
|
---|
91 | this.className = 'ColorDeselected' ;
|
---|
92 | }
|
---|
93 |
|
---|
94 | function FCKTextColorCommand_OnClick( ev, command, color )
|
---|
95 | {
|
---|
96 | this.className = 'ColorDeselected' ;
|
---|
97 | command.SetColor( color ) ;
|
---|
98 | command._Panel.Hide() ;
|
---|
99 | }
|
---|
100 |
|
---|
101 | function FCKTextColorCommand_AutoOnClick( ev, command )
|
---|
102 | {
|
---|
103 | this.className = 'ColorDeselected' ;
|
---|
104 | command.SetColor( '' ) ;
|
---|
105 | command._Panel.Hide() ;
|
---|
106 | }
|
---|
107 |
|
---|
108 | function FCKTextColorCommand_MoreOnClick( ev, command )
|
---|
109 | {
|
---|
110 | this.className = 'ColorDeselected' ;
|
---|
111 | command._Panel.Hide() ;
|
---|
112 | FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 410, 320,
|
---|
113 | FCKTools.Bind( command, command.SetColor ) ) ;
|
---|
114 | }
|
---|
115 |
|
---|
116 | FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv )
|
---|
117 | {
|
---|
118 | function CreateSelectionDiv()
|
---|
119 | {
|
---|
120 | var oDiv = targetDocument.createElement( "DIV" ) ;
|
---|
121 | oDiv.className = 'ColorDeselected' ;
|
---|
122 | FCKTools.AddEventListenerEx( oDiv, 'mouseover', FCKTextColorCommand_OnMouseOver ) ;
|
---|
123 | FCKTools.AddEventListenerEx( oDiv, 'mouseout', FCKTextColorCommand_OnMouseOut ) ;
|
---|
124 |
|
---|
125 | return oDiv ;
|
---|
126 | }
|
---|
127 |
|
---|
128 | // Create the Table that will hold all colors.
|
---|
129 | var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ;
|
---|
130 | oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug.
|
---|
131 | oTable.style.tableLayout = 'fixed' ;
|
---|
132 | oTable.cellPadding = 0 ;
|
---|
133 | oTable.cellSpacing = 0 ;
|
---|
134 | oTable.border = 0 ;
|
---|
135 | oTable.width = 150 ;
|
---|
136 |
|
---|
137 | var oCell = oTable.insertRow(-1).insertCell(-1) ;
|
---|
138 | oCell.colSpan = 8 ;
|
---|
139 |
|
---|
140 | // Create the Button for the "Automatic" color selection.
|
---|
141 | var oDiv = oCell.appendChild( CreateSelectionDiv() ) ;
|
---|
142 | oDiv.innerHTML =
|
---|
143 | '<table cellspacing="0" cellpadding="0" width="100%" border="0">\
|
---|
144 | <tr>\
|
---|
145 | <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\
|
---|
146 | <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\
|
---|
147 | </tr>\
|
---|
148 | </table>' ;
|
---|
149 |
|
---|
150 | FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_AutoOnClick, this ) ;
|
---|
151 |
|
---|
152 | // Dirty hack for Opera, Safari and Firefox 3.
|
---|
153 | if ( !FCKBrowserInfo.IsIE )
|
---|
154 | oDiv.style.width = '96%' ;
|
---|
155 |
|
---|
156 | // Create an array of colors based on the configuration file.
|
---|
157 | var aColors = FCKConfig.FontColors.toString().split(',') ;
|
---|
158 |
|
---|
159 | // Create the colors table based on the array.
|
---|
160 | var iCounter = 0 ;
|
---|
161 | while ( iCounter < aColors.length )
|
---|
162 | {
|
---|
163 | var oRow = oTable.insertRow(-1) ;
|
---|
164 |
|
---|
165 | for ( var i = 0 ; i < 8 ; i++, iCounter++ )
|
---|
166 | {
|
---|
167 | // The div will be created even if no more colors are available.
|
---|
168 | // Extra divs will be hidden later in the code. (#1597)
|
---|
169 | if ( iCounter < aColors.length )
|
---|
170 | {
|
---|
171 | var colorParts = aColors[iCounter].split('/') ;
|
---|
172 | var colorValue = '#' + colorParts[0] ;
|
---|
173 | var colorName = colorParts[1] || colorValue ;
|
---|
174 | }
|
---|
175 |
|
---|
176 | oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ;
|
---|
177 | oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: ' + colorValue + '"></div></div>' ;
|
---|
178 |
|
---|
179 | if ( iCounter >= aColors.length )
|
---|
180 | oDiv.style.visibility = 'hidden' ;
|
---|
181 | else
|
---|
182 | FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_OnClick, [ this, colorName ] ) ;
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | // Create the Row and the Cell for the "More Colors..." button.
|
---|
187 | if ( FCKConfig.EnableMoreFontColors )
|
---|
188 | {
|
---|
189 | oCell = oTable.insertRow(-1).insertCell(-1) ;
|
---|
190 | oCell.colSpan = 8 ;
|
---|
191 |
|
---|
192 | oDiv = oCell.appendChild( CreateSelectionDiv() ) ;
|
---|
193 | oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ;
|
---|
194 |
|
---|
195 | FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_MoreOnClick, this ) ;
|
---|
196 |
|
---|
197 | // Dirty hack for Opera, Safari and Firefox 3.
|
---|
198 | if ( !FCKBrowserInfo.IsIE )
|
---|
199 | oDiv.style.width = '96%' ;
|
---|
200 | }
|
---|
201 | }
|
---|