X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fcontextmenu%2Fplugin.js;h=8d7cb8d59e3b69136a029253d28865736dadf84f;hb=039a051ccf3901311661022a30afd60fc38130c9;hp=60aad928cf05778addbcd3ac0ff3d8a08afef36e;hpb=059b4c2fef02528bf1af189f7996e80652faddfb;p=ckeditor.git diff --git a/_source/plugins/contextmenu/plugin.js b/_source/plugins/contextmenu/plugin.js index 60aad92..8d7cb8d 100644 --- a/_source/plugins/contextmenu/plugin.js +++ b/_source/plugins/contextmenu/plugin.js @@ -25,7 +25,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( { $ : function( editor ) { - this.id = 'cke_' + CKEDITOR.tools.getNextNumber(); + this.id = CKEDITOR.tools.getNextId(); this.editor = editor; this._.listeners = []; this._.functionId = CKEDITOR.tools.addFunction( function( commandName ) @@ -36,14 +36,14 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( }, this); - this._.definiton = + this.definition = { panel: { className : editor.skinClass + ' cke_contextmenu', attributes : { - 'aria-label' : editor.lang.common.options + 'aria-label' : editor.lang.contextmenu.options } } }; @@ -63,7 +63,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( } else { - menu = this._.menu = new CKEDITOR.menu( editor, this._.definiton ); + menu = this._.menu = new CKEDITOR.menu( editor, this.definition ); menu.onClick = CKEDITOR.tools.bind( function( item ) { menu.hide(); @@ -147,13 +147,14 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( { addTarget : function( element, nativeContextMenuOnCtrl ) { - // Opera doesn't support 'contextmenu' event, we have duo approaches employed here: - // 1. Inherit the 'button override' hack we introduced in v2 (#4530), while this require the Opera browser - // option 'Allow script to detect context menu/right click events' to be always turned on. + + // For browsers (Opera <=10a) that doesn't support 'contextmenu' event, we have duo approaches employed here: + // 1. Inherit the 'button override' hack we introduced in v2 (#4530) (In Opera browser, this require the + // option 'Allow script to detect context menu/right click events' to be always turned on). // 2. Considering the fact that ctrl/meta key is not been occupied // for multiple range selecting (like Gecko), we use this key // combination as a fallback for triggering context-menu. (#4530) - if ( CKEDITOR.env.opera ) + if ( CKEDITOR.env.opera && !( 'oncontextmenu' in document.body ) ) { var contextMenuOverrideButton; element.on( 'mousedown', function( evt ) @@ -167,7 +168,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( } if ( nativeContextMenuOnCtrl - && ( evt.$.ctrlKey || evt.$.metaKey ) ) + && ( CKEDITOR.env.mac ? evt.$.metaKey : evt.$.ctrlKey ) ) return; var target = evt.getTarget(); @@ -205,16 +206,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(); @@ -231,12 +225,25 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( }, this ); + if ( CKEDITOR.env.opera ) + { + // 'contextmenu' event triggered by Windows menu key is unpreventable, + // cancel the key event itself. (#6534) + element.on( 'keypress' , function ( evt ) + { + var domEvent = evt.data; + + if ( domEvent.$.keyCode === 0 ) + domEvent.preventDefault(); + }); + } + 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() { @@ -257,6 +264,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 ); } }