X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fcontextmenu%2Fplugin.js;h=60aad928cf05778addbcd3ac0ff3d8a08afef36e;hb=refs%2Ftags%2Fv3.2;hp=6cbc3e764cabf03df978ea092bbb5df744d75ea5;hpb=7cd80714081a8ffdf4a1a8d2c72f120ed5ef3d6d;p=ckeditor.git diff --git a/_source/plugins/contextmenu/plugin.js b/_source/plugins/contextmenu/plugin.js index 6cbc3e7..60aad92 100644 --- a/_source/plugins/contextmenu/plugin.js +++ b/_source/plugins/contextmenu/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -35,6 +35,18 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( editor.execCommand( commandName ); }, this); + + this._.definiton = + { + panel: + { + className : editor.skinClass + ' cke_contextmenu', + attributes : + { + 'aria-label' : editor.lang.common.options + } + } + }; }, _ : @@ -51,29 +63,38 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( } else { - menu = this._.menu = new CKEDITOR.menu( editor ); + menu = this._.menu = new CKEDITOR.menu( editor, this._.definiton ); menu.onClick = CKEDITOR.tools.bind( function( item ) { - var noUnlock = true; menu.hide(); - if ( CKEDITOR.env.ie ) - menu.onEscape(); - if ( item.onClick ) item.onClick(); else if ( item.command ) editor.execCommand( item.command ); - noUnlock = false; }, this ); - menu.onEscape = function() + menu.onEscape = function( keystroke ) { - editor.focus(); - - if ( CKEDITOR.env.ie ) - editor.getSelection().unlock( true ); + var parent = this.parent; + // 1. If it's sub-menu, restore the last focused item + // of upper level menu. + // 2. In case of a top-menu, close it. + if ( parent ) + { + parent._.panel.hideChild(); + // Restore parent block item focus. + var parentBlock = parent._.panel._.panel._.currentBlock, + parentFocusIndex = parentBlock._.focusIndex; + parentBlock._.markItem( parentFocusIndex ); + } + else if ( keystroke == 27 ) + { + this.hide(); + editor.focus(); + } + return false; }; } @@ -83,17 +104,15 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( var selection = this.editor.getSelection(), element = selection && selection.getStartElement(); - // Lock the selection in IE, so it can be restored when closing the - // menu. - if ( CKEDITOR.env.ie ) - selection.lock(); - menu.onHide = CKEDITOR.tools.bind( function() { menu.onHide = null; if ( CKEDITOR.env.ie ) - editor.getSelection().unlock(); + { + var selection = editor.getSelection(); + selection && selection.unlock(); + } this.onHide && this.onHide(); }, @@ -140,7 +159,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( element.on( 'mousedown', function( evt ) { evt = evt.data; - if( evt.$.button != 2 ) + if ( evt.$.button != 2 ) { if ( evt.getKeystroke() == CKEDITOR.CTRL + 1 ) element.fire( 'contextmenu', evt ); @@ -153,7 +172,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( var target = evt.getTarget(); - if( !contextMenuOverrideButton ) + if ( !contextMenuOverrideButton ) { var ownerDoc = target.getDocument(); contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ; @@ -189,6 +208,14 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( ( CKEDITOR.env.webkit ? holdCtrlKey : domEvent.$.ctrlKey || domEvent.$.metaKey ) ) return; + // Selection will be unavailable after context menu shows up + // in IE, lock it now. + if ( CKEDITOR.env.ie ) + { + var selection = this.editor.getSelection(); + selection && selection.lock(); + } + // Cancel the browser context menu. domEvent.preventDefault(); @@ -198,13 +225,13 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( CKEDITOR.tools.setTimeout( function() { - this._.onMenu( offsetParent, null, offsetX, offsetY ); + this.show( offsetParent, null, offsetX, offsetY ); }, 0, this ); }, this ); - if( CKEDITOR.env.webkit ) + if ( CKEDITOR.env.webkit ) { var holdCtrlKey, onKeyDown = function( event )