2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.plugins.add( 'colorbutton',
\r
8 requires : [ 'panelbutton', 'floatpanel', 'styles' ],
\r
10 init : function( editor )
\r
12 var config = editor.config,
\r
13 lang = editor.lang.colorButton;
\r
17 if ( !CKEDITOR.env.hc )
\r
19 addButton( 'TextColor', 'fore', lang.textColorTitle );
\r
20 addButton( 'BGColor', 'back', lang.bgColorTitle );
\r
23 function addButton( name, type, title )
\r
25 editor.ui.add( name, CKEDITOR.UI_PANELBUTTON,
\r
29 className : 'cke_button_' + name.toLowerCase(),
\r
30 modes : { wysiwyg : 1 },
\r
34 css : editor.skin.editor.css
\r
37 onBlock : function( panel, blockName )
\r
39 var block = panel.addBlock( blockName );
\r
40 block.autoSize = true;
\r
41 block.element.addClass( 'cke_colorblock' );
\r
42 block.element.setHtml( renderColors( panel, type ) );
\r
44 var keys = block.keys;
\r
45 keys[ 39 ] = 'next'; // ARROW-RIGHT
\r
46 keys[ 9 ] = 'next'; // TAB
\r
47 keys[ 37 ] = 'prev'; // ARROW-LEFT
\r
48 keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB
\r
49 keys[ 32 ] = 'click'; // SPACE
\r
55 function renderColors( panel, type )
\r
58 colors = config.colorButton_colors.split( ',' );
\r
60 var clickFn = CKEDITOR.tools.addFunction( function( color, type )
\r
64 var applyColorStyle = arguments.callee;
\r
65 function onColorDialogClose( evt )
\r
67 this.removeListener( 'ok', onColorDialogClose );
\r
68 this.removeListener( 'cancel', onColorDialogClose );
\r
70 evt.name == 'ok' && applyColorStyle( this.getContentElement( 'picker', 'selectedColor' ).getValue(), type );
\r
73 editor.openDialog( 'colordialog', function()
\r
75 this.on( 'ok', onColorDialogClose );
\r
76 this.on( 'cancel', onColorDialogClose );
\r
86 var style = new CKEDITOR.style( config['colorButton_' + type + 'Style'], color && { color : color } );
\r
88 editor.fire( 'saveSnapshot' );
\r
90 style.apply( editor.document );
\r
92 style.remove( editor.document );
\r
93 editor.fire( 'saveSnapshot' );
\r
96 // Render the "Automatic" button.
\r
98 '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
\r
99 ' title="', lang.auto, '"' +
\r
100 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
\r
101 ' href="javascript:void(\'', lang.auto, '\')">' +
\r
102 '<table cellspacing=0 cellpadding=0 width="100%">' +
\r
105 '<span class="cke_colorbox" style="background-color:#000"></span>' +
\r
107 '<td colspan=7 align=center>',
\r
113 '<table cellspacing=0 cellpadding=0 width="100%">' );
\r
115 // Render the color boxes.
\r
116 for ( var i = 0 ; i < colors.length ; i++ )
\r
118 if ( ( i % 8 ) === 0 )
\r
119 output.push( '</tr><tr>' );
\r
121 var colorCode = colors[ i ];
\r
122 var colorLabel = editor.lang.colors[ colorCode ] || colorCode;
\r
125 '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' +
\r
126 ' title="', colorLabel, '"' +
\r
127 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'#', colorCode, '\',\'', type, '\'); return false;"' +
\r
128 ' href="javascript:void(\'', colorLabel, '\')">' +
\r
129 '<span class="cke_colorbox" style="background-color:#', colorCode, '"></span>' +
\r
134 // Render the "More Colors" button.
\r
135 if ( config.colorButton_enableMore )
\r
140 '<td colspan=8 align=center>' +
\r
141 '<a class="cke_colormore" _cke_focus=1 hidefocus=true' +
\r
142 ' title="', lang.more, '"' +
\r
143 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'?\',\'', type, '\');return false;"' +
\r
144 ' href="javascript:void(\'', lang.more, '\')">',
\r
147 '</td>' ); // It is later in the code.
\r
150 output.push( '</tr></table>' );
\r
152 return output.join( '' );
\r
158 * Whether to enable the "More Colors..." button in the color selectors.
\r
162 * config.colorButton_enableMore = false;
\r
164 CKEDITOR.config.colorButton_enableMore = true;
\r
167 * Defines the colors to be displayed in the color selectors. It's a string
\r
168 * containing the hexadecimal notation for HTML colors, without the "#" prefix.
\r
170 * @default '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF'
\r
172 * // Brazil colors only.
\r
173 * config.colorButton_colors = '00923E,F8C100,28166F';
\r
175 CKEDITOR.config.colorButton_colors =
\r
176 '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
\r
177 'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
\r
178 'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
\r
179 'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
\r
180 'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';
\r
183 * Holds the style definition to be used to apply the text foreground color.
\r
186 * // This is basically the default setting value.
\r
187 * config.colorButton_foreStyle =
\r
189 * element : 'span',
\r
190 * styles : { 'color' : '#(color)' }
\r
193 CKEDITOR.config.colorButton_foreStyle =
\r
196 styles : { 'color' : '#(color)' },
\r
197 overrides : [ { element : 'font', attributes : { 'color' : null } } ],
\r
199 // Fore color style must be applied inside links instead of around it.
\r
200 childRule : function( element )
\r
202 return element.getName() != 'a';
\r
207 * Holds the style definition to be used to apply the text background color.
\r
210 * // This is basically the default setting value.
\r
211 * config.colorButton_backStyle =
\r
213 * element : 'span',
\r
214 * styles : { 'background-color' : '#(color)' }
\r
217 CKEDITOR.config.colorButton_backStyle =
\r
220 styles : { 'background-color' : '#(color)' }
\r