Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / contextmenu / editor_plugin_src.js
index a686c77eb57b134e3bbc4daf488c911dc7e70819..956fbea99880c9825a5cf24e025170314615474b 100644 (file)
@@ -1,26 +1,81 @@
-/*\r
- * Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.\r
+/**\r
+ * editor_plugin_src.js\r
+ *\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, showMenu, contextmenuNeverUseNative, realCtrlKey;\r
 \r
                        t.editor = ed;\r
+\r
+                       contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native;\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
-                                       t._getMenu(ed).showMenu(e.clientX, e.clientY);\r
-                                       Event.add(ed.getDoc(), 'click', hide);\r
-                                       Event.cancel(e);\r
-                               }\r
+                       showMenu = ed.onContextMenu.add(function(ed, e) {\r
+                               // Block TinyMCE menu on ctrlKey and work around Safari issue\r
+                               if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative)\r
+                                       return;\r
+\r
+                               Event.cancel(e);\r
+\r
+                               // Select the image if it's clicked. WebKit would other wise expand the selection\r
+                               if (e.target.nodeName == 'IMG')\r
+                                       ed.selection.select(e.target);\r
+\r
+                               t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageY);\r
+                               Event.add(ed.getDoc(), 'click', function(e) {\r
+                                       hide(ed, e);\r
+                               });\r
+\r
+                               ed.nodeChanged();\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
+                               realCtrlKey = 0;\r
+\r
+                               // Since the contextmenu event moves\r
+                               // the selection we need to store it away\r
+                               if (e && e.button == 2) {\r
+                                       realCtrlKey = e.ctrlKey;\r
+                                       return;\r
+                               }\r
+\r
                                if (t._menu) {\r
                                        t._menu.removeAll();\r
                                        t._menu.destroy();\r
 \r
                        ed.onMouseDown.add(hide);\r
                        ed.onKeyDown.add(hide);\r
+                       ed.onKeyDown.add(function(ed, e) {\r
+                               if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) {\r
+                                       Event.cancel(e);\r
+                                       showMenu(ed, e);\r
+                               }\r
+                       });\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
                },\r
 \r
                _getMenu : function(ed) {\r
-                       var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;\r
+                       var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p;\r
 \r
                        if (m) {\r
                                m.removeAll();\r
                                m.destroy();\r
                        }\r
 \r
-                       p1 = DOM.getPos(ed.getContentAreaContainer());\r
-                       p2 = DOM.getPos(ed.getContainer());\r
+                       p = DOM.getPos(ed.getContentAreaContainer());\r
 \r
                        m = ed.controlManager.createDropMenu('contextmenu', {\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
+                               offset_x : p.x + ed.getParam('contextmenu_offset_x', 0),\r
+                               offset_y : p.y + ed.getParam('contextmenu_offset_y', 0),\r
+                               constrain : 1,\r
+                               keyboard_focus: true\r
                        });\r
 \r
                        t._menu = m;\r