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