Line # Revision Author
1 3 ahitrov@rambler.ru /**
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;
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 t._getMenu(ed).showMenu(e.clientX, e.clientY);
46 Event.add(ed.getDoc(), 'click', hide);
47 Event.cancel(e);
48 }
49 });
50
51 function hide() {
52 if (t._menu) {
53 t._menu.removeAll();
54 t._menu.destroy();
55 Event.remove(ed.getDoc(), 'click', hide);
56 }
57 };
58
59 ed.onMouseDown.add(hide);
60 ed.onKeyDown.add(hide);
61 },
62
63 /**
64 * Returns information about the plugin as a name/value array.
65 * The current keys are longname, author, authorurl, infourl and version.
66 *
67 * @method getInfo
68 * @return {Object} Name/value array containing information about the plugin.
69 */
70 getInfo : function() {
71 return {
72 longname : 'Contextmenu',
73 author : 'Moxiecode Systems AB',
74 authorurl : 'http://tinymce.moxiecode.com',
75 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
76 version : tinymce.majorVersion + "." + tinymce.minorVersion
77 };
78 },
79
80 _getMenu : function(ed) {
81 var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;
82
83 if (m) {
84 m.removeAll();
85 m.destroy();
86 }
87
88 p1 = DOM.getPos(ed.getContentAreaContainer());
89 p2 = DOM.getPos(ed.getContainer());
90
91 m = ed.controlManager.createDropMenu('contextmenu', {
92 offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0),
93 offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0),
94 constrain : 1
95 });
96
97 t._menu = m;
98
99 m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
100 m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
101 m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
102
103 if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
104 m.addSeparator();
105 m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
106 m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
107 }
108
109 m.addSeparator();
110 m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
111
112 m.addSeparator();
113 am = m.addMenu({title : 'contextmenu.align'});
114 am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
115 am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
116 am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
117 am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
118
119 t.onContextMenu.dispatch(t, m, el, col);
120
121 return m;
122 }
123 });
124
125 // Register plugin
126 tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
127 })();