root / static / js / tinymce / plugins / contextmenu / editor_plugin_src.js @ 6ecbf4ec
History | View | Annotate | Download (4.5 kB)
1 |
/**
|
---|---|
2 |
* editor_plugin_src.js
|
3 |
*
|
4 |
* Copyright 2009, Moxiecode Systems AB
|
5 |
* Released under LGPL License.
|
6 |
*
|
7 |
* License: http://tinymce.moxiecode.com/license
|
8 |
* Contributing: http://tinymce.moxiecode.com/contributing
|
9 |
*/
|
10 |
|
11 |
(function() {
|
12 |
var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
|
13 |
|
14 |
/**
|
15 |
* This plugin a context menu to TinyMCE editor instances.
|
16 |
*
|
17 |
* @class tinymce.plugins.ContextMenu
|
18 |
*/
|
19 |
tinymce.create('tinymce.plugins.ContextMenu', {
|
20 |
/**
|
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.
|
24 |
*
|
25 |
* @method init
|
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.
|
28 |
*/
|
29 |
init : function(ed) { |
30 |
var t = this, lastRng; |
31 |
|
32 |
t.editor = ed; |
33 |
|
34 |
/**
|
35 |
* This event gets fired when the context menu is shown.
|
36 |
*
|
37 |
* @event onContextMenu
|
38 |
* @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
|
39 |
* @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
|
40 |
*/
|
41 |
t.onContextMenu = new tinymce.util.Dispatcher(this); |
42 |
|
43 |
ed.onContextMenu.add(function(ed, e) {
|
44 |
if (!e.ctrlKey) {
|
45 |
// Restore the last selection since it was removed
|
46 |
if (lastRng)
|
47 |
ed.selection.setRng(lastRng); |
48 |
|
49 |
t._getMenu(ed).showMenu(e.clientX, e.clientY); |
50 |
Event.add(ed.getDoc(), 'click', function(e) { |
51 |
hide(ed, e); |
52 |
}); |
53 |
Event.cancel(e); |
54 |
} |
55 |
}); |
56 |
|
57 |
ed.onRemove.add(function() {
|
58 |
if (t._menu)
|
59 |
t._menu.removeAll(); |
60 |
}); |
61 |
|
62 |
function hide(ed, e) { |
63 |
lastRng = null;
|
64 |
|
65 |
// Since the contextmenu event moves
|
66 |
// the selection we need to store it away
|
67 |
if (e && e.button == 2) { |
68 |
lastRng = ed.selection.getRng(); |
69 |
return;
|
70 |
} |
71 |
|
72 |
if (t._menu) {
|
73 |
t._menu.removeAll(); |
74 |
t._menu.destroy(); |
75 |
Event.remove(ed.getDoc(), 'click', hide);
|
76 |
} |
77 |
}; |
78 |
|
79 |
ed.onMouseDown.add(hide); |
80 |
ed.onKeyDown.add(hide); |
81 |
}, |
82 |
|
83 |
/**
|
84 |
* Returns information about the plugin as a name/value array.
|
85 |
* The current keys are longname, author, authorurl, infourl and version.
|
86 |
*
|
87 |
* @method getInfo
|
88 |
* @return {Object} Name/value array containing information about the plugin.
|
89 |
*/
|
90 |
getInfo : function() { |
91 |
return {
|
92 |
longname : 'Contextmenu', |
93 |
author : 'Moxiecode Systems AB', |
94 |
authorurl : 'http://tinymce.moxiecode.com', |
95 |
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu', |
96 |
version : tinymce.majorVersion + "." + tinymce.minorVersion |
97 |
}; |
98 |
}, |
99 |
|
100 |
_getMenu : function(ed) { |
101 |
var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2; |
102 |
|
103 |
if (m) {
|
104 |
m.removeAll(); |
105 |
m.destroy(); |
106 |
} |
107 |
|
108 |
p1 = DOM.getPos(ed.getContentAreaContainer()); |
109 |
p2 = DOM.getPos(ed.getContainer()); |
110 |
|
111 |
m = ed.controlManager.createDropMenu('contextmenu', {
|
112 |
offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0), |
113 |
offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0), |
114 |
constrain : 1 |
115 |
}); |
116 |
|
117 |
t._menu = m; |
118 |
|
119 |
m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col); |
120 |
m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col); |
121 |
m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'}); |
122 |
|
123 |
if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) { |
124 |
m.addSeparator(); |
125 |
m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true}); |
126 |
m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); |
127 |
} |
128 |
|
129 |
m.addSeparator(); |
130 |
m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); |
131 |
|
132 |
m.addSeparator(); |
133 |
am = m.addMenu({title : 'contextmenu.align'}); |
134 |
am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'}); |
135 |
am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'}); |
136 |
am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'}); |
137 |
am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'}); |
138 |
|
139 |
t.onContextMenu.dispatch(t, m, el, col); |
140 |
|
141 |
return m;
|
142 |
} |
143 |
}); |
144 |
|
145 |
// Register plugin
|
146 |
tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
|
147 |
})(); |