2 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 function forceHtmlMode( evt ) { evt.data.mode = 'html'; }
\r
9 CKEDITOR.plugins.add( 'pastefromword',
\r
11 init : function( editor )
\r
14 // Flag indicate this command is actually been asked instead of a generic
\r
16 var forceFromWord = 0;
\r
17 var resetFromWord = function( evt )
\r
19 evt && evt.removeListener();
\r
20 editor.removeListener( 'beforePaste', forceHtmlMode );
\r
21 forceFromWord && setTimeout( function() { forceFromWord = 0; }, 0 );
\r
24 // Features bring by this command beside the normal process:
\r
25 // 1. No more bothering of user about the clean-up.
\r
26 // 2. Perform the clean-up even if content is not from MS-Word.
\r
27 // (e.g. from a MS-Word similar application.)
\r
28 editor.addCommand( 'pastefromword',
\r
33 // Ensure the received data format is HTML and apply content filtering. (#6718)
\r
35 editor.on( 'beforePaste', forceHtmlMode );
\r
37 if ( editor.execCommand( 'paste', 'html' ) === false )
\r
39 editor.on( 'dialogShow', function ( evt )
\r
41 evt.removeListener();
\r
42 evt.data.on( 'cancel', resetFromWord );
\r
45 editor.on( 'dialogHide', function( evt )
\r
47 evt.data.removeListener( 'cancel', resetFromWord );
\r
51 editor.on( 'afterPaste', resetFromWord );
\r
55 // Register the toolbar button.
\r
56 editor.ui.addButton( 'PasteFromWord',
\r
58 label : editor.lang.pastefromword.toolbar,
\r
59 command : 'pastefromword'
\r
62 editor.on( 'pasteState', function( evt )
\r
64 editor.getCommand( 'pastefromword' ).setState( evt.data );
\r
67 editor.on( 'paste', function( evt )
\r
69 var data = evt.data,
\r
72 // MS-WORD format sniffing.
\r
73 if ( ( mswordHtml = data[ 'html' ] )
\r
74 && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
\r
76 var isLazyLoad = this.loadFilterRules( function()
\r
78 // Event continuation with the original data.
\r
80 editor.fire( 'paste', data );
\r
81 else if ( !editor.config.pasteFromWordPromptCleanup
\r
82 || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
\r
84 data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
\r
88 // The cleanup rules are to be loaded, we should just cancel
\r
90 isLazyLoad && evt.cancel();
\r
95 loadFilterRules : function( callback )
\r
98 var isLoaded = CKEDITOR.cleanWord;
\r
104 var filterFilePath = CKEDITOR.getUrl(
\r
105 CKEDITOR.config.pasteFromWordCleanupFile
\r
106 || ( this.path + 'filter/default.js' ) );
\r
108 // Load with busy indicator.
\r
109 CKEDITOR.scriptLoader.load( filterFilePath, callback, null, true );
\r
115 requires : [ 'clipboard' ]
\r
120 * Whether to prompt the user about the clean up of content being pasted from
\r
122 * @name CKEDITOR.config.pasteFromWordPromptCleanup
\r
125 * @default undefined
\r
127 * config.pasteFromWordPromptCleanup = true;
\r
131 * The file that provides the MS Word cleanup function for pasting operations.
\r
132 * Note: This is a global configuration shared by all editor instances present
\r
134 * @name CKEDITOR.config.pasteFromWordCleanupFile
\r
137 * @default 'default'
\r
139 * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).
\r
140 * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';
\r