2 Copyright (c) 2003-2010, 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. (#3417)
\r
47 if ( CKEDITOR.env.ie )
\r
48 setTimeout( function(){ editor.toolbox.focus(); }, 100 );
\r
50 editor.toolbox.focus();
\r
56 CKEDITOR.plugins.add( 'toolbar',
\r
58 init : function( editor )
\r
60 var itemKeystroke = function( item, keystroke )
\r
62 var next, nextToolGroup, groupItemsCount;
\r
64 switch ( keystroke )
\r
66 case 39 : // RIGHT-ARROW
\r
70 // Look for the previous item in the toolbar.
\r
75 nextToolGroup = item.toolbar.next;
\r
76 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
78 // Bypass the empty toolgroups.
\r
79 while ( groupItemsCount === 0 )
\r
81 nextToolGroup = nextToolGroup.next;
\r
82 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
85 if ( nextToolGroup )
\r
86 next = nextToolGroup.items[ 0 ];
\r
91 while ( item && !item.focus )
\r
93 // If available, just focus it, otherwise focus the
\r
98 editor.toolbox.focus();
\r
102 case 37 : // LEFT-ARROW
\r
103 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
\r
106 // Look for the previous item in the toolbar.
\r
107 next = item.previous;
\r
111 nextToolGroup = item.toolbar.previous;
\r
112 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
114 // Bypass the empty toolgroups.
\r
115 while ( groupItemsCount === 0 )
\r
117 nextToolGroup = nextToolGroup.previous;
\r
118 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
121 if ( nextToolGroup )
\r
122 next = nextToolGroup.items[ groupItemsCount - 1 ];
\r
127 while ( item && !item.focus )
\r
129 // If available, just focus it, otherwise focus the
\r
135 var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items;
\r
136 lastToolbarItems[ lastToolbarItems.length - 1 ].focus();
\r
153 editor.on( 'themeSpace', function( event )
\r
155 if ( event.data.space == editor.config.toolbarLocation )
\r
157 editor.toolbox = new toolbox();
\r
159 var labelId = 'cke_' + CKEDITOR.tools.getNextNumber();
\r
161 var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '"' ],
\r
162 expanded = editor.config.toolbarStartupExpanded !== false,
\r
165 output.push( expanded ? '>' : ' style="display:none">' );
\r
167 // Sends the ARIA label.
\r
168 output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );
\r
170 var toolbars = editor.toolbox.toolbars,
\r
172 ( editor.config.toolbar instanceof Array ) ?
\r
173 editor.config.toolbar
\r
175 editor.config[ 'toolbar_' + editor.config.toolbar ];
\r
177 for ( var r = 0 ; r < toolbar.length ; r++ )
\r
179 var row = toolbar[ r ];
\r
181 // It's better to check if the row object is really
\r
182 // available because it's a common mistake to leave
\r
183 // an extra comma in the toolbar definition
\r
184 // settings, which leads on the editor not loading
\r
185 // at all in IE. (#3983)
\r
189 var toolbarId = 'cke_' + CKEDITOR.tools.getNextNumber(),
\r
190 toolbarObj = { id : toolbarId, items : [] };
\r
192 if ( groupStarted )
\r
194 output.push( '</div>' );
\r
200 output.push( '<div class="cke_break"></div>' );
\r
204 output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );
\r
206 // Add the toolbar to the "editor.toolbox.toolbars"
\r
208 var index = toolbars.push( toolbarObj ) - 1;
\r
210 // Create the next/previous reference.
\r
213 toolbarObj.previous = toolbars[ index - 1 ];
\r
214 toolbarObj.previous.next = toolbarObj;
\r
217 // Create all items defined for this toolbar.
\r
218 for ( var i = 0 ; i < row.length ; i++ )
\r
221 itemName = row[ i ];
\r
223 if ( itemName == '-' )
\r
224 item = CKEDITOR.ui.separator;
\r
226 item = editor.ui.create( itemName );
\r
230 if ( item.canGroup )
\r
232 if ( !groupStarted )
\r
234 output.push( '<span class="cke_toolgroup" role="presentation">' );
\r
238 else if ( groupStarted )
\r
240 output.push( '</span>' );
\r
244 var itemObj = item.render( editor, output );
\r
245 index = toolbarObj.items.push( itemObj ) - 1;
\r
249 itemObj.previous = toolbarObj.items[ index - 1 ];
\r
250 itemObj.previous.next = itemObj;
\r
253 itemObj.toolbar = toolbarObj;
\r
254 itemObj.onkey = itemKeystroke;
\r
258 * Prevent JAWS from focusing the toolbar after document load.
\r
260 itemObj.onfocus = function()
\r
262 if ( !editor.toolbox.focusCommandExecuted )
\r
268 if ( groupStarted )
\r
270 output.push( '</span>' );
\r
274 output.push( '<span class="cke_toolbar_end"></span></span>' );
\r
277 output.push( '</div>' );
\r
279 if ( editor.config.toolbarCanCollapse )
\r
281 var collapserFn = CKEDITOR.tools.addFunction(
\r
284 editor.execCommand( 'toolbarCollapse' );
\r
287 var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber();
\r
289 editor.addCommand( 'toolbarCollapse',
\r
291 exec : function( editor )
\r
293 var collapser = CKEDITOR.document.getById( collapserId );
\r
294 var toolbox = collapser.getPrevious();
\r
295 var contents = editor.getThemeSpace( 'contents' );
\r
296 var toolboxContainer = toolbox.getParent();
\r
297 var contentHeight = parseInt( contents.$.style.height, 10 );
\r
298 var previousHeight = toolboxContainer.$.offsetHeight;
\r
299 var collapsed = !toolbox.isVisible();
\r
304 collapser.addClass( 'cke_toolbox_collapser_min' );
\r
305 collapser.setAttribute( 'title', editor.lang.toolbarExpand );
\r
310 collapser.removeClass( 'cke_toolbox_collapser_min' );
\r
311 collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
\r
314 // Update collapser symbol.
\r
315 collapser.getFirst().setText( collapsed ?
\r
316 '\u25B2' : // BLACK UP-POINTING TRIANGLE
\r
317 '\u25C0' ); // BLACK LEFT-POINTING TRIANGLE
\r
319 var dy = toolboxContainer.$.offsetHeight - previousHeight;
\r
320 contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
\r
322 editor.fire( 'resize' );
\r
325 modes : { wysiwyg : 1, source : 1 }
\r
328 output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
\r
329 + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );
\r
332 output.push( ' cke_toolbox_collapser_min' );
\r
334 output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',
\r
335 '<span>▲</span>', // BLACK UP-POINTING TRIANGLE
\r
339 event.data.html += output.join( '' );
\r
343 editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
\r
349 * The UI element that renders a toolbar separator.
\r
353 CKEDITOR.ui.separator =
\r
355 render : function( editor, output )
\r
357 output.push( '<span class="cke_separator" role="separator"></span>' );
\r
363 * The "theme space" to which rendering the toolbar. For the default theme,
\r
364 * the recommended options are "top" and "bottom".
\r
367 * @see CKEDITOR.config.theme
\r
369 * config.toolbarLocation = 'bottom';
\r
371 CKEDITOR.config.toolbarLocation = 'top';
\r
374 * The toolbar definition. It is an array of toolbars (strips),
\r
375 * each one being also an array, containing a list of UI items.
\r
376 * Note that this setting is composed by "toolbar_" added by the toolbar name,
\r
377 * which in this case is called "Basic". This second part of the setting name
\r
378 * can be anything. You must use this name in the
\r
379 * {@link CKEDITOR.config.toolbar} setting, so you instruct the editor which
\r
380 * toolbar_(name) setting to you.
\r
383 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
384 * // separator and the "Bold" and "Italic" buttons.
\r
385 * <b>config.toolbar_Basic =
\r
387 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
389 * config.toolbar = 'Basic';
\r
391 CKEDITOR.config.toolbar_Basic =
\r
393 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
\r
397 * This is the default toolbar definition used by the editor. It contains all
\r
400 * @default (see example)
\r
402 * // This is actually the default value.
\r
403 * config.toolbar_Full =
\r
405 * ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
406 * ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
407 * ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
408 * ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
410 * ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
411 * ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
\r
412 * ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
413 * ['Link','Unlink','Anchor'],
\r
414 * ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
416 * ['Styles','Format','Font','FontSize'],
\r
417 * ['TextColor','BGColor'],
\r
418 * ['Maximize', 'ShowBlocks','-','About']
\r
421 CKEDITOR.config.toolbar_Full =
\r
423 ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
424 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
425 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
426 ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
428 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
429 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
\r
430 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
431 ['Link','Unlink','Anchor'],
\r
432 ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
434 ['Styles','Format','Font','FontSize'],
\r
435 ['TextColor','BGColor'],
\r
436 ['Maximize', 'ShowBlocks','-','About']
\r
440 * The toolbox (alias toolbar) definition. It is a toolbar name or an array of
\r
441 * toolbars (strips), each one being also an array, containing a list of UI items.
\r
442 * @type Array|String
\r
445 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
446 * // separator and the "Bold" and "Italic" buttons.
\r
449 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
452 * // Load toolbar_Name where Name = Basic.
\r
453 * config.toolbar = 'Basic';
\r
455 CKEDITOR.config.toolbar = 'Full';
\r
458 * Whether the toolbar can be collapsed by the user. If disabled, the collapser
\r
459 * button will not be displayed.
\r
463 * config.toolbarCanCollapse = false;
\r
465 CKEDITOR.config.toolbarCanCollapse = true;
\r
468 * Whether the toolbar must start expanded when the editor is loaded.
\r
469 * @name CKEDITOR.config.toolbarStartupExpanded
\r
473 * config.toolbarStartupExpanded = false;
\r