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