2 * editor_plugin_src.js
\r
4 * Copyright 2009, Moxiecode Systems AB
\r
5 * Released under LGPL License.
\r
7 * License: http://tinymce.moxiecode.com/license
\r
8 * Contributing: http://tinymce.moxiecode.com/contributing
\r
12 var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
\r
15 * This plugin a context menu to TinyMCE editor instances.
\r
17 * @class tinymce.plugins.ContextMenu
\r
19 tinymce.create('tinymce.plugins.ContextMenu', {
\r
21 * Initializes the plugin, this will be executed after the plugin has been created.
\r
22 * This call is done before the editor instance has finished it's initialization so use the onInit event
\r
23 * of the editor instance to intercept that event.
\r
26 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
\r
27 * @param {string} url Absolute URL to where the plugin is located.
\r
29 init : function(ed) {
\r
30 var t = this, lastRng;
\r
35 * This event gets fired when the context menu is shown.
\r
37 * @event onContextMenu
\r
38 * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
\r
39 * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
\r
41 t.onContextMenu = new tinymce.util.Dispatcher(this);
\r
43 ed.onContextMenu.add(function(ed, e) {
\r
45 // Restore the last selection since it was removed
\r
47 ed.selection.setRng(lastRng);
\r
49 t._getMenu(ed).showMenu(e.clientX, e.clientY);
\r
50 Event.add(ed.getDoc(), 'click', function(e) {
\r
57 ed.onRemove.add(function() {
\r
59 t._menu.removeAll();
\r
62 function hide(ed, e) {
\r
65 // Since the contextmenu event moves
\r
66 // the selection we need to store it away
\r
67 if (e && e.button == 2) {
\r
68 lastRng = ed.selection.getRng();
\r
73 t._menu.removeAll();
\r
75 Event.remove(ed.getDoc(), 'click', hide);
\r
79 ed.onMouseDown.add(hide);
\r
80 ed.onKeyDown.add(hide);
\r
84 * Returns information about the plugin as a name/value array.
\r
85 * The current keys are longname, author, authorurl, infourl and version.
\r
88 * @return {Object} Name/value array containing information about the plugin.
\r
90 getInfo : function() {
\r
92 longname : 'Contextmenu',
\r
93 author : 'Moxiecode Systems AB',
\r
94 authorurl : 'http://tinymce.moxiecode.com',
\r
95 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
\r
96 version : tinymce.majorVersion + "." + tinymce.minorVersion
\r
100 _getMenu : function(ed) {
\r
101 var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;
\r
108 p1 = DOM.getPos(ed.getContentAreaContainer());
\r
109 p2 = DOM.getPos(ed.getContainer());
\r
111 m = ed.controlManager.createDropMenu('contextmenu', {
\r
112 offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0),
\r
113 offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0),
\r
119 m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
\r
120 m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
\r
121 m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
\r
123 if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
\r
125 m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
\r
126 m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
\r
130 m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
\r
133 am = m.addMenu({title : 'contextmenu.align'});
\r
134 am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
\r
135 am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
\r
136 am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
\r
137 am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
\r
139 t.onContextMenu.dispatch(t, m, el, col);
\r
146 tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
\r