/*\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
-CKEDITOR.plugins.add( 'pastefromword',\r
+(function()\r
{\r
- init : function( editor )\r
+ CKEDITOR.plugins.add( 'pastefromword',\r
{\r
- // Register the command.\r
- editor.addCommand( 'pastefromword', new CKEDITOR.dialogCommand( 'pastefromword' ) );\r
+ init : function( editor )\r
+ {\r
+\r
+ // Flag indicate this command is actually been asked instead of a generic\r
+ // pasting.\r
+ var forceFromWord = 0;\r
+ var resetFromWord = function()\r
+ {\r
+ setTimeout( function() { forceFromWord = 0; }, 0 );\r
+ };\r
\r
- // Register the toolbar button.\r
- editor.ui.addButton( 'PasteFromWord',\r
+ // Features bring by this command beside the normal process:\r
+ // 1. No more bothering of user about the clean-up.\r
+ // 2. Perform the clean-up even if content is not from MS-Word.\r
+ // (e.g. from a MS-Word similar application.)\r
+ editor.addCommand( 'pastefromword',\r
{\r
- label : editor.lang.pastefromword.toolbar,\r
- command : 'pastefromword'\r
- } );\r
+ canUndo : false,\r
+ exec : function()\r
+ {\r
+ forceFromWord = 1;\r
+ if ( editor.execCommand( 'paste' ) === false )\r
+ {\r
+ editor.on( 'dialogHide', function ( evt )\r
+ {\r
+ evt.removeListener();\r
+ resetFromWord();\r
+ });\r
+ }\r
+ else\r
+ resetFromWord();\r
+ }\r
+ });\r
\r
- // Register the dialog.\r
- CKEDITOR.dialog.add( 'pastefromword', this.path + 'dialogs/pastefromword.js' );\r
- }\r
-} );\r
+ // Register the toolbar button.\r
+ editor.ui.addButton( 'PasteFromWord',\r
+ {\r
+ label : editor.lang.pastefromword.toolbar,\r
+ command : 'pastefromword'\r
+ });\r
\r
-/**\r
- * Whether the "Ignore font face definitions" checkbox is enabled by default in\r
- * the Paste from Word dialog.\r
- * @type Boolean\r
- * @default true\r
- * @example\r
- * config.pasteFromWordIgnoreFontFace = false;\r
- */\r
-CKEDITOR.config.pasteFromWordIgnoreFontFace = true;\r
+ editor.on( 'paste', function( evt )\r
+ {\r
+ var data = evt.data,\r
+ mswordHtml;\r
+\r
+ // MS-WORD format sniffing.\r
+ if ( ( mswordHtml = data[ 'html' ] )\r
+ && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )\r
+ {\r
+ var isLazyLoad = this.loadFilterRules( function()\r
+ {\r
+ // Event continuation with the original data.\r
+ if ( isLazyLoad )\r
+ editor.fire( 'paste', data );\r
+ else if ( !editor.config.pasteFromWordPromptCleanup\r
+ || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )\r
+ {\r
+ data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );\r
+ }\r
+ });\r
+\r
+ // The cleanup rules are to be loaded, we should just cancel\r
+ // this event.\r
+ isLazyLoad && evt.cancel();\r
+ }\r
+ }, this );\r
+ },\r
+\r
+ loadFilterRules : function( callback )\r
+ {\r
+\r
+ var isLoaded = CKEDITOR.cleanWord;\r
+\r
+ if ( isLoaded )\r
+ callback();\r
+ else\r
+ {\r
+ var filterFilePath = CKEDITOR.getUrl(\r
+ CKEDITOR.config.pasteFromWordCleanupFile\r
+ || ( this.path + 'filter/default.js' ) );\r
+\r
+ // Load with busy indicator.\r
+ CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true );\r
+ }\r
+\r
+ return !isLoaded;\r
+ }\r
+ });\r
+})();\r
\r
/**\r
- * Whether the "Remove styles definitions" checkbox is enabled by default in\r
- * the Paste from Word dialog.\r
+ * Whether to prompt the user about the clean up of content being pasted from\r
+ * MS Word.\r
+ * @name CKEDITOR.config.pasteFromWordPromptCleanup\r
+ * @since 3.1\r
* @type Boolean\r
- * @default false\r
+ * @default undefined\r
* @example\r
- * config.pasteFromWordRemoveStyle = true;\r
+ * config.pasteFromWordPromptCleanup = true;\r
*/\r
-CKEDITOR.config.pasteFromWordRemoveStyle = false;\r
\r
/**\r
- * Whether to keep structure markup (<h1>, <h2>, etc.) or replace\r
- * it with elements that create more similar pasting results when pasting\r
- * content from Microsoft Word into the Paste from Word dialog.\r
- * @type Boolean\r
- * @default false\r
+ * The file that provides the MS Word cleanup function for pasting operations.\r
+ * Note: This is a global configuration shared by all editor instances present\r
+ * in the page.\r
+ * @name CKEDITOR.config.pasteFromWordCleanupFile\r
+ * @since 3.1\r
+ * @type String\r
+ * @default 'default'\r
* @example\r
- * config.pasteFromWordKeepsStructure = true;\r
+ * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).\r
+ * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';\r
*/\r
-CKEDITOR.config.pasteFromWordKeepsStructure = false;\r