JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1.1
[ckeditor.git] / _source / plugins / contextmenu / plugin.js
index 6cbc3e7..1c83546 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -54,26 +54,18 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
                                menu = this._.menu = new CKEDITOR.menu( editor );\r
                                menu.onClick = CKEDITOR.tools.bind( function( item )\r
                                {\r
-                                       var noUnlock = true;\r
                                        menu.hide();\r
 \r
-                                       if ( CKEDITOR.env.ie )\r
-                                               menu.onEscape();\r
-\r
                                        if ( item.onClick )\r
                                                item.onClick();\r
                                        else if ( item.command )\r
                                                editor.execCommand( item.command );\r
 \r
-                                       noUnlock = false;\r
                                }, this );\r
 \r
                                menu.onEscape = function()\r
                                {\r
                                        editor.focus();\r
-\r
-                                       if ( CKEDITOR.env.ie )\r
-                                               editor.getSelection().unlock( true );\r
                                };\r
                        }\r
 \r
@@ -83,17 +75,15 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
                        var selection = this.editor.getSelection(),\r
                                element = selection && selection.getStartElement();\r
 \r
-                       // Lock the selection in IE, so it can be restored when closing the\r
-                       // menu.\r
-                       if ( CKEDITOR.env.ie )\r
-                               selection.lock();\r
-\r
                        menu.onHide = CKEDITOR.tools.bind( function()\r
                                {\r
                                        menu.onHide = null;\r
 \r
                                        if ( CKEDITOR.env.ie )\r
-                                               editor.getSelection().unlock();\r
+                                       {\r
+                                               var selection = editor.getSelection();\r
+                                               selection && selection.unlock();\r
+                                       }\r
 \r
                                        this.onHide && this.onHide();\r
                                },\r
@@ -140,7 +130,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
                                element.on( 'mousedown', function( evt )\r
                                {\r
                                        evt = evt.data;\r
-                                       if( evt.$.button != 2 )\r
+                                       if ( evt.$.button != 2 )\r
                                        {\r
                                                if ( evt.getKeystroke() == CKEDITOR.CTRL + 1 )\r
                                                        element.fire( 'contextmenu', evt );\r
@@ -153,7 +143,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
 \r
                                        var target = evt.getTarget();\r
 \r
-                                       if( !contextMenuOverrideButton )\r
+                                       if ( !contextMenuOverrideButton )\r
                                        {\r
                                                var ownerDoc =  target.getDocument();\r
                                                contextMenuOverrideButton = ownerDoc.createElement( 'input' ) ;\r
@@ -189,6 +179,14 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
                                             ( CKEDITOR.env.webkit ? holdCtrlKey : domEvent.$.ctrlKey || domEvent.$.metaKey ) )\r
                                                return;\r
 \r
+                                       // Selection will be unavailable after context menu shows up\r
+                                       // in IE, lock it now.\r
+                                       if ( CKEDITOR.env.ie )\r
+                                       {\r
+                                               var selection = this.editor.getSelection();\r
+                                               selection && selection.lock();\r
+                                       }\r
+\r
                                        // Cancel the browser context menu.\r
                                        domEvent.preventDefault();\r
 \r
@@ -204,7 +202,7 @@ CKEDITOR.plugins.contextMenu = CKEDITOR.tools.createClass(
                                },\r
                                this );\r
 \r
-                       if( CKEDITOR.env.webkit )\r
+                       if ( CKEDITOR.env.webkit )\r
                        {\r
                                var holdCtrlKey,\r
                                        onKeyDown = function( event )\r