2014-04-11 20:07:18 +00:00
|
|
|
|
/**
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
|
|
|
|
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CKEDITOR.plugins.add( 'contextmenu', {
|
|
|
|
|
requires: 'menu',
|
|
|
|
|
|
2018-06-17 16:07:19 +00:00
|
|
|
|
// jscs:disable maximumLineLength
|
|
|
|
|
lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,oc,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
|
|
|
|
|
// jscs:enable maximumLineLength
|
|
|
|
|
|
|
|
|
|
// Make sure the base class (CKEDITOR.menu) is loaded before it (https://dev.ckeditor.com/ticket/3318).
|
2014-04-11 20:07:18 +00:00
|
|
|
|
onLoad: function() {
|
|
|
|
|
/**
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* Class replacing the non-configurable native context menu with a configurable CKEditor's equivalent.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*
|
|
|
|
|
* @class
|
|
|
|
|
* @extends CKEDITOR.menu
|
|
|
|
|
*/
|
|
|
|
|
CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass( {
|
|
|
|
|
base: CKEDITOR.menu,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates the CKEDITOR.plugins.contextMenu class instance.
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param {CKEDITOR.editor} editor
|
|
|
|
|
*/
|
|
|
|
|
$: function( editor ) {
|
|
|
|
|
this.base.call( this, editor, {
|
|
|
|
|
panel: {
|
|
|
|
|
className: 'cke_menu_panel',
|
|
|
|
|
attributes: {
|
|
|
|
|
'aria-label': editor.lang.contextmenu.options
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
proto: {
|
|
|
|
|
/**
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* Starts watching on native context menu triggers (<kbd>Option</kbd> key, right click) on the given element.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*
|
|
|
|
|
* @param {CKEDITOR.dom.element} element
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* @param {Boolean} [nativeContextMenuOnCtrl] Whether to open native context menu if the
|
|
|
|
|
* <kbd>Ctrl</kbd> key is held on opening the context menu. See {@link CKEDITOR.config#browserContextMenuOnCtrl}.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*/
|
|
|
|
|
addTarget: function( element, nativeContextMenuOnCtrl ) {
|
|
|
|
|
element.on( 'contextmenu', function( event ) {
|
|
|
|
|
var domEvent = event.data,
|
|
|
|
|
isCtrlKeyDown =
|
|
|
|
|
// Safari on Windows always show 'ctrlKey' as true in 'contextmenu' event,
|
2018-06-17 16:07:19 +00:00
|
|
|
|
// which make this property unreliable. (https://dev.ckeditor.com/ticket/4826)
|
2014-04-11 20:07:18 +00:00
|
|
|
|
( CKEDITOR.env.webkit ? holdCtrlKey : ( CKEDITOR.env.mac ? domEvent.$.metaKey : domEvent.$.ctrlKey ) );
|
|
|
|
|
|
|
|
|
|
if ( nativeContextMenuOnCtrl && isCtrlKeyDown )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Cancel the browser context menu.
|
|
|
|
|
domEvent.preventDefault();
|
|
|
|
|
|
2018-06-17 16:07:19 +00:00
|
|
|
|
// Fix selection when non-editable element in Webkit/Blink (Mac) (https://dev.ckeditor.com/ticket/11306).
|
|
|
|
|
if ( CKEDITOR.env.mac && CKEDITOR.env.webkit ) {
|
|
|
|
|
var editor = this.editor,
|
|
|
|
|
contentEditableParent = new CKEDITOR.dom.elementPath( domEvent.getTarget(), editor.editable() ).contains( function( el ) {
|
|
|
|
|
// Return when non-editable or nested editable element is found.
|
|
|
|
|
return el.hasAttribute( 'contenteditable' );
|
|
|
|
|
}, true ); // Exclude editor's editable.
|
|
|
|
|
|
|
|
|
|
// Fake selection for non-editables only (to exclude nested editables).
|
|
|
|
|
if ( contentEditableParent && contentEditableParent.getAttribute( 'contenteditable' ) == 'false' )
|
|
|
|
|
editor.getSelection().fake( contentEditableParent );
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 20:07:18 +00:00
|
|
|
|
var doc = domEvent.getTarget().getDocument(),
|
|
|
|
|
offsetParent = domEvent.getTarget().getDocument().getDocumentElement(),
|
|
|
|
|
fromFrame = !doc.equals( CKEDITOR.document ),
|
|
|
|
|
scroll = doc.getWindow().getScrollPosition(),
|
|
|
|
|
offsetX = fromFrame ? domEvent.$.clientX : domEvent.$.pageX || scroll.x + domEvent.$.clientX,
|
|
|
|
|
offsetY = fromFrame ? domEvent.$.clientY : domEvent.$.pageY || scroll.y + domEvent.$.clientY;
|
|
|
|
|
|
|
|
|
|
CKEDITOR.tools.setTimeout( function() {
|
|
|
|
|
this.open( offsetParent, null, offsetX, offsetY );
|
|
|
|
|
|
2018-06-17 16:07:19 +00:00
|
|
|
|
// IE needs a short while to allow selection change before opening menu. (https://dev.ckeditor.com/ticket/7908)
|
2014-04-11 20:07:18 +00:00
|
|
|
|
}, CKEDITOR.env.ie ? 200 : 0, this );
|
|
|
|
|
}, this );
|
|
|
|
|
|
|
|
|
|
if ( CKEDITOR.env.webkit ) {
|
|
|
|
|
var holdCtrlKey,
|
|
|
|
|
onKeyDown = function( event ) {
|
|
|
|
|
holdCtrlKey = CKEDITOR.env.mac ? event.data.$.metaKey : event.data.$.ctrlKey;
|
|
|
|
|
},
|
|
|
|
|
resetOnKeyUp = function() {
|
|
|
|
|
holdCtrlKey = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
element.on( 'keydown', onKeyDown );
|
|
|
|
|
element.on( 'keyup', resetOnKeyUp );
|
|
|
|
|
element.on( 'contextmenu', resetOnKeyUp );
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* Opens the context menu in the given location. See the {@link CKEDITOR.menu#show} method.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*
|
|
|
|
|
* @param {CKEDITOR.dom.element} offsetParent
|
|
|
|
|
* @param {Number} [corner]
|
|
|
|
|
* @param {Number} [offsetX]
|
|
|
|
|
* @param {Number} [offsetY]
|
|
|
|
|
*/
|
|
|
|
|
open: function( offsetParent, corner, offsetX, offsetY ) {
|
2018-06-17 16:07:19 +00:00
|
|
|
|
if ( this.editor.config.enableContextMenu === false ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-11 20:07:18 +00:00
|
|
|
|
this.editor.focus();
|
|
|
|
|
offsetParent = offsetParent || CKEDITOR.document.getDocumentElement();
|
|
|
|
|
|
2018-06-17 16:07:19 +00:00
|
|
|
|
// https://dev.ckeditor.com/ticket/9362: Force selection check to update commands' states in the new context.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
this.editor.selectionChange( 1 );
|
|
|
|
|
|
|
|
|
|
this.show( offsetParent, corner, offsetX, offsetY );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
beforeInit: function( editor ) {
|
|
|
|
|
/**
|
|
|
|
|
* @readonly
|
|
|
|
|
* @property {CKEDITOR.plugins.contextMenu} contextMenu
|
|
|
|
|
* @member CKEDITOR.editor
|
|
|
|
|
*/
|
|
|
|
|
var contextMenu = editor.contextMenu = new CKEDITOR.plugins.contextMenu( editor );
|
|
|
|
|
|
|
|
|
|
editor.on( 'contentDom', function() {
|
|
|
|
|
contextMenu.addTarget( editor.editable(), editor.config.browserContextMenuOnCtrl !== false );
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
editor.addCommand( 'contextMenu', {
|
|
|
|
|
exec: function() {
|
|
|
|
|
editor.contextMenu.open( editor.document.getBody() );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
editor.setKeystroke( CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' );
|
|
|
|
|
editor.setKeystroke( CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-17 16:07:19 +00:00
|
|
|
|
* Whether to show the browser native context menu when the <kbd>Ctrl</kbd> or
|
|
|
|
|
* <kbd>Meta</kbd> (Mac) key is pressed on opening the context menu with the
|
|
|
|
|
* right mouse button click or the <kbd>Menu</kbd> key.
|
2014-04-11 20:07:18 +00:00
|
|
|
|
*
|
|
|
|
|
* config.browserContextMenuOnCtrl = false;
|
|
|
|
|
*
|
|
|
|
|
* @since 3.0.2
|
|
|
|
|
* @cfg {Boolean} [browserContextMenuOnCtrl=true]
|
|
|
|
|
* @member CKEDITOR.config
|
|
|
|
|
*/
|
2018-06-17 16:07:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether to enable the context menu. Regardless of the setting the [Context Menu](https://ckeditor.com/cke4/addon/contextmenu)
|
|
|
|
|
* plugin is still loaded.
|
|
|
|
|
*
|
|
|
|
|
* config.enableContextMenu = false;
|
|
|
|
|
*
|
|
|
|
|
* @since 4.7.0
|
|
|
|
|
* @cfg {Boolean} [enableContextMenu=true]
|
|
|
|
|
* @member CKEDITOR.config
|
|
|
|
|
*/
|