4
* Copyright 2009, Moxiecode Systems AB
5
* Released under LGPL License.
7
* License: http://tinymce.moxiecode.com/license
8
* Contributing: http://tinymce.moxiecode.com/contributing
12
var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
15
* This plugin a context menu to TinyMCE editor instances.
17
* @class tinymce.plugins.ContextMenu
19
tinymce.create('tinymce.plugins.ContextMenu', {
21
* Initializes the plugin, this will be executed after the plugin has been created.
22
* This call is done before the editor instance has finished it's initialization so use the onInit event
23
* of the editor instance to intercept that event.
26
* @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
27
* @param {string} url Absolute URL to where the plugin is located.
30
var t = this, showMenu, contextmenuNeverUseNative, realCtrlKey, hideMenu;
34
contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native;
37
* This event gets fired when the context menu is shown.
39
* @event onContextMenu
40
* @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
41
* @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
43
t.onContextMenu = new tinymce.util.Dispatcher(this);
45
hideMenu = function(e) {
49
showMenu = ed.onContextMenu.add(function(ed, e) {
50
// Block TinyMCE menu on ctrlKey and work around Safari issue
51
if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative)
56
// Select the image if it's clicked. WebKit would other wise expand the selection
57
if (e.target.nodeName == 'IMG')
58
ed.selection.select(e.target);
60
t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageY);
61
Event.add(ed.getDoc(), 'click', hideMenu);
66
ed.onRemove.add(function() {
71
function hide(ed, e) {
74
// Since the contextmenu event moves
75
// the selection we need to store it away
76
if (e && e.button == 2) {
77
realCtrlKey = e.ctrlKey;
84
Event.remove(ed.getDoc(), 'click', hideMenu);
89
ed.onMouseDown.add(hide);
90
ed.onKeyDown.add(hide);
91
ed.onKeyDown.add(function(ed, e) {
92
if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) {
100
* Returns information about the plugin as a name/value array.
101
* The current keys are longname, author, authorurl, infourl and version.
104
* @return {Object} Name/value array containing information about the plugin.
106
getInfo : function() {
108
longname : 'Contextmenu',
109
author : 'Moxiecode Systems AB',
110
authorurl : 'http://tinymce.moxiecode.com',
111
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
112
version : tinymce.majorVersion + "." + tinymce.minorVersion
116
_getMenu : function(ed) {
117
var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p;
124
p = DOM.getPos(ed.getContentAreaContainer());
126
m = ed.controlManager.createDropMenu('contextmenu', {
127
offset_x : p.x + ed.getParam('contextmenu_offset_x', 0),
128
offset_y : p.y + ed.getParam('contextmenu_offset_y', 0),
135
m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
136
m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
137
m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
139
if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
141
m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
142
m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
146
m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
149
am = m.addMenu({title : 'contextmenu.align'});
150
am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
151
am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
152
am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
153
am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
155
t.onContextMenu.dispatch(t, m, el, col);
162
tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);