cmc-sales/webroot/js/ckeditor/_source/plugins/contextmenu/plugin.js

178 lines
5 KiB
JavaScript
Raw Normal View History

2009-10-10 00:15:12 -07:00
/*
2011-05-16 20:19:32 -07:00
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
2009-10-10 00:15:12 -07:00
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.plugins.add( 'contextmenu',
{
requires : [ 'menu' ],
2011-05-16 20:19:32 -07:00
// Make sure the base class (CKEDITOR.menu) is loaded before it (#3318).
onLoad : function()
2009-10-10 00:15:12 -07:00
{
2011-05-16 20:19:32 -07:00
CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
{
base : CKEDITOR.menu,
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
$ : function( editor )
2009-10-10 00:15:12 -07:00
{
2011-05-16 20:19:32 -07:00
this.base.call( this, editor,
{
panel:
2009-10-10 00:15:12 -07:00
{
2011-05-16 20:19:32 -07:00
className : editor.skinClass + ' cke_contextmenu',
attributes :
{
'aria-label' : editor.lang.contextmenu.options
}
2009-10-10 00:15:12 -07:00
}
2011-05-16 20:19:32 -07:00
});
2009-10-10 00:15:12 -07:00
},
2011-05-16 20:19:32 -07:00
proto :
{
2011-05-16 20:19:32 -07:00
addTarget : function( element, nativeContextMenuOnCtrl )
{
2011-05-16 20:19:32 -07:00
// 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.
// 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 && !( 'oncontextmenu' in document.body ))
{
2011-05-16 20:19:32 -07:00
var contextMenuOverrideButton;
element.on( 'mousedown', function( evt )
{
evt = evt.data;
if ( evt.$.button != 2 )
{
if ( evt.getKeystroke() == CKEDITOR.CTRL + 1 )
element.fire( 'contextmenu', evt );
return;
}
if ( nativeContextMenuOnCtrl
&& ( CKEDITOR.env.mac ? evt.$.metaKey : evt.$.ctrlKey ) )
return;
var target = evt.getTarget();
if ( !contextMenuOverrideButton )
{
var ownerDoc = target.getDocument();
contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ;
contextMenuOverrideButton.$.type = 'button' ;
ownerDoc.getBody().append( contextMenuOverrideButton ) ;
}
contextMenuOverrideButton.setAttribute( 'style', 'position:absolute;top:' + ( evt.$.clientY - 2 ) +
'px;left:' + ( evt.$.clientX - 2 ) +
'px;width:5px;height:5px;opacity:0.01' );
} );
element.on( 'mouseup', function ( evt )
{
if ( contextMenuOverrideButton )
{
contextMenuOverrideButton.remove();
contextMenuOverrideButton = undefined;
// Simulate 'contextmenu' event.
element.fire( 'contextmenu', evt.data );
}
} );
}
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
element.on( 'contextmenu', function( event )
{
var domEvent = event.data;
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
if ( nativeContextMenuOnCtrl &&
// Safari on Windows always show 'ctrlKey' as true in 'contextmenu' event,
// which make this property unreliable. (#4826)
( CKEDITOR.env.webkit ? holdCtrlKey : ( CKEDITOR.env.mac ? domEvent.$.metaKey : domEvent.$.ctrlKey ) ) )
return;
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
// Cancel the browser context menu.
domEvent.preventDefault();
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
var offsetParent = domEvent.getTarget().getDocument().getDocumentElement(),
offsetX = domEvent.$.clientX,
offsetY = domEvent.$.clientY;
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
CKEDITOR.tools.setTimeout( function()
{
this.open( offsetParent, null, offsetX, offsetY );
},
0, this );
},
this );
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
if ( CKEDITOR.env.opera )
2009-10-10 00:15:12 -07:00
{
2011-05-16 20:19:32 -07:00
// 'contextmenu' event triggered by Windows menu key is unpreventable,
// cancel the key event itself. (#6534)
element.on( 'keypress' , function ( evt )
2009-10-10 00:15:12 -07:00
{
2011-05-16 20:19:32 -07:00
var domEvent = evt.data;
2009-10-10 00:15:12 -07:00
2011-05-16 20:19:32 -07:00
if ( domEvent.$.keyCode === 0 )
domEvent.preventDefault();
});
}
2011-05-16 20:19:32 -07:00
if ( CKEDITOR.env.webkit )
{
2011-05-16 20:19:32 -07:00
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 );
}
2011-05-16 20:19:32 -07:00
},
2011-05-16 20:19:32 -07:00
open : function( offsetParent, corner, offsetX, offsetY )
{
2011-05-16 20:19:32 -07:00
this.editor.focus();
offsetParent = offsetParent || CKEDITOR.document.getDocumentElement();
this.show( offsetParent, corner, offsetX, offsetY );
}
}
2011-05-16 20:19:32 -07:00
});
},
2011-05-16 20:19:32 -07:00
beforeInit : function( editor )
{
editor.contextMenu = new CKEDITOR.plugins.contextMenu( editor );
2011-05-16 20:19:32 -07:00
editor.addCommand( 'contextMenu',
{
2011-05-16 20:19:32 -07:00
exec : function()
{
2011-05-16 20:19:32 -07:00
editor.contextMenu.open( editor.document.getBody() );
}
});
2009-10-10 00:15:12 -07:00
}
});
/**
* Whether to show the browser native context menu when the CTRL or the
* META (Mac) key is pressed while opening the context menu.
* @name CKEDITOR.config.browserContextMenuOnCtrl
* @since 3.0.2
* @type Boolean
* @default true
* @example
* config.browserContextMenuOnCtrl = false;
*/