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
35 attributes : { role : 'listbox', 'aria-label' : lang.panelTitle }
\r
38 onBlock : function( panel, block )
\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[ 40 ] = 'next'; // ARROW-DOWN
\r
47 keys[ 9 ] = 'next'; // TAB
\r
48 keys[ 37 ] = 'prev'; // ARROW-LEFT
\r
49 keys[ 38 ] = 'prev'; // ARROW-UP
\r
50 keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB
\r
51 keys[ 32 ] = 'click'; // SPACE
\r
57 function renderColors( panel, type )
\r
60 colors = config.colorButton_colors.split( ',' ),
\r
61 total = colors.length + ( config.colorButton_enableMore ? 2 : 1 );
\r
63 var clickFn = CKEDITOR.tools.addFunction( function( color, type )
\r
67 var applyColorStyle = arguments.callee;
\r
68 function onColorDialogClose( evt )
\r
70 this.removeListener( 'ok', onColorDialogClose );
\r
71 this.removeListener( 'cancel', onColorDialogClose );
\r
73 evt.name == 'ok' && applyColorStyle( this.getContentElement( 'picker', 'selectedColor' ).getValue(), type );
\r
76 editor.openDialog( 'colordialog', function()
\r
78 this.on( 'ok', onColorDialogClose );
\r
79 this.on( 'cancel', onColorDialogClose );
\r
90 editor.fire( 'saveSnapshot' );
\r
92 // Clean up any conflicting style within the range.
\r
93 new CKEDITOR.style( config['colorButton_' + type + 'Style'], { color : 'inherit' } ).remove( editor.document );
\r
97 var colorStyle = config['colorButton_' + type + 'Style'];
\r
99 colorStyle.childRule = type == 'back' ?
\r
100 // It's better to apply background color as the innermost style. (#3599)
\r
101 function(){ return false; } :
\r
102 // Fore color style must be applied inside links instead of around it.
\r
103 function( element ){ return element.getName() != 'a'; };
\r
105 new CKEDITOR.style( colorStyle, { color : color } ).apply( editor.document );
\r
108 editor.fire( 'saveSnapshot' );
\r
111 // Render the "Automatic" button.
\r
113 '<a class="cke_colorauto" _cke_focus=1 hidefocus=true' +
\r
114 ' title="', lang.auto, '"' +
\r
115 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',null,\'', type, '\');return false;"' +
\r
116 ' href="javascript:void(\'', lang.auto, '\')"' +
\r
117 ' role="option" aria-posinset="1" aria-setsize="', total, '">' +
\r
118 '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' +
\r
121 '<span class="cke_colorbox" style="background-color:#000"></span>' +
\r
123 '<td colspan=7 align=center>',
\r
129 '<table role="presentation" cellspacing=0 cellpadding=0 width="100%">' );
\r
131 // Render the color boxes.
\r
132 for ( var i = 0 ; i < colors.length ; i++ )
\r
134 if ( ( i % 8 ) === 0 )
\r
135 output.push( '</tr><tr>' );
\r
137 var parts = colors[ i ].split( '/' ),
\r
138 colorName = parts[ 0 ],
\r
139 colorCode = parts[ 1 ] || colorName;
\r
141 // The data can be only a color code (without #) or colorName + color code
\r
142 // If only a color code is provided, then the colorName is the color with the hash
\r
143 // Convert the color from RGB to RRGGBB for better compatibility with IE and <font>. See #5676
\r
145 colorName = '#' + colorName.replace( /^(.)(.)(.)$/, '$1$1$2$2$3$3' );
\r
147 var colorLabel = editor.lang.colors[ colorCode ] || colorCode;
\r
150 '<a class="cke_colorbox" _cke_focus=1 hidefocus=true' +
\r
151 ' title="', colorLabel, '"' +
\r
152 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'', colorName, '\',\'', type, '\'); return false;"' +
\r
153 ' href="javascript:void(\'', colorLabel, '\')"' +
\r
154 ' role="option" aria-posinset="', ( i + 2 ), '" aria-setsize="', total, '">' +
\r
155 '<span class="cke_colorbox" style="background-color:#', colorCode, '"></span>' +
\r
160 // Render the "More Colors" button.
\r
161 if ( config.colorButton_enableMore )
\r
166 '<td colspan=8 align=center>' +
\r
167 '<a class="cke_colormore" _cke_focus=1 hidefocus=true' +
\r
168 ' title="', lang.more, '"' +
\r
169 ' onclick="CKEDITOR.tools.callFunction(', clickFn, ',\'?\',\'', type, '\');return false;"' +
\r
170 ' href="javascript:void(\'', lang.more, '\')"',
\r
171 ' role="option" aria-posinset="', total, '" aria-setsize="', total, '">',
\r
174 '</td>' ); // It is later in the code.
\r
177 output.push( '</tr></table>' );
\r
179 return output.join( '' );
\r
185 * Whether to enable the "More Colors..." button in the color selectors.
\r
189 * config.colorButton_enableMore = false;
\r
191 CKEDITOR.config.colorButton_enableMore = true;
\r
194 * Defines the colors to be displayed in the color selectors. It's a string
\r
195 * containing the hexadecimal notation for HTML colors, without the "#" prefix.
\r
197 * Since 3.3: A name may be optionally defined by prefixing the entries with the
\r
198 * name and the slash character. For example, "FontColor1/FF9900" will be
\r
199 * displayed as the color #FF9900 in the selector, but will be outputted as "FontColor1".
\r
201 * @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
203 * // Brazil colors only.
\r
204 * config.colorButton_colors = '00923E,F8C100,28166F';
\r
206 * config.colorButton_colors = 'FontColor1/FF9900,FontColor2/0066CC,FontColor3/F00'
\r
208 CKEDITOR.config.colorButton_colors =
\r
209 '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
\r
210 'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
\r
211 'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
\r
212 'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
\r
213 'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';
\r
216 * Holds the style definition to be used to apply the text foreground color.
\r
219 * // This is basically the default setting value.
\r
220 * config.colorButton_foreStyle =
\r
222 * element : 'span',
\r
223 * styles : { 'color' : '#(color)' }
\r
226 CKEDITOR.config.colorButton_foreStyle =
\r
229 styles : { 'color' : '#(color)' },
\r
230 overrides : [ { element : 'font', attributes : { 'color' : null } } ]
\r
234 * Holds the style definition to be used to apply the text background color.
\r
237 * // This is basically the default setting value.
\r
238 * config.colorButton_backStyle =
\r
240 * element : 'span',
\r
241 * styles : { 'background-color' : '#(color)' }
\r
244 CKEDITOR.config.colorButton_backStyle =
\r
247 styles : { 'background-color' : '#(color)' }
\r