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