comparison static/js/tiny_mce/plugins/contextmenu/editor_plugin_src.js @ 442:6c182ceb7147

Fixing #217; upgrade TinyMCE to 3.4.2 and enable the paste plugin.
author Brian Neal <bgneal@gmail.com>
date Thu, 26 May 2011 00:43:49 +0000
parents 88b2b9cb8c1f
children
comparison
equal deleted inserted replaced
441:33d0c55e57a9 442:6c182ceb7147
25 * @method init 25 * @method init
26 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. 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. 27 * @param {string} url Absolute URL to where the plugin is located.
28 */ 28 */
29 init : function(ed) { 29 init : function(ed) {
30 var t = this, lastRng; 30 var t = this, showMenu, contextmenuNeverUseNative, realCtrlKey;
31 31
32 t.editor = ed; 32 t.editor = ed;
33
34 contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native;
33 35
34 /** 36 /**
35 * This event gets fired when the context menu is shown. 37 * This event gets fired when the context menu is shown.
36 * 38 *
37 * @event onContextMenu 39 * @event onContextMenu
38 * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event. 40 * @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. 41 * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
40 */ 42 */
41 t.onContextMenu = new tinymce.util.Dispatcher(this); 43 t.onContextMenu = new tinymce.util.Dispatcher(this);
42 44
43 ed.onContextMenu.add(function(ed, e) { 45 showMenu = ed.onContextMenu.add(function(ed, e) {
44 if (!e.ctrlKey) { 46 // Block TinyMCE menu on ctrlKey and work around Safari issue
45 // Restore the last selection since it was removed 47 if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative)
46 if (lastRng) 48 return;
47 ed.selection.setRng(lastRng);
48 49
49 t._getMenu(ed).showMenu(e.clientX, e.clientY); 50 Event.cancel(e);
50 Event.add(ed.getDoc(), 'click', function(e) { 51
51 hide(ed, e); 52 // Select the image if it's clicked. WebKit would other wise expand the selection
52 }); 53 if (e.target.nodeName == 'IMG')
53 Event.cancel(e); 54 ed.selection.select(e.target);
54 } 55
56 t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageX);
57 Event.add(ed.getDoc(), 'click', function(e) {
58 hide(ed, e);
59 });
60
61 ed.nodeChanged();
55 }); 62 });
56 63
57 ed.onRemove.add(function() { 64 ed.onRemove.add(function() {
58 if (t._menu) 65 if (t._menu)
59 t._menu.removeAll(); 66 t._menu.removeAll();
60 }); 67 });
61 68
62 function hide(ed, e) { 69 function hide(ed, e) {
63 lastRng = null; 70 realCtrlKey = 0;
64 71
65 // Since the contextmenu event moves 72 // Since the contextmenu event moves
66 // the selection we need to store it away 73 // the selection we need to store it away
67 if (e && e.button == 2) { 74 if (e && e.button == 2) {
68 lastRng = ed.selection.getRng(); 75 realCtrlKey = e.ctrlKey;
69 return; 76 return;
70 } 77 }
71 78
72 if (t._menu) { 79 if (t._menu) {
73 t._menu.removeAll(); 80 t._menu.removeAll();
76 } 83 }
77 }; 84 };
78 85
79 ed.onMouseDown.add(hide); 86 ed.onMouseDown.add(hide);
80 ed.onKeyDown.add(hide); 87 ed.onKeyDown.add(hide);
88 ed.onKeyDown.add(function(ed, e) {
89 if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) {
90 Event.cancel(e);
91 showMenu(ed, e);
92 }
93 });
81 }, 94 },
82 95
83 /** 96 /**
84 * Returns information about the plugin as a name/value array. 97 * Returns information about the plugin as a name/value array.
85 * The current keys are longname, author, authorurl, infourl and version. 98 * The current keys are longname, author, authorurl, infourl and version.
109 p2 = DOM.getPos(ed.getContainer()); 122 p2 = DOM.getPos(ed.getContainer());
110 123
111 m = ed.controlManager.createDropMenu('contextmenu', { 124 m = ed.controlManager.createDropMenu('contextmenu', {
112 offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0), 125 offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0),
113 offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0), 126 offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0),
114 constrain : 1 127 constrain : 1,
128 keyboard_focus: true
115 }); 129 });
116 130
117 t._menu = m; 131 t._menu = m;
118 132
119 m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col); 133 m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);