JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.4
[ckeditor.git] / _source / plugins / pastefromword / plugin.js
index d50b3f0..c9bd2ec 100644 (file)
@@ -1,9 +1,11 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 (function()\r
 {\r
+       function forceHtmlMode( evt ) { evt.data.mode = 'html'; }\r
+\r
        CKEDITOR.plugins.add( 'pastefromword',\r
        {\r
                init : function( editor )\r
@@ -12,9 +14,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        // Flag indicate this command is actually been asked instead of a generic\r
                        // pasting.\r
                        var forceFromWord = 0;\r
-                       var resetFromWord = function()\r
+                       var resetFromWord = function( evt )\r
                                {\r
-                                       setTimeout( function() { forceFromWord = 0; }, 0 );\r
+                                       evt && evt.removeListener();\r
+                                       editor.removeListener( 'beforePaste', forceHtmlMode );\r
+                                       forceFromWord && setTimeout( function() { forceFromWord = 0; }, 0 );\r
                                };\r
 \r
                        // Features bring by this command beside the normal process:\r
@@ -26,17 +30,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                canUndo : false,\r
                                exec : function()\r
                                {\r
+                                       // Ensure the received data format is HTML and apply content filtering. (#6718)\r
                                        forceFromWord = 1;\r
-                                       if ( editor.execCommand( 'paste' ) === false )\r
+                                       editor.on( 'beforePaste', forceHtmlMode );\r
+\r
+                                       if ( editor.execCommand( 'paste', 'html' ) === false )\r
                                        {\r
-                                               editor.on( 'dialogHide', function ( evt )\r
-                                                       {\r
-                                                               evt.removeListener();\r
-                                                               resetFromWord();\r
-                                                       });\r
+                                               editor.on( 'dialogShow', function ( evt )\r
+                                               {\r
+                                                       evt.removeListener();\r
+                                                       evt.data.on( 'cancel', resetFromWord );\r
+                                               });\r
+\r
+                                               editor.on( 'dialogHide', function( evt )\r
+                                               {\r
+                                                       evt.data.removeListener( 'cancel', resetFromWord );\r
+                                               } );\r
                                        }\r
-                                       else\r
-                                               resetFromWord();\r
+\r
+                                       editor.on( 'afterPaste', resetFromWord );\r
                                }\r
                        });\r
 \r
@@ -47,6 +59,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        command : 'pastefromword'\r
                                });\r
 \r
+                       editor.on( 'pasteState', function( evt )\r
+                               {\r
+                                       editor.getCommand( 'pastefromword' ).setState( evt.data );\r
+                               });\r
+\r
                        editor.on( 'paste', function( evt )\r
                        {\r
                                var data = evt.data,\r
@@ -89,11 +106,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                || ( this.path + 'filter/default.js' ) );\r
 \r
                                // Load with busy indicator.\r
-                               CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true );\r
+                               CKEDITOR.scriptLoader.load( filterFilePath, callback, null, true );\r
                        }\r
 \r
                        return !isLoaded;\r
-               }\r
+               },\r
+\r
+               requires : [ 'clipboard' ]\r
        });\r
 })();\r
 \r