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
63 var rtl = editor.lang.dir == 'rtl';
\r
65 switch ( keystroke )
\r
67 case rtl ? 37 : 39 : // RIGHT-ARROW
\r
71 // Look for the next item in the toolbar.
\r
76 nextToolGroup = item.toolbar.next;
\r
77 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
79 // Bypass the empty toolgroups.
\r
80 while ( groupItemsCount === 0 )
\r
82 nextToolGroup = nextToolGroup.next;
\r
83 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
86 if ( nextToolGroup )
\r
87 next = nextToolGroup.items[ 0 ];
\r
92 while ( item && !item.focus )
\r
94 // If available, just focus it, otherwise focus the
\r
99 editor.toolbox.focus();
\r
103 case rtl ? 39 : 37 : // LEFT-ARROW
\r
104 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
\r
107 // Look for the previous item in the toolbar.
\r
108 next = item.previous;
\r
112 nextToolGroup = item.toolbar.previous;
\r
113 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
115 // Bypass the empty toolgroups.
\r
116 while ( groupItemsCount === 0 )
\r
118 nextToolGroup = nextToolGroup.previous;
\r
119 groupItemsCount = nextToolGroup && nextToolGroup.items.length;
\r
122 if ( nextToolGroup )
\r
123 next = nextToolGroup.items[ groupItemsCount - 1 ];
\r
128 while ( item && !item.focus )
\r
130 // If available, just focus it, otherwise focus the
\r
136 var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items;
\r
137 lastToolbarItems[ lastToolbarItems.length - 1 ].focus();
\r
154 editor.on( 'themeSpace', function( event )
\r
156 if ( event.data.space == editor.config.toolbarLocation )
\r
158 editor.toolbox = new toolbox();
\r
160 var labelId = 'cke_' + CKEDITOR.tools.getNextNumber();
\r
162 var output = [ '<div class="cke_toolbox" role="toolbar" aria-labelledby="', labelId, '"' ],
\r
163 expanded = editor.config.toolbarStartupExpanded !== false,
\r
166 output.push( expanded ? '>' : ' style="display:none">' );
\r
168 // Sends the ARIA label.
\r
169 output.push( '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar, '</span>' );
\r
171 var toolbars = editor.toolbox.toolbars,
\r
173 ( editor.config.toolbar instanceof Array ) ?
\r
174 editor.config.toolbar
\r
176 editor.config[ 'toolbar_' + editor.config.toolbar ];
\r
178 for ( var r = 0 ; r < toolbar.length ; r++ )
\r
180 var row = toolbar[ r ];
\r
182 // It's better to check if the row object is really
\r
183 // available because it's a common mistake to leave
\r
184 // an extra comma in the toolbar definition
\r
185 // settings, which leads on the editor not loading
\r
186 // at all in IE. (#3983)
\r
190 var toolbarId = 'cke_' + CKEDITOR.tools.getNextNumber(),
\r
191 toolbarObj = { id : toolbarId, items : [] };
\r
193 if ( groupStarted )
\r
195 output.push( '</div>' );
\r
201 output.push( '<div class="cke_break"></div>' );
\r
205 output.push( '<span id="', toolbarId, '" class="cke_toolbar" role="presentation"><span class="cke_toolbar_start"></span>' );
\r
207 // Add the toolbar to the "editor.toolbox.toolbars"
\r
209 var index = toolbars.push( toolbarObj ) - 1;
\r
211 // Create the next/previous reference.
\r
214 toolbarObj.previous = toolbars[ index - 1 ];
\r
215 toolbarObj.previous.next = toolbarObj;
\r
218 // Create all items defined for this toolbar.
\r
219 for ( var i = 0 ; i < row.length ; i++ )
\r
222 itemName = row[ i ];
\r
224 if ( itemName == '-' )
\r
225 item = CKEDITOR.ui.separator;
\r
227 item = editor.ui.create( itemName );
\r
231 if ( item.canGroup )
\r
233 if ( !groupStarted )
\r
235 output.push( '<span class="cke_toolgroup" role="presentation">' );
\r
239 else if ( groupStarted )
\r
241 output.push( '</span>' );
\r
245 var itemObj = item.render( editor, output );
\r
246 index = toolbarObj.items.push( itemObj ) - 1;
\r
250 itemObj.previous = toolbarObj.items[ index - 1 ];
\r
251 itemObj.previous.next = itemObj;
\r
254 itemObj.toolbar = toolbarObj;
\r
255 itemObj.onkey = itemKeystroke;
\r
259 * Prevent JAWS from focusing the toolbar after document load.
\r
261 itemObj.onfocus = function()
\r
263 if ( !editor.toolbox.focusCommandExecuted )
\r
269 if ( groupStarted )
\r
271 output.push( '</span>' );
\r
275 output.push( '<span class="cke_toolbar_end"></span></span>' );
\r
278 output.push( '</div>' );
\r
280 if ( editor.config.toolbarCanCollapse )
\r
282 var collapserFn = CKEDITOR.tools.addFunction(
\r
285 editor.execCommand( 'toolbarCollapse' );
\r
288 editor.on( 'destroy', function () {
\r
289 CKEDITOR.tools.removeFunction( collapserFn );
\r
292 var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber();
\r
294 editor.addCommand( 'toolbarCollapse',
\r
296 exec : function( editor )
\r
298 var collapser = CKEDITOR.document.getById( collapserId );
\r
299 var toolbox = collapser.getPrevious();
\r
300 var contents = editor.getThemeSpace( 'contents' );
\r
301 var toolboxContainer = toolbox.getParent();
\r
302 var contentHeight = parseInt( contents.$.style.height, 10 );
\r
303 var previousHeight = toolboxContainer.$.offsetHeight;
\r
304 var collapsed = !toolbox.isVisible();
\r
309 collapser.addClass( 'cke_toolbox_collapser_min' );
\r
310 collapser.setAttribute( 'title', editor.lang.toolbarExpand );
\r
315 collapser.removeClass( 'cke_toolbox_collapser_min' );
\r
316 collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
\r
319 // Update collapser symbol.
\r
320 collapser.getFirst().setText( collapsed ?
\r
321 '\u25B2' : // BLACK UP-POINTING TRIANGLE
\r
322 '\u25C0' ); // BLACK LEFT-POINTING TRIANGLE
\r
324 var dy = toolboxContainer.$.offsetHeight - previousHeight;
\r
325 contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
\r
327 editor.fire( 'resize' );
\r
330 modes : { wysiwyg : 1, source : 1 }
\r
333 output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
\r
334 + '" id="' + collapserId + '" tabIndex="-1" class="cke_toolbox_collapser' );
\r
337 output.push( ' cke_toolbox_collapser_min' );
\r
339 output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">',
\r
340 '<span>▲</span>', // BLACK UP-POINTING TRIANGLE
\r
344 event.data.html += output.join( '' );
\r
348 editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
\r
354 * The UI element that renders a toolbar separator.
\r
358 CKEDITOR.ui.separator =
\r
360 render : function( editor, output )
\r
362 output.push( '<span class="cke_separator" role="separator"></span>' );
\r
368 * The "theme space" to which rendering the toolbar. For the default theme,
\r
369 * the recommended options are "top" and "bottom".
\r
372 * @see CKEDITOR.config.theme
\r
374 * config.toolbarLocation = 'bottom';
\r
376 CKEDITOR.config.toolbarLocation = 'top';
\r
379 * The toolbar definition. It is an array of toolbars (strips),
\r
380 * each one being also an array, containing a list of UI items.
\r
381 * Note that this setting is composed by "toolbar_" added by the toolbar name,
\r
382 * which in this case is called "Basic". This second part of the setting name
\r
383 * can be anything. You must use this name in the
\r
384 * {@link CKEDITOR.config.toolbar} setting, so you instruct the editor which
\r
385 * toolbar_(name) setting to you.
\r
388 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
389 * // separator and the "Bold" and "Italic" buttons.
\r
390 * <b>config.toolbar_Basic =
\r
392 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
394 * config.toolbar = 'Basic';
\r
396 CKEDITOR.config.toolbar_Basic =
\r
398 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
\r
402 * This is the default toolbar definition used by the editor. It contains all
\r
405 * @default (see example)
\r
407 * // This is actually the default value.
\r
408 * config.toolbar_Full =
\r
410 * ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
411 * ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
412 * ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
413 * ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
415 * ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
416 * ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
\r
417 * ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
418 * ['Link','Unlink','Anchor'],
\r
419 * ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
421 * ['Styles','Format','Font','FontSize'],
\r
422 * ['TextColor','BGColor'],
\r
423 * ['Maximize', 'ShowBlocks','-','About']
\r
426 CKEDITOR.config.toolbar_Full =
\r
428 ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
429 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
430 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
431 ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
433 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
434 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
\r
435 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
436 ['Link','Unlink','Anchor'],
\r
437 ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
439 ['Styles','Format','Font','FontSize'],
\r
440 ['TextColor','BGColor'],
\r
441 ['Maximize', 'ShowBlocks','-','About']
\r
445 * The toolbox (alias toolbar) definition. It is a toolbar name or an array of
\r
446 * toolbars (strips), each one being also an array, containing a list of UI items.
\r
447 * @type Array|String
\r
450 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
451 * // separator and the "Bold" and "Italic" buttons.
\r
454 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
457 * // Load toolbar_Name where Name = Basic.
\r
458 * config.toolbar = 'Basic';
\r
460 CKEDITOR.config.toolbar = 'Full';
\r
463 * Whether the toolbar can be collapsed by the user. If disabled, the collapser
\r
464 * button will not be displayed.
\r
468 * config.toolbarCanCollapse = false;
\r
470 CKEDITOR.config.toolbarCanCollapse = true;
\r
473 * Whether the toolbar must start expanded when the editor is loaded.
\r
474 * @name CKEDITOR.config.toolbarStartupExpanded
\r
478 * config.toolbarStartupExpanded = false;
\r