X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fcontextmenu%2Fplugin.js;h=b009dee02344480c88f80fdbbb243358aa9f716b;hb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7;hp=3f25a9461cb4bc2f143d1c0e7c9c96ad1bb732af;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/contextmenu/plugin.js b/_source/plugins/contextmenu/plugin.js index 3f25a94..b009dee 100644 --- a/_source/plugins/contextmenu/plugin.js +++ b/_source/plugins/contextmenu/plugin.js @@ -35,6 +35,18 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( editor.execCommand( commandName ); }, this); + + this.definition = + { + panel: + { + className : editor.skinClass + ' cke_contextmenu', + attributes : + { + 'aria-label' : editor.lang.contextmenu.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.definition ); 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; }; } @@ -138,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 ); @@ -146,12 +167,12 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( } if ( nativeContextMenuOnCtrl - && ( evt.$.ctrlKey || evt.$.metaKey ) ) + && ( CKEDITOR.env.mac ? evt.$.metaKey : evt.$.ctrlKey ) ) return; var target = evt.getTarget(); - if( !contextMenuOverrideButton ) + if ( !contextMenuOverrideButton ) { var ownerDoc = target.getDocument(); contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ; @@ -184,16 +205,9 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( if ( nativeContextMenuOnCtrl && // Safari on Windows always show 'ctrlKey' as true in 'contextmenu' event, // which make this property unreliable. (#4826) - ( CKEDITOR.env.webkit ? holdCtrlKey : domEvent.$.ctrlKey || domEvent.$.metaKey ) ) + ( CKEDITOR.env.webkit ? holdCtrlKey : ( CKEDITOR.env.mac ? domEvent.$.metaKey : domEvent.$.ctrlKey ) ) ) 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(); @@ -204,18 +218,18 @@ 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 ) { - holdCtrlKey = event.data.$.ctrlKey || event.data.$.metaKey; + holdCtrlKey = CKEDITOR.env.mac ? event.data.$.metaKey : event.data.$.ctrlKey ; }, resetOnKeyUp = function() { @@ -236,6 +250,15 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( show : function( offsetParent, corner, offsetX, offsetY ) { this.editor.focus(); + + // 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(); + } + this._.onMenu( offsetParent || CKEDITOR.document.getDocumentElement(), corner, offsetX || 0, offsetY || 0 ); } }