X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fmenu%2Fplugin.js;h=6e6b98eb9723651ff738973ad71aa7520ef9dcc7;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=5d37ffda020723f252a92c96819f7fb8227f90d3;hpb=9afde8772159bd3436f1f5b7862960307710ae5a;p=ckeditor.git diff --git a/_source/plugins/menu/plugin.js b/_source/plugins/menu/plugin.js index 5d37ffd..6e6b98e 100644 --- a/_source/plugins/menu/plugin.js +++ b/_source/plugins/menu/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -14,17 +14,36 @@ CKEDITOR.plugins.add( 'menu', for ( var i = 0 ; i < groups.length ; i++ ) groupsOrder[ groups[ i ] ] = i + 1; + /** + * Registers an item group to the editor context menu in order to make it + * possible to associate it with menu items later. + * @name CKEDITOR.editor.prototype.addMenuGroup + * @param {String} name Specify a group name. + * @param {Number} [order=100] Define the display sequence of this group + * inside the menu. A smaller value gets displayed first. + */ editor.addMenuGroup = function( name, order ) { groupsOrder[ name ] = order || 100; }; + /** + * Adds an item from the specified definition to the editor context menu. + * @name CKEDITOR.editor.prototype.addMenuItem + * @param {String} name The menu item name. + * @param {CKEDITOR.menu.definition} definition The menu item definition. + */ editor.addMenuItem = function( name, definition ) { if ( groupsOrder[ definition.group ] ) menuItems[ name ] = new CKEDITOR.menuItem( this, name, definition ); }; + /** + * Adds one or more items from the specified definition array to the editor context menu. + * @name CKEDITOR.editor.prototype.addMenuItems + * @param {Array} definitions List of definitions for each menu item as if {@link CKEDITOR.editor.addMenuItem} is called. + */ editor.addMenuItems = function( definitions ) { for ( var itemName in definitions ) @@ -33,10 +52,27 @@ CKEDITOR.plugins.add( 'menu', } }; + /** + * Retrieves a particular menu item definition from the editor context menu. + * @name CKEDITOR.editor.prototype.getMenuItem + * @param {String} name The name of the desired menu item. + * @return {CKEDITOR.menu.definition} + */ editor.getMenuItem = function( name ) { return menuItems[ name ]; }; + + /** + * Removes a particular menu item added before from the editor context menu. + * @name CKEDITOR.editor.prototype.removeMenuItem + * @param {String} name The name of the desired menu item. + * @since 3.6.1 + */ + editor.removeMenuItem = function( name ) + { + delete menuItems[ name ]; + }; }, requires : [ 'floatpanel' ] @@ -49,7 +85,7 @@ CKEDITOR.plugins.add( 'menu', $ : function( editor, definition ) { definition = this._.definition = definition || {}; - this.id = 'cke_' + CKEDITOR.tools.getNextNumber(); + this.id = CKEDITOR.tools.getNextId(); this.editor = editor; this.items = []; @@ -97,7 +133,7 @@ CKEDITOR.plugins.add( 'menu', { var item = this.editor.getMenuItem( itemName ); - if ( item ) + if ( item && ( !item.command || this.editor.getCommand( item.command ).state ) ) { item.state = listenerItems[ itemName ]; this.add( item ); @@ -109,7 +145,7 @@ CKEDITOR.plugins.add( 'menu', onClick : function( item ) { - this.hide(); + this.hide( false ); if ( item.onClick ) item.onClick(); @@ -132,22 +168,24 @@ CKEDITOR.plugins.add( 'menu', parentBlock._.markItem( parentFocusIndex ); } else if ( keystroke == 27 ) - { this.hide(); - this.editor.focus(); - } + return false; }, onHide : function() { - if ( CKEDITOR.env.ie ) + this._.unlockSelection(); + this.onHide && this.onHide(); + }, + + unlockSelection : function() { + // Unlock the selection upon first panel closing. + if ( CKEDITOR.env.ie && !this.parent ) { var selection = this.editor.getSelection(); - selection && selection.unlock(); + selection && selection.unlock( true ); } - - this.onHide && this.onHide(); }, showSubMenu : function( index ) @@ -224,8 +262,10 @@ CKEDITOR.plugins.add( 'menu', { this._.onShow(); // Don't menu with zero items. - if ( ! this.items.length ) + if ( ! this.items.length ) { + this._.unlockSelection(); return; + } } corner = corner || ( this.editor.lang.dir == 'rtl' ? 2 : 1 ); @@ -265,8 +305,9 @@ CKEDITOR.plugins.add( 'menu', keys[ 9 ] = 'next'; // TAB keys[ 38 ] = 'prev'; // ARROW-UP keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB - keys[ 32 ] = 'click'; // SPACE - keys[ ( editor.lang.dir == 'rtl' ? 37 : 39 ) ] = 'click'; // ARROW-RIGHT/ARROW-LEFT(rtl) + keys[ ( editor.lang.dir == 'rtl' ? 37 : 39 ) ]= CKEDITOR.env.ie ? 'mouseup' : 'click'; // ARROW-RIGHT/ARROW-LEFT(rtl) + keys[ 32 ] = CKEDITOR.env.ie ? 'mouseup' : 'click'; // SPACE + CKEDITOR.env.ie && ( keys[ 13 ] = 'mouseup' ); // Manage ENTER, since onclick is blocked in IE (#8041). element = this._.element = block.element; element.addClass( editor.skinClass ); @@ -351,10 +392,10 @@ CKEDITOR.plugins.add( 'menu', this._.listeners.push( listenerFn ); }, - hide : function() + hide : function( returnFocus ) { this._.onHide && this._.onHide(); - this._.panel && this._.panel.hide(); + this._.panel && this._.panel.hide( returnFocus ); } } }); @@ -411,7 +452,7 @@ CKEDITOR.plugins.add( 'menu', var hasSubMenu = this.getItems; output.push( - '' + + '' + '' + '