JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.3
[ckeditor.git] / _source / plugins / clipboard / plugin.js
index 3c53ab1..a285954 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -16,10 +16,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var doc = editor.document,\r
                        body = doc.getBody();\r
 \r
-               var enabled = 0;\r
+               var enabled = false;\r
                var onExec = function()\r
                {\r
-                       enabled = 1;\r
+                       enabled = true;\r
                };\r
 \r
                // The following seems to be the only reliable way to detect that\r
@@ -135,11 +135,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                var body = this.document.getBody();\r
 \r
-                               // Simulate 'beforepaste' event for all none-IEs.\r
-                               if ( !CKEDITOR.env.ie && body.fire( 'beforepaste' ) )\r
-                                       event.cancel();\r
                                // Simulate 'paste' event for Opera/Firefox2.\r
-                               else if ( CKEDITOR.env.opera\r
+                               if ( CKEDITOR.env.opera\r
                                                 || CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )\r
                                        body.fire( 'paste' );\r
                                return;\r
@@ -226,8 +223,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                // Wait a while and grab the pasted contents\r
                window.setTimeout( function()\r
                {\r
-                       mode == 'text' && CKEDITOR.env.gecko && editor.focusGrabber.focus();\r
-                       pastebin.remove();\r
+                       // Restore properly the document focus. (#5684, #8849)\r
+                       editor.document.getBody().focus();\r
+\r
                        editor.removeListener( 'selectionChange', cancel );\r
 \r
                        // Grab the HTML contents.\r
@@ -240,7 +238,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                 && ( bogusSpan.is && bogusSpan.hasClass( 'Apple-style-span' ) ) ?\r
                                                        bogusSpan : pastebin );\r
 \r
+                       // IE7: selection must go before removing paste. (#8691)\r
                        sel.selectBookmarks( bms );\r
+                       pastebin.remove();\r
                        callback( pastebin[ 'get' + ( mode == 'text' ? 'Value' : 'Html' ) ]() );\r
                }, 0 );\r
        }\r
@@ -375,11 +375,18 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                editor.on( 'contentDom', function()\r
                                {\r
                                        var body = editor.document.getBody();\r
-                                       body.on( CKEDITOR.env.webkit ? 'paste' : 'beforepaste', function( evt )\r
+\r
+                                       // Intercept the paste before it actually takes place.\r
+                                       body.on( !CKEDITOR.env.ie ? 'paste' : 'beforepaste', function( evt )\r
                                                {\r
                                                        if ( depressBeforeEvent )\r
                                                                return;\r
 \r
+                                                       // Dismiss the (wrong) 'beforepaste' event fired on toolbar menu open.\r
+                                                       var domEvent = evt.data && evt.data.$;\r
+                                                       if ( CKEDITOR.env.ie && domEvent && !domEvent.ctrlKey )\r
+                                                               return;\r
+\r
                                                        // Fire 'beforePaste' event so clipboard flavor get customized\r
                                                        // by other plugins.\r
                                                        var eventData =  { mode : 'html' };\r
@@ -398,12 +405,31 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        } );\r
                                                });\r
 \r
-                                       // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953)\r
-                                       body.on( 'contextmenu', function()\r
+                                       if ( CKEDITOR.env.ie )\r
                                        {\r
-                                               depressBeforeEvent = 1;\r
-                                               setTimeout( function() { depressBeforeEvent = 0; }, 10 );\r
-                                       });\r
+                                               // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953)\r
+                                               body.on( 'contextmenu', function()\r
+                                               {\r
+                                                       depressBeforeEvent = 1;\r
+                                                       // Important: The following timeout will be called only after menu closed.\r
+                                                       setTimeout( function() { depressBeforeEvent = 0; }, 0 );\r
+                                               } );\r
+\r
+                                               // Handle IE's late coming "paste" event when pasting from\r
+                                               // browser toolbar/context menu.\r
+                                               body.on( 'paste', function( evt )\r
+                                               {\r
+                                                       if ( !editor.document.getById( 'cke_pastebin' ) )\r
+                                                       {\r
+                                                               // Prevent native paste.\r
+                                                               evt.data.preventDefault();\r
+\r
+                                                               depressBeforeEvent = 0;\r
+                                                               // Resort to the paste command.\r
+                                                               pasteCmd.exec( editor );\r
+                                                       }\r
+                                               } );\r
+                                       }\r
 \r
                                        body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } );\r
 \r