/**\r
- * $Id: editor_plugin_src.js 755 2008-03-29 19:14:42Z spocke $\r
+ * editor_plugin_src.js\r
*\r
- * @author Moxiecode\r
- * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
+ *\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
*/\r
\r
(function() {\r
var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;\r
\r
+ /**\r
+ * This plugin a context menu to TinyMCE editor instances.\r
+ *\r
+ * @class tinymce.plugins.ContextMenu\r
+ */\r
tinymce.create('tinymce.plugins.ContextMenu', {\r
+ /**\r
+ * Initializes the plugin, this will be executed after the plugin has been created.\r
+ * This call is done before the editor instance has finished it's initialization so use the onInit event\r
+ * of the editor instance to intercept that event.\r
+ *\r
+ * @method init\r
+ * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.\r
+ * @param {string} url Absolute URL to where the plugin is located.\r
+ */\r
init : function(ed) {\r
- var t = this;\r
+ var t = this, lastRng;\r
\r
t.editor = ed;\r
+\r
+ /**\r
+ * This event gets fired when the context menu is shown.\r
+ *\r
+ * @event onContextMenu\r
+ * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.\r
+ * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.\r
+ */\r
t.onContextMenu = new tinymce.util.Dispatcher(this);\r
\r
ed.onContextMenu.add(function(ed, e) {\r
if (!e.ctrlKey) {\r
+ // Restore the last selection since it was removed\r
+ if (lastRng)\r
+ ed.selection.setRng(lastRng);\r
+\r
t._getMenu(ed).showMenu(e.clientX, e.clientY);\r
- Event.add(document, 'click', hide);\r
+ Event.add(ed.getDoc(), 'click', function(e) {\r
+ hide(ed, e);\r
+ });\r
Event.cancel(e);\r
}\r
});\r
\r
- function hide() {\r
+ ed.onRemove.add(function() {\r
+ if (t._menu)\r
+ t._menu.removeAll();\r
+ });\r
+\r
+ function hide(ed, e) {\r
+ lastRng = null;\r
+\r
+ // Since the contextmenu event moves\r
+ // the selection we need to store it away\r
+ if (e && e.button == 2) {\r
+ lastRng = ed.selection.getRng();\r
+ return;\r
+ }\r
+\r
if (t._menu) {\r
t._menu.removeAll();\r
t._menu.destroy();\r
- Event.remove(document, 'click', hide);\r
+ Event.remove(ed.getDoc(), 'click', hide);\r
}\r
};\r
\r
ed.onKeyDown.add(hide);\r
},\r
\r
+ /**\r
+ * Returns information about the plugin as a name/value array.\r
+ * The current keys are longname, author, authorurl, infourl and version.\r
+ *\r
+ * @method getInfo\r
+ * @return {Object} Name/value array containing information about the plugin.\r
+ */\r
getInfo : function() {\r
return {\r
longname : 'Contextmenu',\r
p2 = DOM.getPos(ed.getContainer());\r
\r
m = ed.controlManager.createDropMenu('contextmenu', {\r
- offset_x : p1.x,\r
- offset_y : p1.y,\r
-/* vp_offset_x : p2.x,\r
- vp_offset_y : p2.y,*/\r
+ offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0),\r
+ offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0),\r
constrain : 1\r
});\r
\r