PageRenderTime 47ms CodeModel.GetById 38ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/contextmenu/editor_plugin_src.js

http://n23.googlecode.com/
JavaScript | 97 lines | 69 code | 19 blank | 9 comment | 8 complexity | b218adc7d5f48eb4d62695929d1484d2 MD5 | raw file
 1/**
 2 * $Id: editor_plugin_src.js 755 2008-03-29 19:14:42Z spocke $
 3 *
 4 * @author Moxiecode
 5 * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
 6 */
 7
 8(function() {
 9	var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
10
11	tinymce.create('tinymce.plugins.ContextMenu', {
12		init : function(ed) {
13			var t = this;
14
15			t.editor = ed;
16			t.onContextMenu = new tinymce.util.Dispatcher(this);
17
18			ed.onContextMenu.add(function(ed, e) {
19				if (!e.ctrlKey) {
20					t._getMenu(ed).showMenu(e.clientX, e.clientY);
21					Event.add(document, 'click', hide);
22					Event.cancel(e);
23				}
24			});
25
26			function hide() {
27				if (t._menu) {
28					t._menu.removeAll();
29					t._menu.destroy();
30					Event.remove(document, 'click', hide);
31				}
32			};
33
34			ed.onMouseDown.add(hide);
35			ed.onKeyDown.add(hide);
36		},
37
38		getInfo : function() {
39			return {
40				longname : 'Contextmenu',
41				author : 'Moxiecode Systems AB',
42				authorurl : 'http://tinymce.moxiecode.com',
43				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
44				version : tinymce.majorVersion + "." + tinymce.minorVersion
45			};
46		},
47
48		_getMenu : function(ed) {
49			var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;
50
51			if (m) {
52				m.removeAll();
53				m.destroy();
54			}
55
56			p1 = DOM.getPos(ed.getContentAreaContainer());
57			p2 = DOM.getPos(ed.getContainer());
58
59			m = ed.controlManager.createDropMenu('contextmenu', {
60				offset_x : p1.x,
61				offset_y : p1.y,
62/*				vp_offset_x : p2.x,
63				vp_offset_y : p2.y,*/
64				constrain : 1
65			});
66
67			t._menu = m;
68
69			m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
70			m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
71			m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
72
73			if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
74				m.addSeparator();
75				m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
76				m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
77			}
78
79			m.addSeparator();
80			m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
81
82			m.addSeparator();
83			am = m.addMenu({title : 'contextmenu.align'});
84			am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
85			am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
86			am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
87			am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
88
89			t.onContextMenu.dispatch(t, m, el, col);
90
91			return m;
92		}
93	});
94
95	// Register plugin
96	tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
97})();