annotate media/js/tiny_mce/plugins/contextmenu/editor_plugin_src.js @ 260:3a4bbf9c2cce

Fixing #107. Apparently some signal handlers were getting connected twice (double import?) and thus saving a forum post would cause 2 email notifications to go out to the post topic's subscribers. Use the dispatch_uid parameter in the connect call to work around this issue.
author Brian Neal <bgneal@gmail.com>
date Wed, 22 Sep 2010 00:24:59 +0000
parents 6ed2932901fa
children
rev   line source
bgneal@45 1 /**
bgneal@183 2 * editor_plugin_src.js
bgneal@45 3 *
bgneal@183 4 * Copyright 2009, Moxiecode Systems AB
bgneal@183 5 * Released under LGPL License.
bgneal@183 6 *
bgneal@183 7 * License: http://tinymce.moxiecode.com/license
bgneal@183 8 * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@45 9 */
bgneal@45 10
bgneal@45 11 (function() {
bgneal@45 12 var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
bgneal@45 13
bgneal@183 14 /**
bgneal@183 15 * This plugin a context menu to TinyMCE editor instances.
bgneal@183 16 *
bgneal@183 17 * @class tinymce.plugins.ContextMenu
bgneal@183 18 */
bgneal@45 19 tinymce.create('tinymce.plugins.ContextMenu', {
bgneal@183 20 /**
bgneal@183 21 * Initializes the plugin, this will be executed after the plugin has been created.
bgneal@183 22 * This call is done before the editor instance has finished it's initialization so use the onInit event
bgneal@183 23 * of the editor instance to intercept that event.
bgneal@183 24 *
bgneal@183 25 * @method init
bgneal@183 26 * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
bgneal@183 27 * @param {string} url Absolute URL to where the plugin is located.
bgneal@183 28 */
bgneal@45 29 init : function(ed) {
bgneal@217 30 var t = this, lastRng;
bgneal@45 31
bgneal@45 32 t.editor = ed;
bgneal@183 33
bgneal@183 34 /**
bgneal@183 35 * This event gets fired when the context menu is shown.
bgneal@183 36 *
bgneal@183 37 * @event onContextMenu
bgneal@183 38 * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
bgneal@183 39 * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
bgneal@183 40 */
bgneal@45 41 t.onContextMenu = new tinymce.util.Dispatcher(this);
bgneal@45 42
bgneal@45 43 ed.onContextMenu.add(function(ed, e) {
bgneal@45 44 if (!e.ctrlKey) {
bgneal@217 45 // Restore the last selection since it was removed
bgneal@217 46 if (lastRng)
bgneal@217 47 ed.selection.setRng(lastRng);
bgneal@217 48
bgneal@45 49 t._getMenu(ed).showMenu(e.clientX, e.clientY);
bgneal@247 50 Event.add(ed.getDoc(), 'click', function(e) {
bgneal@247 51 hide(ed, e);
bgneal@247 52 });
bgneal@45 53 Event.cancel(e);
bgneal@45 54 }
bgneal@45 55 });
bgneal@45 56
bgneal@247 57 ed.onRemove.add(function() {
bgneal@247 58 if (t._menu)
bgneal@247 59 t._menu.removeAll();
bgneal@247 60 });
bgneal@247 61
bgneal@217 62 function hide(ed, e) {
bgneal@217 63 lastRng = null;
bgneal@217 64
bgneal@217 65 // Since the contextmenu event moves
bgneal@217 66 // the selection we need to store it away
bgneal@217 67 if (e && e.button == 2) {
bgneal@217 68 lastRng = ed.selection.getRng();
bgneal@217 69 return;
bgneal@217 70 }
bgneal@217 71
bgneal@45 72 if (t._menu) {
bgneal@45 73 t._menu.removeAll();
bgneal@45 74 t._menu.destroy();
bgneal@45 75 Event.remove(ed.getDoc(), 'click', hide);
bgneal@45 76 }
bgneal@45 77 };
bgneal@45 78
bgneal@45 79 ed.onMouseDown.add(hide);
bgneal@45 80 ed.onKeyDown.add(hide);
bgneal@45 81 },
bgneal@45 82
bgneal@183 83 /**
bgneal@183 84 * Returns information about the plugin as a name/value array.
bgneal@183 85 * The current keys are longname, author, authorurl, infourl and version.
bgneal@183 86 *
bgneal@183 87 * @method getInfo
bgneal@183 88 * @return {Object} Name/value array containing information about the plugin.
bgneal@183 89 */
bgneal@45 90 getInfo : function() {
bgneal@45 91 return {
bgneal@45 92 longname : 'Contextmenu',
bgneal@45 93 author : 'Moxiecode Systems AB',
bgneal@45 94 authorurl : 'http://tinymce.moxiecode.com',
bgneal@45 95 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
bgneal@45 96 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@45 97 };
bgneal@45 98 },
bgneal@45 99
bgneal@45 100 _getMenu : function(ed) {
bgneal@45 101 var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;
bgneal@45 102
bgneal@45 103 if (m) {
bgneal@45 104 m.removeAll();
bgneal@45 105 m.destroy();
bgneal@45 106 }
bgneal@45 107
bgneal@45 108 p1 = DOM.getPos(ed.getContentAreaContainer());
bgneal@45 109 p2 = DOM.getPos(ed.getContainer());
bgneal@45 110
bgneal@45 111 m = ed.controlManager.createDropMenu('contextmenu', {
bgneal@45 112 offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0),
bgneal@45 113 offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0),
bgneal@45 114 constrain : 1
bgneal@45 115 });
bgneal@45 116
bgneal@45 117 t._menu = m;
bgneal@45 118
bgneal@45 119 m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
bgneal@45 120 m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
bgneal@45 121 m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
bgneal@45 122
bgneal@45 123 if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
bgneal@45 124 m.addSeparator();
bgneal@45 125 m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
bgneal@45 126 m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
bgneal@45 127 }
bgneal@45 128
bgneal@45 129 m.addSeparator();
bgneal@45 130 m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
bgneal@45 131
bgneal@45 132 m.addSeparator();
bgneal@45 133 am = m.addMenu({title : 'contextmenu.align'});
bgneal@45 134 am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
bgneal@45 135 am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
bgneal@45 136 am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
bgneal@45 137 am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
bgneal@45 138
bgneal@45 139 t.onContextMenu.dispatch(t, m, el, col);
bgneal@45 140
bgneal@45 141 return m;
bgneal@45 142 }
bgneal@45 143 });
bgneal@45 144
bgneal@45 145 // Register plugin
bgneal@45 146 tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
bgneal@45 147 })();