2 Copyright (c) 2003-2009, 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 switch ( keystroke )
\r
64 case 39 : // RIGHT-ARROW
\r
66 // Look for the next item in the toolbar.
\r
67 while ( ( item = item.next || ( item.toolbar.next && item.toolbar.next.items[ 0 ] ) ) && !item.focus )
\r
70 // If available, just focus it, otherwise focus the
\r
75 editor.toolbox.focus();
\r
79 case 37 : // LEFT-ARROW
\r
80 case CKEDITOR.SHIFT + 9 : // SHIFT + TAB
\r
81 // Look for the previous item in the toolbar.
\r
82 while ( ( item = item.previous || ( item.toolbar.previous && item.toolbar.previous.items[ item.toolbar.previous.items.length - 1 ] ) ) && !item.focus )
\r
85 // If available, just focus it, otherwise focus the
\r
91 var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items;
\r
92 lastToolbarItems[ lastToolbarItems.length - 1 ].focus();
\r
109 editor.on( 'themeSpace', function( event )
\r
111 if ( event.data.space == editor.config.toolbarLocation )
\r
113 editor.toolbox = new toolbox();
\r
115 var output = [ '<div class="cke_toolbox"' ],
\r
116 expanded = editor.config.toolbarStartupExpanded !== false,
\r
119 output.push( expanded ? '>' : ' style="display:none">' );
\r
121 var toolbars = editor.toolbox.toolbars,
\r
123 ( editor.config.toolbar instanceof Array ) ?
\r
124 editor.config.toolbar
\r
126 editor.config[ 'toolbar_' + editor.config.toolbar ];
\r
128 for ( var r = 0 ; r < toolbar.length ; r++ )
\r
130 var row = toolbar[ r ];
\r
132 // It's better to check if the row object is really
\r
133 // available because it's a common mistake to leave
\r
134 // an extra comma in the toolbar definition
\r
135 // settings, which leads on the editor not loading
\r
136 // at all in IE. (#3983)
\r
140 var toolbarId = 'cke_' + CKEDITOR.tools.getNextNumber(),
\r
141 toolbarObj = { id : toolbarId, items : [] };
\r
143 if ( groupStarted )
\r
145 output.push( '</div>' );
\r
151 output.push( '<div class="cke_break"></div>' );
\r
155 output.push( '<span id="', toolbarId, '" class="cke_toolbar"><span class="cke_toolbar_start"></span>' );
\r
157 // Add the toolbar to the "editor.toolbox.toolbars"
\r
159 var index = toolbars.push( toolbarObj ) - 1;
\r
161 // Create the next/previous reference.
\r
164 toolbarObj.previous = toolbars[ index - 1 ];
\r
165 toolbarObj.previous.next = toolbarObj;
\r
168 // Create all items defined for this toolbar.
\r
169 for ( var i = 0 ; i < row.length ; i++ )
\r
172 itemName = row[ i ];
\r
174 if ( itemName == '-' )
\r
175 item = CKEDITOR.ui.separator;
\r
177 item = editor.ui.create( itemName );
\r
181 if ( item.canGroup )
\r
183 if ( !groupStarted )
\r
185 output.push( '<span class="cke_toolgroup">' );
\r
189 else if ( groupStarted )
\r
191 output.push( '</span>' );
\r
195 var itemObj = item.render( editor, output );
\r
196 index = toolbarObj.items.push( itemObj ) - 1;
\r
200 itemObj.previous = toolbarObj.items[ index - 1 ];
\r
201 itemObj.previous.next = itemObj;
\r
204 itemObj.toolbar = toolbarObj;
\r
205 itemObj.onkey = itemKeystroke;
\r
209 * Prevent JAWS from focusing the toolbar after document load.
\r
211 itemObj.onfocus = function()
\r
213 if ( !editor.toolbox.focusCommandExecuted )
\r
219 if ( groupStarted )
\r
221 output.push( '</span>' );
\r
225 output.push( '<span class="cke_toolbar_end"></span></span>' );
\r
228 output.push( '</div>' );
\r
230 if ( editor.config.toolbarCanCollapse )
\r
232 var collapserFn = CKEDITOR.tools.addFunction(
\r
235 editor.execCommand( 'toolbarCollapse' );
\r
238 var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber();
\r
240 editor.addCommand( 'toolbarCollapse',
\r
242 exec : function( editor )
\r
244 var collapser = CKEDITOR.document.getById( collapserId );
\r
245 var toolbox = collapser.getPrevious();
\r
246 var contents = editor.getThemeSpace( 'contents' );
\r
247 var toolboxContainer = toolbox.getParent();
\r
248 var contentHeight = parseInt( contents.$.style.height, 10 );
\r
249 var previousHeight = toolboxContainer.$.offsetHeight;
\r
251 if ( toolbox.isVisible() )
\r
254 collapser.addClass( 'cke_toolbox_collapser_min' );
\r
255 collapser.setAttribute( 'title', editor.lang.toolbarExpand );
\r
260 collapser.removeClass( 'cke_toolbox_collapser_min' );
\r
261 collapser.setAttribute( 'title', editor.lang.toolbarCollapse );
\r
264 var dy = toolboxContainer.$.offsetHeight - previousHeight;
\r
265 contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
\r
268 modes : { wysiwyg : 1, source : 1 }
\r
271 output.push( '<a title="' + ( expanded ? editor.lang.toolbarCollapse : editor.lang.toolbarExpand )
\r
272 + '" id="' + collapserId + '" class="cke_toolbox_collapser' );
\r
275 output.push( ' cke_toolbox_collapser_min' );
\r
277 output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')"></a>' );
\r
280 event.data.html += output.join( '' );
\r
284 editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
\r
290 * The UI element that renders a toolbar separator.
\r
294 CKEDITOR.ui.separator =
\r
296 render : function( editor, output )
\r
298 output.push( '<span class="cke_separator"></span>' );
\r
304 * The "theme space" to which rendering the toolbar. For the default theme,
\r
305 * the recommended options are "top" and "bottom".
\r
308 * @see CKEDITOR.config.theme
\r
310 * config.toolbarLocation = 'bottom';
\r
312 CKEDITOR.config.toolbarLocation = 'top';
\r
315 * The toolbar definition. It is an array of toolbars (strips),
\r
316 * each one being also an array, containing a list of UI items.
\r
317 * Note that this setting is composed by "toolbar_" added by the toolbar name,
\r
318 * which in this case is called "Basic". This second part of the setting name
\r
319 * can be anything. You must use this name in the
\r
320 * {@link CKEDITOR.config.toolbar} setting, so you instruct the editor which
\r
321 * toolbar_(name) setting to you.
\r
324 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
325 * // separator and the "Bold" and "Italic" buttons.
\r
326 * <b>config.toolbar_Basic =
\r
328 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
330 * config.toolbar = 'Basic';
\r
332 CKEDITOR.config.toolbar_Basic =
\r
334 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
\r
338 * This is the default toolbar definition used by the editor. It contains all
\r
341 * @default (see example)
\r
343 * // This is actually the default value.
\r
344 * config.toolbar_Full =
\r
346 * ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
347 * ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
348 * ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
349 * ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
351 * ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
352 * ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
\r
353 * ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
354 * ['Link','Unlink','Anchor'],
\r
355 * ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
357 * ['Styles','Format','Font','FontSize'],
\r
358 * ['TextColor','BGColor'],
\r
359 * ['Maximize', 'ShowBlocks','-','About']
\r
362 CKEDITOR.config.toolbar_Full =
\r
364 ['Source','-','Save','NewPage','Preview','-','Templates'],
\r
365 ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
\r
366 ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
\r
367 ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
\r
369 ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
\r
370 ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
\r
371 ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
\r
372 ['Link','Unlink','Anchor'],
\r
373 ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
\r
375 ['Styles','Format','Font','FontSize'],
\r
376 ['TextColor','BGColor'],
\r
377 ['Maximize', 'ShowBlocks','-','About']
\r
381 * The toolbox (alias toolbar) definition. It is a toolbar name or an array of
\r
382 * toolbars (strips), each one being also an array, containing a list of UI items.
\r
383 * @type Array|String
\r
386 * // Defines a toolbar with only one strip containing the "Source" button, a
\r
387 * // separator and the "Bold" and "Italic" buttons.
\r
390 * [ 'Source', '-', 'Bold', 'Italic' ]
\r
393 * // Load toolbar_Name where Name = Basic.
\r
394 * config.toolbar = 'Basic';
\r
396 CKEDITOR.config.toolbar = 'Full';
\r
399 * Whether the toolbar can be collapsed by the user. If disabled, the collapser
\r
400 * button will not be displayed.
\r
404 * config.toolbarCanCollapse = false;
\r
406 CKEDITOR.config.toolbarCanCollapse = true;
\r
409 * Whether the toolbar must start expanded when the editor is loaded.
\r
410 * @name CKEDITOR.config.toolbarStartupExpanded
\r
414 * config.toolbarStartupExpanded = false;
\r