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 Contructor |
---|
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, true ) ; |
---|
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 | |
---|
49 | FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement ) |
---|
50 | { |
---|
51 | // We must "cache" the actual panel type to be used in the SetColor method. |
---|
52 | FCK._ActiveColorPanelType = this.Type ; |
---|
53 | |
---|
54 | // Show the Color Panel at the desired position. |
---|
55 | this._Panel.Show( panelX, panelY, relElement ) ; |
---|
56 | } |
---|
57 | |
---|
58 | FCKTextColorCommand.prototype.SetColor = function( color ) |
---|
59 | { |
---|
60 | if ( FCK._ActiveColorPanelType == 'ForeColor' ) |
---|
61 | FCK.ExecuteNamedCommand( 'ForeColor', color ) ; |
---|
62 | else if ( FCKBrowserInfo.IsGeckoLike ) |
---|
63 | { |
---|
64 | if ( FCKBrowserInfo.IsGecko && !FCKConfig.GeckoUseSPAN ) |
---|
65 | FCK.EditorDocument.execCommand( 'useCSS', false, false ) ; |
---|
66 | |
---|
67 | FCK.ExecuteNamedCommand( 'hilitecolor', color ) ; |
---|
68 | |
---|
69 | if ( FCKBrowserInfo.IsGecko && !FCKConfig.GeckoUseSPAN ) |
---|
70 | FCK.EditorDocument.execCommand( 'useCSS', false, true ) ; |
---|
71 | } |
---|
72 | else |
---|
73 | FCK.ExecuteNamedCommand( 'BackColor', color ) ; |
---|
74 | |
---|
75 | // Delete the "cached" active panel type. |
---|
76 | delete FCK._ActiveColorPanelType ; |
---|
77 | } |
---|
78 | |
---|
79 | FCKTextColorCommand.prototype.GetState = function() |
---|
80 | { |
---|
81 | return FCK_TRISTATE_OFF ; |
---|
82 | } |
---|
83 | |
---|
84 | function FCKTextColorCommand_OnMouseOver() { this.className='ColorSelected' ; } |
---|
85 | |
---|
86 | function FCKTextColorCommand_OnMouseOut() { this.className='ColorDeselected' ; } |
---|
87 | |
---|
88 | function FCKTextColorCommand_OnClick() |
---|
89 | { |
---|
90 | this.className = 'ColorDeselected' ; |
---|
91 | this.Command.SetColor( '#' + this.Color ) ; |
---|
92 | this.Command._Panel.Hide() ; |
---|
93 | } |
---|
94 | |
---|
95 | function FCKTextColorCommand_AutoOnClick() |
---|
96 | { |
---|
97 | this.className = 'ColorDeselected' ; |
---|
98 | this.Command.SetColor( '' ) ; |
---|
99 | this.Command._Panel.Hide() ; |
---|
100 | } |
---|
101 | |
---|
102 | function FCKTextColorCommand_MoreOnClick() |
---|
103 | { |
---|
104 | this.className = 'ColorDeselected' ; |
---|
105 | this.Command._Panel.Hide() ; |
---|
106 | FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 400, 330, this.Command.SetColor ) ; |
---|
107 | } |
---|
108 | |
---|
109 | FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv ) |
---|
110 | { |
---|
111 | function CreateSelectionDiv() |
---|
112 | { |
---|
113 | var oDiv = targetDocument.createElement( "DIV" ) ; |
---|
114 | oDiv.className = 'ColorDeselected' ; |
---|
115 | oDiv.onmouseover = FCKTextColorCommand_OnMouseOver ; |
---|
116 | oDiv.onmouseout = FCKTextColorCommand_OnMouseOut ; |
---|
117 | |
---|
118 | return oDiv ; |
---|
119 | } |
---|
120 | |
---|
121 | // Create the Table that will hold all colors. |
---|
122 | var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ; |
---|
123 | oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug. |
---|
124 | oTable.style.tableLayout = 'fixed' ; |
---|
125 | oTable.cellPadding = 0 ; |
---|
126 | oTable.cellSpacing = 0 ; |
---|
127 | oTable.border = 0 ; |
---|
128 | oTable.width = 150 ; |
---|
129 | |
---|
130 | var oCell = oTable.insertRow(-1).insertCell(-1) ; |
---|
131 | oCell.colSpan = 8 ; |
---|
132 | |
---|
133 | // Create the Button for the "Automatic" color selection. |
---|
134 | var oDiv = oCell.appendChild( CreateSelectionDiv() ) ; |
---|
135 | oDiv.innerHTML = |
---|
136 | '<table cellspacing="0" cellpadding="0" width="100%" border="0">\ |
---|
137 | <tr>\ |
---|
138 | <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\ |
---|
139 | <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\ |
---|
140 | </tr>\ |
---|
141 | </table>' ; |
---|
142 | |
---|
143 | oDiv.Command = this ; |
---|
144 | oDiv.onclick = FCKTextColorCommand_AutoOnClick ; |
---|
145 | |
---|
146 | // Create an array of colors based on the configuration file. |
---|
147 | var aColors = FCKConfig.FontColors.toString().split(',') ; |
---|
148 | |
---|
149 | // Create the colors table based on the array. |
---|
150 | var iCounter = 0 ; |
---|
151 | while ( iCounter < aColors.length ) |
---|
152 | { |
---|
153 | var oRow = oTable.insertRow(-1) ; |
---|
154 | |
---|
155 | for ( var i = 0 ; i < 8 && iCounter < aColors.length ; i++, iCounter++ ) |
---|
156 | { |
---|
157 | oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ; |
---|
158 | oDiv.Color = aColors[iCounter] ; |
---|
159 | oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #' + aColors[iCounter] + '"></div></div>' ; |
---|
160 | |
---|
161 | oDiv.Command = this ; |
---|
162 | oDiv.onclick = FCKTextColorCommand_OnClick ; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | // Create the Row and the Cell for the "More Colors..." button. |
---|
167 | oCell = oTable.insertRow(-1).insertCell(-1) ; |
---|
168 | oCell.colSpan = 8 ; |
---|
169 | |
---|
170 | oDiv = oCell.appendChild( CreateSelectionDiv() ) ; |
---|
171 | oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ; |
---|
172 | |
---|
173 | oDiv.Command = this ; |
---|
174 | oDiv.onclick = FCKTextColorCommand_MoreOnClick ; |
---|
175 | } |
---|