2 Copyright (c) 2003-2009, 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 : [ CKEDITOR.getUrl( editor.skinPath + '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 // TODO : Implement the colors dialog.
\r
65 // editor.openDialog( '' );
\r
73 var style = new CKEDITOR.style( config['colorButton_' + type + 'Style'], color && { color : color } );
\r
75 editor.fire( 'saveSnapshot' );
\r
77 style.apply( editor.document );
\r
79 style.remove( editor.document );
\r
80 editor.fire( 'saveSnapshot' );
\r
83 // Render the "Automatic" button.
\r
85 '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
\r
86 ' title="', lang.auto, '"' +
\r
87 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
\r
88 ' href="javascript:void(\'', lang.auto, '\')">' +
\r
89 '<table cellspacing=0 cellpadding=0 width="100%">' +
\r
92 '<span class="cke_colorbox" style="background-color:#000"></span>' +
\r
94 '<td colspan=7 align=center>',
\r
100 '<table cellspacing=0 cellpadding=0 width="100%">' );
\r
102 // Render the color boxes.
\r
103 for ( var i = 0 ; i < colors.length ; i++ )
\r
105 if ( ( i % 8 ) === 0 )
\r
106 output.push( '</tr><tr>' );
\r
108 var colorCode = colors[ i ];
\r
109 var colorLabel = editor.lang.colors[ colorCode ] || colorCode;
\r
112 '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' +
\r
113 ' title="', colorLabel, '"' +
\r
114 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'#', colorCode, '\',\'', type, '\'); return false;"' +
\r
115 ' href="javascript:void(\'', colorLabel, '\')">' +
\r
116 '<span class="cke_colorbox" style="background-color:#', colorCode, '"></span>' +
\r
121 // Render the "More Colors" button.
\r
122 if ( config.colorButton_enableMore )
\r
127 '<td colspan=8 align=center>' +
\r
128 '<a class="cke_colormore" _cke_focus=1 hidefocus=true' +
\r
129 ' title="', lang.more, '"' +
\r
130 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'?\',\'', type, '\');return false;"' +
\r
131 ' href="javascript:void(\'', lang.more, '\')">',
\r
134 '</td>' ); // It is later in the code.
\r
137 output.push( '</tr></table>' );
\r
139 return output.join( '' );
\r
145 * Whether to enable the "More Colors..." button in the color selectors.
\r
149 * config.colorButton_enableMore = false;
\r
151 CKEDITOR.config.colorButton_enableMore = false;
\r
154 * Defines the colors to be displayed in the color selectors. It's a string
\r
155 * containing the hexadecimal notation for HTML colors, without the "#" prefix.
\r
157 * @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
159 * // Brazil colors only.
\r
160 * config.colorButton_colors = '00923E,F8C100,28166F';
\r
162 CKEDITOR.config.colorButton_colors =
\r
163 '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
\r
164 'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
\r
165 'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
\r
166 'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
\r
167 'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';
\r
170 * Holds the style definition to be used to apply the text foreground color.
\r
173 * // This is basically the default setting value.
\r
174 * config.colorButton_foreStyle =
\r
176 * element : 'span',
\r
177 * styles : { 'color' : '#(color)' }
\r
180 CKEDITOR.config.colorButton_foreStyle =
\r
183 styles : { 'color' : '#(color)' },
\r
184 overrides : [ { element : 'font', attributes : { 'color' : null } } ]
\r
188 * Holds the style definition to be used to apply the text background color.
\r
191 * // This is basically the default setting value.
\r
192 * config.colorButton_backStyle =
\r
194 * element : 'span',
\r
195 * styles : { 'background-color' : '#(color)' }
\r
198 CKEDITOR.config.colorButton_backStyle =
\r
201 styles : { 'background-color' : '#(color)' }
\r