2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
7 * @fileOverview The "toolbar" plugin. Renders the default toolbar interface in
13 var toolbox = function()
16 this.focusCommandExecuted = false;
19 toolbox.prototype.focus = function()
21 for ( var t = 0, toolbar ; toolbar = this.toolbars[ t++ ] ; )
23 for ( var i = 0, item ; item = toolbar.items[ i++ ] ; )
38 modes : { wysiwyg : 1, source : 1 },
40 exec : function( editor )
44 editor.toolbox.focusCommandExecuted = true;
46 // Make the first button focus accessible for IE. (#3417)
47 // Adobe AIR instead need while of delay.
48 if ( CKEDITOR.env.ie || CKEDITOR.env.air )
49 setTimeout( function(){ editor.toolbox.focus(); }, 100 );
51 editor.toolbox.focus();
57 CKEDITOR.plugins.add( 'toolbar',
59 init : function( editor )
61 var itemKeystroke = function( item, keystroke )
63 var next, nextToolGroup, groupItemsCount;
64 var rtl = editor.lang.dir == 'rtl';
68 case rtl ? 37 : 39 : // RIGHT-ARROW
72 // Look for the next item in the toolbar.
77 nextToolGroup = item.toolbar.next;
78 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
80 // Bypass the empty toolgroups.
81 while ( groupItemsCount === 0 )
83 nextToolGroup = nextToolGroup.next;
84 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
88 next = nextToolGroup.items[ 0 ];
93 while ( item && !item.focus )
95 // If available, just focus it, otherwise focus the
100 editor.toolbox.focus();
104 case rtl ? 39 : 37 : // LEFT-ARROW
105 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
108 // Look for the previous item in the toolbar.
109 next = item.previous;
113 nextToolGroup = item.toolbar.previous;
114 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
116 // Bypass the empty toolgroups.
117 while ( groupItemsCount === 0 )
119 nextToolGroup = nextToolGroup.previous;
120 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
124 next = nextToolGroup.items[ groupItemsCount - 1 ];
129 while ( item && !item.focus )
131 // If available, just focus it, otherwise focus the
137 var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items;
138 lastToolbarItems[ lastToolbarItems.length - 1 ].focus();
155 editor.on( 'themeSpace', function( event )
157 if ( event.data.space == editor.config.toolbarLocation )
159 editor.toolbox = new toolbox();
161 var labelId = CKEDITOR.tools.getNextId();
163 var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '" onmousedown="return false;"' ],
164 expanded = editor.config.toolbarStartupExpanded !== false,
167 output.push( expanded ? '>' : ' style="display:none">' );
169 // Sends the ARIA label.
170 output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );
172 var toolbars = editor.toolbox.toolbars,
174 ( editor.config.toolbar instanceof Array ) ?
175 editor.config.toolbar
177 editor.config[ 'toolbar_' + editor.config.toolbar ];
179 for ( var r = 0 ; r < toolbar.length ; r++ )
181 var row = toolbar[ r ];
183 // It's better to check if the row object is really
184 // available because it's a common mistake to leave
185 // an extra comma in the toolbar definition
186 // settings, which leads on the editor not loading
187 // at all in IE. (#3983)
191 var toolbarId = CKEDITOR.tools.getNextId(),
192 toolbarObj = { id : toolbarId, items : [] };
196 output.push( '</div>' );
202 output.push( '<div class="cke_break"></div>' );
206 output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );
208 // Add the toolbar to the "editor.toolbox.toolbars"
210 var index = toolbars.push( toolbarObj ) - 1;
212 // Create the next/previous reference.
215 toolbarObj.previous = toolbars[ index - 1 ];
216 toolbarObj.previous.next = toolbarObj;
219 // Create all items defined for this toolbar.
220 for ( var i = 0 ; i < row.length ; i++ )
225 if ( itemName == '-' )
226 item = CKEDITOR.ui.separator;
228 item = editor.ui.create( itemName );
236 output.push( '<span class="cke_toolgroup" role="presentation">' );
240 else if ( groupStarted )
242 output.push( '</span>' );
246 var itemObj = item.render( editor, output );
247 index = toolbarObj.items.push( itemObj ) - 1;
251 itemObj.previous = toolbarObj.items[ index - 1 ];
252 itemObj.previous.next = itemObj;
255 itemObj.toolbar = toolbarObj;
256 itemObj.onkey = itemKeystroke;
260 * Prevent JAWS from focusing the toolbar after document load.
262 itemObj.onfocus = function()
264 if ( !editor.toolbox.focusCommandExecuted )
272 output.push( '</span>' );
276 output.push( '<span class="cke_toolbar_end"></span></span>' );
279 output.push( '</div>' );
281 if ( editor.config.toolbarCanCollapse )
283 var collapserFn = CKEDITOR.tools.addFunction(
286 editor.execCommand( 'toolbarCollapse' );
289 editor.on( 'destroy', function () {
290 CKEDITOR.tools.removeFunction( collapserFn );
293 var collapserId = CKEDITOR.tools.getNextId();
295 editor.addCommand( 'toolbarCollapse',
297 exec : function( editor )
299 var collapser = CKEDITOR.document.getById( collapserId ),
300 toolbox = collapser.getPrevious(),
301 contents = editor.getThemeSpace( 'contents' ),
302 toolboxContainer = toolbox.getParent(),
303 contentHeight = parseInt( contents.$.style.height, 10 ),
304 previousHeight = toolboxContainer.$.offsetHeight,
305 collapsed = !toolbox.isVisible();
310 collapser.addClass( 'cke_toolbox_collapser_min' );
311 collapser.setAttribute( 'title', editor.lang.toolbarExpand );
316 collapser.removeClass( 'cke_toolbox_collapser_min' );
317 collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
320 // Update collapser symbol.
321 collapser.getFirst().setText( collapsed ?
322 '\u25B2' : // BLACK UP-POINTING TRIANGLE
323 '\u25C0' ); // BLACK LEFT-POINTING TRIANGLE
325 var dy = toolboxContainer.$.offsetHeight - previousHeight;
326 contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
328 editor.fire( 'resize' );
331 modes : { wysiwyg : 1, source : 1 }
334 output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
335 + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );
338 output.push( ' cke_toolbox_collapser_min' );
340 output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',
341 '<span>▲</span>', // BLACK UP-POINTING TRIANGLE
345 event.data.html += output.join( '' );
349 editor.on( 'destroy', function()
351 var toolbars, index = 0, i,
353 toolbars = this.toolbox.toolbars;
354 for ( ; index < toolbars.length; index++ )
356 items = toolbars[ index ].items;
357 for ( i = 0; i < items.length; i++ )
359 instance = items[ i ];
360 if ( instance.clickFn ) CKEDITOR.tools.removeFunction( instance.clickFn );
361 if ( instance.keyDownFn ) CKEDITOR.tools.removeFunction( instance.keyDownFn );
363 if ( instance.index ) CKEDITOR.ui.button._.instances[ instance.index ] = null;
368 editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
374 * The UI element that renders a toolbar separator.
378 CKEDITOR.ui.separator =
380 render : function( editor, output )
382 output.push( '<span class="cke_separator" role="separator"></span>' );
388 * The "theme space" to which rendering the toolbar. For the default theme,
389 * the recommended options are "top" and "bottom".
392 * @see CKEDITOR.config.theme
394 * config.toolbarLocation = 'bottom';
396 CKEDITOR.config.toolbarLocation = 'top';
399 * The toolbar definition. It is an array of toolbars (strips),
400 * each one being also an array, containing a list of UI items.
401 * Note that this setting is composed by "toolbar_" added by the toolbar name,
402 * which in this case is called "Basic". This second part of the setting name
403 * can be anything. You must use this name in the
404 * {@link CKEDITOR.config.toolbar} setting, so you instruct the editor which
405 * toolbar_(name) setting to you.
408 * // Defines a toolbar with only one strip containing the "Source" button, a
409 * // separator and the "Bold" and "Italic" buttons.
410 * <b>config.toolbar_Basic =
412 * [ 'Source', '-', 'Bold', 'Italic' ]
414 * config.toolbar = 'Basic';
416 CKEDITOR.config.toolbar_Basic =
418 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
422 * This is the default toolbar definition used by the editor. It contains all
425 * @default (see example)
427 * // This is actually the default value.
428 * config.toolbar_Full =
430 * ['Source','-','Save','NewPage','Preview','-','Templates'],
431 * ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
432 * ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
433 * ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
435 * ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
436 * ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
437 * ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
438 * ['BidiLtr', 'BidiRtl' ],
439 * ['Link','Unlink','Anchor'],
440 * ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
442 * ['Styles','Format','Font','FontSize'],
443 * ['TextColor','BGColor'],
444 * ['Maximize', 'ShowBlocks','-','About']
447 CKEDITOR.config.toolbar_Full =
449 ['Source','-','Save','NewPage','Preview','-','Templates'],
450 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
451 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
452 ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
454 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
455 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
456 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
457 ['BidiLtr', 'BidiRtl' ],
458 ['Link','Unlink','Anchor'],
459 ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
461 ['Styles','Format','Font','FontSize'],
462 ['TextColor','BGColor'],
463 ['Maximize', 'ShowBlocks','-','About']
467 * The toolbox (alias toolbar) definition. It is a toolbar name or an array of
468 * toolbars (strips), each one being also an array, containing a list of UI items.
472 * // Defines a toolbar with only one strip containing the "Source" button, a
473 * // separator and the "Bold" and "Italic" buttons.
476 * [ 'Source', '-', 'Bold', 'Italic' ]
479 * // Load toolbar_Name where Name = Basic.
480 * config.toolbar = 'Basic';
482 CKEDITOR.config.toolbar = 'Full';
485 * Whether the toolbar can be collapsed by the user. If disabled, the collapser
486 * button will not be displayed.
490 * config.toolbarCanCollapse = false;
492 CKEDITOR.config.toolbarCanCollapse = true;
495 * Whether the toolbar must start expanded when the editor is loaded.
496 * @name CKEDITOR.config.toolbarStartupExpanded
500 * config.toolbarStartupExpanded = false;