]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/js/tiny_mce/plugins/contextmenu/editor_plugin_src.js
Imported Upstream version 0.5
[roundcube.git] / program / js / tiny_mce / plugins / contextmenu / editor_plugin_src.js
index a2c1866ba56d00fea8796f57c95dfc03a7340407..13813a64e4630df01ed620a1d04554c00c4ad939 100644 (file)
@@ -1,29 +1,74 @@
 /**\r
- * $Id: editor_plugin_src.js 848 2008-05-15 11:54:40Z 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(ed.getDoc(), '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
                        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