[ Index ] |
|
Code source de FCKeditor 2.4 |
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 * File Name: fcktextcolorcommand.js 22 * FCKTextColorCommand Class: represents the text color comand. It shows the 23 * color selection panel. 24 * 25 * File Authors: 26 * Frederico Caldeira Knabben (www.fckeditor.net) 27 */ 28 29 // FCKTextColorCommand Contructor 30 // type: can be 'ForeColor' or 'BackColor'. 31 var FCKTextColorCommand = function( type ) 32 { 33 this.Name = type == 'ForeColor' ? 'TextColor' : 'BGColor' ; 34 this.Type = type ; 35 36 var oWindow ; 37 38 if ( FCKBrowserInfo.IsIE ) 39 oWindow = window ; 40 else if ( FCK.ToolbarSet._IFrame ) 41 oWindow = FCKTools.GetElementWindow( FCK.ToolbarSet._IFrame ) ; 42 else 43 oWindow = window.parent ; 44 45 this._Panel = new FCKPanel( oWindow, true ) ; 46 this._Panel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ; 47 this._Panel.MainNode.className = 'FCK_Panel' ; 48 this._CreatePanelBody( this._Panel.Document, this._Panel.MainNode ) ; 49 50 FCKTools.DisableSelection( this._Panel.Document.body ) ; 51 } 52 53 FCKTextColorCommand.prototype.Execute = function( panelX, panelY, relElement ) 54 { 55 // We must "cache" the actual panel type to be used in the SetColor method. 56 FCK._ActiveColorPanelType = this.Type ; 57 58 // Show the Color Panel at the desired position. 59 this._Panel.Show( panelX, panelY, relElement ) ; 60 } 61 62 FCKTextColorCommand.prototype.SetColor = function( color ) 63 { 64 if ( FCK._ActiveColorPanelType == 'ForeColor' ) 65 FCK.ExecuteNamedCommand( 'ForeColor', color ) ; 66 else if ( FCKBrowserInfo.IsGeckoLike ) 67 { 68 if ( FCKBrowserInfo.IsGecko && !FCKConfig.GeckoUseSPAN ) 69 FCK.EditorDocument.execCommand( 'useCSS', false, false ) ; 70 71 FCK.ExecuteNamedCommand( 'hilitecolor', color ) ; 72 73 if ( FCKBrowserInfo.IsGecko && !FCKConfig.GeckoUseSPAN ) 74 FCK.EditorDocument.execCommand( 'useCSS', false, true ) ; 75 } 76 else 77 FCK.ExecuteNamedCommand( 'BackColor', color ) ; 78 79 // Delete the "cached" active panel type. 80 delete FCK._ActiveColorPanelType ; 81 } 82 83 FCKTextColorCommand.prototype.GetState = function() 84 { 85 return FCK_TRISTATE_OFF ; 86 } 87 88 function FCKTextColorCommand_OnMouseOver() { this.className='ColorSelected' ; } 89 90 function FCKTextColorCommand_OnMouseOut() { this.className='ColorDeselected' ; } 91 92 function FCKTextColorCommand_OnClick() 93 { 94 this.className = 'ColorDeselected' ; 95 this.Command.SetColor( '#' + this.Color ) ; 96 this.Command._Panel.Hide() ; 97 } 98 99 function FCKTextColorCommand_AutoOnClick() 100 { 101 this.className = 'ColorDeselected' ; 102 this.Command.SetColor( '' ) ; 103 this.Command._Panel.Hide() ; 104 } 105 106 function FCKTextColorCommand_MoreOnClick() 107 { 108 this.className = 'ColorDeselected' ; 109 this.Command._Panel.Hide() ; 110 FCKDialog.OpenDialog( 'FCKDialog_Color', FCKLang.DlgColorTitle, 'dialog/fck_colorselector.html', 400, 330, this.Command.SetColor ) ; 111 } 112 113 FCKTextColorCommand.prototype._CreatePanelBody = function( targetDocument, targetDiv ) 114 { 115 function CreateSelectionDiv() 116 { 117 var oDiv = targetDocument.createElement( "DIV" ) ; 118 oDiv.className = 'ColorDeselected' ; 119 oDiv.onmouseover = FCKTextColorCommand_OnMouseOver ; 120 oDiv.onmouseout = FCKTextColorCommand_OnMouseOut ; 121 122 return oDiv ; 123 } 124 125 // Create the Table that will hold all colors. 126 var oTable = targetDiv.appendChild( targetDocument.createElement( "TABLE" ) ) ; 127 oTable.className = 'ForceBaseFont' ; // Firefox 1.5 Bug. 128 oTable.style.tableLayout = 'fixed' ; 129 oTable.cellPadding = 0 ; 130 oTable.cellSpacing = 0 ; 131 oTable.border = 0 ; 132 oTable.width = 150 ; 133 134 var oCell = oTable.insertRow(-1).insertCell(-1) ; 135 oCell.colSpan = 8 ; 136 137 // Create the Button for the "Automatic" color selection. 138 var oDiv = oCell.appendChild( CreateSelectionDiv() ) ; 139 oDiv.innerHTML = 140 '<table cellspacing="0" cellpadding="0" width="100%" border="0">\ 141 <tr>\ 142 <td><div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #000000"></div></div></td>\ 143 <td nowrap width="100%" align="center">' + FCKLang.ColorAutomatic + '</td>\ 144 </tr>\ 145 </table>' ; 146 147 oDiv.Command = this ; 148 oDiv.onclick = FCKTextColorCommand_AutoOnClick ; 149 150 // Create an array of colors based on the configuration file. 151 var aColors = FCKConfig.FontColors.toString().split(',') ; 152 153 // Create the colors table based on the array. 154 var iCounter = 0 ; 155 while ( iCounter < aColors.length ) 156 { 157 var oRow = oTable.insertRow(-1) ; 158 159 for ( var i = 0 ; i < 8 && iCounter < aColors.length ; i++, iCounter++ ) 160 { 161 oDiv = oRow.insertCell(-1).appendChild( CreateSelectionDiv() ) ; 162 oDiv.Color = aColors[iCounter] ; 163 oDiv.innerHTML = '<div class="ColorBoxBorder"><div class="ColorBox" style="background-color: #' + aColors[iCounter] + '"></div></div>' ; 164 165 oDiv.Command = this ; 166 oDiv.onclick = FCKTextColorCommand_OnClick ; 167 } 168 } 169 170 // Create the Row and the Cell for the "More Colors..." button. 171 oCell = oTable.insertRow(-1).insertCell(-1) ; 172 oCell.colSpan = 8 ; 173 174 oDiv = oCell.appendChild( CreateSelectionDiv() ) ; 175 oDiv.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td nowrap align="center">' + FCKLang.ColorMoreColors + '</td></tr></table>' ; 176 177 oDiv.Command = this ; 178 oDiv.onclick = FCKTextColorCommand_MoreOnClick ; 179 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 15:28:05 2007 | par Balluche grâce à PHPXref 0.7 |