import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / commandclasses / fcktextcolorcommand.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * FCKTextColorCommand Class: represents the text color comand. It shows the\r
22  * color selection panel.\r
23  */\r
24 \r
25 // FCKTextColorCommand Constructor\r
26 //              type: can be 'ForeColor' or 'BackColor'.\r
27 var FCKTextColorCommand = function( type )\r
28 {\r
29         this.Name = type == 'ForeColor' ? 'TextColor' : 'BGColor' ;\r
30         this.Type = type ;\r
31 \r
32         var oWindow ;\r
33 \r
34         if ( FCKBrowserInfo.IsIE )\r
35                 oWindow = window ;\r
36         else if ( FCK.ToolbarSet._IFrame )\r
37                 oWindow = FCKTools.GetElementWindow( FCK.ToolbarSet._IFrame ) ;\r
38         else\r
39                 oWindow = window.parent ;\r
40 \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
46 \r
47         FCKTools.DisableSelection( this._Panel.Document.body ) ;\r
48 }\r
49 \r
50 FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement )\r
51 {\r
52         // Show the Color Panel at the desired position.\r
53         this._Panel.Show( panelX, panelY, relElement ) ;\r
54 }\r
55 \r
56 FCKTextColorCommand.prototype.SetColor = function( color )\r
57 {\r
58         FCKUndo.SaveUndoStep() ;\r
59 \r
60         var style = FCKStyles.GetStyle( '_FCK_' +\r
61                 ( this.Type == 'ForeColor' ? 'Color' : 'BackColor' ) ) ;\r
62 \r
63         if ( !color || color.length == 0 )\r
64                 FCK.Styles.RemoveStyle( style ) ;\r
65         else\r
66         {\r
67                 style.SetVariable( 'Color', color ) ;\r
68                 FCKStyles.ApplyStyle( style ) ;\r
69         }\r
70 \r
71         FCKUndo.SaveUndoStep() ;\r
72 \r
73         FCK.Focus() ;\r
74         FCK.Events.FireEvent( 'OnSelectionChange' ) ;\r
75 }\r
76 \r
77 FCKTextColorCommand.prototype.GetState = function()\r
78 {\r
79         if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )\r
80                 return FCK_TRISTATE_DISABLED ;\r
81         return FCK_TRISTATE_OFF ;\r
82 }\r
83 \r
84 function FCKTextColorCommand_OnMouseOver()\r
85 {\r
86         this.className = 'ColorSelected' ;\r
87 }\r
88 \r
89 function FCKTextColorCommand_OnMouseOut()\r
90 {\r
91         this.className = 'ColorDeselected' ;\r
92 }\r
93 \r
94 function FCKTextColorCommand_OnClick( ev, command, color )\r
95 {\r
96         this.className = 'ColorDeselected' ;\r
97         command.SetColor( color ) ;\r
98         command._Panel.Hide() ;\r
99 }\r
100 \r
101 function FCKTextColorCommand_AutoOnClick( ev, command )\r
102 {\r
103         this.className = 'ColorDeselected' ;\r
104         command.SetColor( '' ) ;\r
105         command._Panel.Hide() ;\r
106 }\r
107 \r
108 function FCKTextColorCommand_MoreOnClick( ev, command )\r
109 {\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
114 }\r
115 \r
116 FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv )\r
117 {\r
118         function CreateSelectionDiv()\r
119         {\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
124 \r
125                 return oDiv ;\r
126         }\r
127 \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
136 \r
137         var oCell = oTable.insertRow(-1).insertCell(-1) ;\r
138         oCell.colSpan = 8 ;\r
139 \r
140         // Create the Button for the "Automatic" color selection.\r
141         var oDiv = oCell.appendChild( CreateSelectionDiv() ) ;\r
142         oDiv.innerHTML =\r
143                 '<table cellspacing="0" cellpadding="0" width="100%" border="0">\\r
144                         <tr>\\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
147                         </tr>\\r
148                 </table>' ;\r
149 \r
150         FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_AutoOnClick, this ) ;\r
151 \r
152         // Dirty hack for Opera, Safari and Firefox 3.\r
153         if ( !FCKBrowserInfo.IsIE )\r
154                 oDiv.style.width = '96%' ;\r
155 \r
156         // Create an array of colors based on the configuration file.\r
157         var aColors = FCKConfig.FontColors.toString().split(',') ;\r
158 \r
159         // Create the colors table based on the array.\r
160         var iCounter = 0 ;\r
161         while ( iCounter < aColors.length )\r
162         {\r
163                 var oRow = oTable.insertRow(-1) ;\r
164 \r
165                 for ( var i = 0 ; i < 8 ; i++, iCounter++ )\r
166                 {\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
170                         {\r
171                                 var colorParts = aColors[iCounter].split('/') ;\r
172                                 var colorValue = '#' + colorParts[0] ;\r
173                                 var colorName = colorParts[1] || colorValue ;\r
174                         }\r
175 \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
178 \r
179                         if ( iCounter >= aColors.length )\r
180                                 oDiv.style.visibility = 'hidden' ;\r
181                         else\r
182                                 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_OnClick, [ this, colorName ] ) ;\r
183                 }\r
184         }\r
185 \r
186         // Create the Row and the Cell for the "More Colors..." button.\r
187         if ( FCKConfig.EnableMoreFontColors )\r
188         {\r
189                 oCell = oTable.insertRow(-1).insertCell(-1) ;\r
190                 oCell.colSpan = 8 ;\r
191 \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
194 \r
195                 FCKTools.AddEventListenerEx( oDiv, 'click', FCKTextColorCommand_MoreOnClick, this ) ;\r
196         }\r
197 \r
198         // Dirty hack for Opera, Safari and Firefox 3.\r
199         if ( !FCKBrowserInfo.IsIE )\r
200                 oDiv.style.width = '96%' ;\r
201 }\r