1 | /** |
---|
2 | * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z 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 | t._getMenu(ed).showMenu(e.clientX, e.clientY); |
---|
20 | Event.cancel(e); |
---|
21 | }); |
---|
22 | |
---|
23 | function hide() { |
---|
24 | if (t._menu) { |
---|
25 | t._menu.removeAll(); |
---|
26 | t._menu.destroy(); |
---|
27 | } |
---|
28 | }; |
---|
29 | |
---|
30 | ed.onMouseDown.add(hide); |
---|
31 | ed.onKeyDown.add(hide); |
---|
32 | Event.add(document, 'click', hide); |
---|
33 | }, |
---|
34 | |
---|
35 | _getMenu : function(ed) { |
---|
36 | var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am; |
---|
37 | |
---|
38 | if (m) { |
---|
39 | m.removeAll(); |
---|
40 | m.destroy(); |
---|
41 | } |
---|
42 | |
---|
43 | p1 = DOM.getPos(ed.getContentAreaContainer()); |
---|
44 | p2 = DOM.getPos(ed.getContainer()); |
---|
45 | |
---|
46 | m = ed.controlManager.createDropMenu('contextmenu', { |
---|
47 | offset_x : p1.x, |
---|
48 | offset_y : p1.y, |
---|
49 | /* vp_offset_x : p2.x, |
---|
50 | vp_offset_y : p2.y,*/ |
---|
51 | constrain : 1 |
---|
52 | }); |
---|
53 | |
---|
54 | t._menu = m; |
---|
55 | |
---|
56 | m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col); |
---|
57 | m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col); |
---|
58 | m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'}); |
---|
59 | |
---|
60 | if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) { |
---|
61 | m.addSeparator(); |
---|
62 | m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true}); |
---|
63 | m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); |
---|
64 | } |
---|
65 | |
---|
66 | m.addSeparator(); |
---|
67 | m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); |
---|
68 | |
---|
69 | m.addSeparator(); |
---|
70 | am = m.addMenu({title : 'contextmenu.align'}); |
---|
71 | am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'}); |
---|
72 | am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'}); |
---|
73 | am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'}); |
---|
74 | am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'}); |
---|
75 | |
---|
76 | t.onContextMenu.dispatch(t, m, el, col); |
---|
77 | |
---|
78 | return m; |
---|
79 | } |
---|
80 | }); |
---|
81 | |
---|
82 | // Register plugin |
---|
83 | tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu); |
---|
84 | })(); |
---|