X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Ftoolbar%2Fplugin.js;h=d29462eef29d2e332c84ad6d565ad18996d34ffa;hb=6e682412d5cc0dfaedb376482e585bf2989c6863;hp=fd9fab04ffda4d3369c26f9dfe637dd2f1e50404;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/toolbar/plugin.js b/_source/plugins/toolbar/plugin.js index fd9fab0..d29462e 100644 --- a/_source/plugins/toolbar/plugin.js +++ b/_source/plugins/toolbar/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -36,6 +36,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license toolbarFocus : { modes : { wysiwyg : 1, source : 1 }, + readOnly : 1, exec : function( editor ) { @@ -43,8 +44,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { editor.toolbox.focusCommandExecuted = true; - // Make the first button focus accessible. (#3417) - if ( CKEDITOR.env.ie ) + // Make the first button focus accessible for IE. (#3417) + // Adobe AIR instead need while of delay. + if ( CKEDITOR.env.ie || CKEDITOR.env.air ) setTimeout( function(){ editor.toolbox.focus(); }, 100 ); else editor.toolbox.focus(); @@ -55,86 +57,98 @@ For licensing, see LICENSE.html or http://ckeditor.com/license CKEDITOR.plugins.add( 'toolbar', { + requires : [ 'button' ], init : function( editor ) { + var endFlag; + var itemKeystroke = function( item, keystroke ) { - var next, nextToolGroup, groupItemsCount; - var rtl = editor.lang.dir == 'rtl'; + var next, toolbar; + var rtl = editor.lang.dir == 'rtl', + toolbarGroupCycling = editor.config.toolbarGroupCycling; + + toolbarGroupCycling = toolbarGroupCycling === undefined || toolbarGroupCycling; switch ( keystroke ) { - case rtl ? 37 : 39 : // RIGHT-ARROW case 9 : // TAB - do + case CKEDITOR.SHIFT + 9 : // SHIFT + TAB + // Cycle through the toolbars, starting from the one + // closest to the current item. + while ( !toolbar || !toolbar.items.length ) { - // Look for the next item in the toolbar. - next = item.next; + toolbar = keystroke == 9 ? + ( ( toolbar ? toolbar.next : item.toolbar.next ) || editor.toolbox.toolbars[ 0 ] ) : + ( ( toolbar ? toolbar.previous : item.toolbar.previous ) || editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ] ); - if ( !next ) + // Look for the first item that accepts focus. + if ( toolbar.items.length ) { - nextToolGroup = item.toolbar.next; - groupItemsCount = nextToolGroup && nextToolGroup.items.length; - - // Bypass the empty toolgroups. - while ( groupItemsCount === 0 ) + item = toolbar.items[ endFlag ? ( toolbar.items.length - 1 ) : 0 ]; + while ( item && !item.focus ) { - nextToolGroup = nextToolGroup.next; - groupItemsCount = nextToolGroup && nextToolGroup.items.length; - } + item = endFlag ? item.previous : item.next; - if ( nextToolGroup ) - next = nextToolGroup.items[ 0 ]; + if ( !item ) + toolbar = 0; + } } - - item = next; } - while ( item && !item.focus ) - // If available, just focus it, otherwise focus the - // first one. if ( item ) item.focus(); - else - editor.toolbox.focus(); return false; - case rtl ? 39 : 37 : // LEFT-ARROW - case CKEDITOR.SHIFT + 9 : // SHIFT + TAB + case rtl ? 37 : 39 : // RIGHT-ARROW + case 40 : // DOWN-ARROW + next = item; do { - // Look for the previous item in the toolbar. - next = item.previous; + // Look for the next item in the toolbar. + next = next.next; - if ( !next ) - { - nextToolGroup = item.toolbar.previous; - groupItemsCount = nextToolGroup && nextToolGroup.items.length; + // If it's the last item, cycle to the first one. + if ( !next && toolbarGroupCycling ) + next = item.toolbar.items[ 0 ]; + } + while ( next && !next.focus ) - // Bypass the empty toolgroups. - while ( groupItemsCount === 0 ) - { - nextToolGroup = nextToolGroup.previous; - groupItemsCount = nextToolGroup && nextToolGroup.items.length; - } + // If available, just focus it, otherwise focus the + // first one. + if ( next ) + next.focus(); + else + // Send a TAB. + itemKeystroke( item, 9 ); - if ( nextToolGroup ) - next = nextToolGroup.items[ groupItemsCount - 1 ]; - } + return false; + + case rtl ? 39 : 37 : // LEFT-ARROW + case 38 : // UP-ARROW + next = item; + do + { + // Look for the previous item in the toolbar. + next = next.previous; - item = next; + // If it's the first item, cycle to the last one. + if ( !next && toolbarGroupCycling ) + next = item.toolbar.items[ item.toolbar.items.length - 1 ]; } - while ( item && !item.focus ) + while ( next && !next.focus ) // If available, just focus it, otherwise focus the // last one. - if ( item ) - item.focus(); + if ( next ) + next.focus(); else { - var lastToolbarItems = editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ].items; - lastToolbarItems[ lastToolbarItems.length - 1 ].focus(); + endFlag = 1; + // Send a SHIFT + TAB. + itemKeystroke( item, CKEDITOR.SHIFT + 9 ); + endFlag = 0; } return false; @@ -157,16 +171,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { editor.toolbox = new toolbox(); - var labelId = 'cke_' + CKEDITOR.tools.getNextNumber(); + var labelId = CKEDITOR.tools.getNextId(); - var output = [ '' ); @@ -202,33 +217,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license continue; } - output.push( '' ); - - // Add the toolbar to the "editor.toolbox.toolbars" - // array. - var index = toolbars.push( toolbarObj ) - 1; - - // Create the next/previous reference. - if ( index > 0 ) - { - toolbarObj.previous = toolbars[ index - 1 ]; - toolbarObj.previous.next = toolbarObj; - } + items = row.items || row; // Create all items defined for this toolbar. - for ( var i = 0 ; i < row.length ; i++ ) + for ( var i = 0 ; i < items.length ; i++ ) { var item, - itemName = row[ i ]; + itemName = items[ i ], + canGroup; - if ( itemName == '-' ) - item = CKEDITOR.ui.separator; - else - item = editor.ui.create( itemName ); + item = editor.ui.create( itemName ); if ( item ) { - if ( item.canGroup ) + canGroup = item.canGroup !== false; + + // Initialize the toolbar first, if needed. + if ( !toolbarObj ) + { + // Create the basic toolbar object. + toolbarId = CKEDITOR.tools.getNextId(); + toolbarObj = { id : toolbarId, items : [] }; + toolbarName = row.name && ( editor.lang.toolbarGroups[ row.name ] || row.name ); + + // Output the toolbar opener. + output.push( '' ); + + // If a toolbar name is available, send the voice label. + toolbarName && output.push( '', toolbarName, '' ); + + output.push( '' ); + + // Add the toolbar to the "editor.toolbox.toolbars" + // array. + var index = toolbars.push( toolbarObj ) - 1; + + // Create the next/previous reference. + if ( index > 0 ) + { + toolbarObj.previous = toolbars[ index - 1 ]; + toolbarObj.previous.next = toolbarObj; + } + } + + if ( canGroup ) { if ( !groupStarted ) { @@ -272,7 +306,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license groupStarted = 0; } - output.push( '' ); + if ( toolbarObj ) + output.push( '' ); } output.push( '' ); @@ -283,25 +318,26 @@ For licensing, see LICENSE.html or http://ckeditor.com/license function() { editor.execCommand( 'toolbarCollapse' ); - } ); + }); editor.on( 'destroy', function () { CKEDITOR.tools.removeFunction( collapserFn ); - } ); + }); - var collapserId = 'cke_' + CKEDITOR.tools.getNextNumber(); + var collapserId = CKEDITOR.tools.getNextId(); editor.addCommand( 'toolbarCollapse', { + readOnly : 1, exec : function( editor ) { - var collapser = CKEDITOR.document.getById( collapserId ); - var toolbox = collapser.getPrevious(); - var contents = editor.getThemeSpace( 'contents' ); - var toolboxContainer = toolbox.getParent(); - var contentHeight = parseInt( contents.$.style.height, 10 ); - var previousHeight = toolboxContainer.$.offsetHeight; - var collapsed = !toolbox.isVisible(); + var collapser = CKEDITOR.document.getById( collapserId ), + toolbox = collapser.getPrevious(), + contents = editor.getThemeSpace( 'contents' ), + toolboxContainer = toolbox.getParent(), + contentHeight = parseInt( contents.$.style.height, 10 ), + previousHeight = toolboxContainer.$.offsetHeight, + collapsed = !toolbox.isVisible(); if ( !collapsed ) { @@ -345,24 +381,44 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }); + editor.on( 'destroy', function() + { + var toolbars, index = 0, i, + items, instance; + toolbars = this.toolbox.toolbars; + for ( ; index < toolbars.length; index++ ) + { + items = toolbars[ index ].items; + for ( i = 0; i < items.length; i++ ) + { + instance = items[ i ]; + if ( instance.clickFn ) CKEDITOR.tools.removeFunction( instance.clickFn ); + if ( instance.keyDownFn ) CKEDITOR.tools.removeFunction( instance.keyDownFn ); + } + } + }); + editor.addCommand( 'toolbarFocus', commands.toolbarFocus ); + + editor.ui.add( '-', CKEDITOR.UI_SEPARATOR, {} ); + editor.ui.addHandler( CKEDITOR.UI_SEPARATOR, + { + create: function() + { + return { + render : function( editor, output ) + { + output.push( '' ); + return {}; + } + }; + } + }); } }); })(); -/** - * The UI element that renders a toolbar separator. - * @type Object - * @example - */ -CKEDITOR.ui.separator = -{ - render : function( editor, output ) - { - output.push( '' ); - return {}; - } -}; +CKEDITOR.UI_SEPARATOR = 'separator'; /** * The "theme space" to which rendering the toolbar. For the default theme, @@ -407,38 +463,36 @@ CKEDITOR.config.toolbar_Basic = * // This is actually the default value. * config.toolbar_Full = * [ - * ['Source','-','Save','NewPage','Preview','-','Templates'], - * ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], - * ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], - * ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], + * { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] }, + * { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, + * { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, + * { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, * '/', - * ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], - * ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], - * ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], - * ['Link','Unlink','Anchor'], - * ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], + * { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, + * { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, + * { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, + * { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak' ] }, * '/', - * ['Styles','Format','Font','FontSize'], - * ['TextColor','BGColor'], - * ['Maximize', 'ShowBlocks','-','About'] + * { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, + * { name: 'colors', items : [ 'TextColor','BGColor' ] }, + * { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } * ]; */ CKEDITOR.config.toolbar_Full = [ - ['Source','-','Save','NewPage','Preview','-','Templates'], - ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], - ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], - ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], + { name: 'document', items : [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] }, + { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, + { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] }, + { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, '/', - ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], - ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], - ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], - ['Link','Unlink','Anchor'], - ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], + { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, + { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, + { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, + { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] }, '/', - ['Styles','Format','Font','FontSize'], - ['TextColor','BGColor'], - ['Maximize', 'ShowBlocks','-','About'] + { name: 'styles', items : [ 'Styles','Format','Font','FontSize' ] }, + { name: 'colors', items : [ 'TextColor','BGColor' ] }, + { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } ]; /** @@ -477,3 +531,16 @@ CKEDITOR.config.toolbarCanCollapse = true; * @example * config.toolbarStartupExpanded = false; */ + +/** + * When enabled, makes the arrow keys navigation cycle within the current + * toolbar group. Otherwise the arrows will move trought all items available in + * the toolbar. The TAB key will still be used to quickly jump among the + * toolbar groups. + * @name CKEDITOR.config.toolbarGroupCycling + * @since 3.6 + * @type Boolean + * @default true + * @example + * config.toolbarGroupCycling = false; + */