]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/js/tiny_mce/plugins/contextmenu/editor_plugin_src.js
Imported Upstream version 0.5.2+dfsg
[roundcube.git] / program / js / tiny_mce / plugins / contextmenu / editor_plugin_src.js
index 13813a64e4630df01ed620a1d04554c00c4ad939..4328f4b117614956c979f5694279973fcfc24eaf 100644 (file)
                 * @param {string} url Absolute URL to where the plugin is located.\r
                 */\r
                init : function(ed) {\r
-                       var t = this, lastRng;\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
                         */\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
+                       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
-                                       t._getMenu(ed).showMenu(e.clientX, e.clientY);\r
-                                       Event.add(ed.getDoc(), 'click', function(e) {\r
-                                               hide(ed, e);\r
-                                       });\r
-                                       Event.cancel(e);\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.pageX);\r
+                               Event.add(ed.getDoc(), 'click', function(e) {\r
+                                       hide(ed, e);\r
+                               });\r
+\r
+                               ed.nodeChanged();\r
                        });\r
 \r
                        ed.onRemove.add(function() {\r
                        });\r
 \r
                        function hide(ed, e) {\r
-                               lastRng = null;\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
-                                       lastRng = ed.selection.getRng();\r
+                                       realCtrlKey = e.ctrlKey;\r
                                        return;\r
                                }\r
 \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
                        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
+                               constrain : 1,\r
+                               keyboard_focus: true\r
                        });\r
 \r
                        t._menu = m;\r
 \r
        // Register plugin\r
        tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);\r
-})();
\ No newline at end of file
+})();\r