2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 CKEDITOR.plugins.add( 'pastefromword',
\r
9 init : function( editor )
\r
12 // Flag indicate this command is actually been asked instead of a generic
\r
14 var forceFromWord = 0;
\r
15 var resetFromWord = function( evt )
\r
17 evt && evt.removeListener();
\r
18 forceFromWord && setTimeout( function() { forceFromWord = 0; }, 0 );
\r
21 // Features bring by this command beside the normal process:
\r
22 // 1. No more bothering of user about the clean-up.
\r
23 // 2. Perform the clean-up even if content is not from MS-Word.
\r
24 // (e.g. from a MS-Word similar application.)
\r
25 editor.addCommand( 'pastefromword',
\r
31 if ( editor.execCommand( 'paste' ) === false )
\r
33 editor.on( 'dialogShow', function ( evt )
\r
35 evt.removeListener();
\r
36 evt.data.on( 'cancel', resetFromWord );
\r
39 editor.on( 'dialogHide', function( evt )
\r
41 evt.data.removeListener( 'cancel', resetFromWord );
\r
45 editor.on( 'afterPaste', resetFromWord );
\r
49 // Register the toolbar button.
\r
50 editor.ui.addButton( 'PasteFromWord',
\r
52 label : editor.lang.pastefromword.toolbar,
\r
53 command : 'pastefromword'
\r
56 editor.on( 'pasteState', function( evt )
\r
58 editor.getCommand( 'pastefromword' ).setState( evt.data );
\r
61 editor.on( 'paste', function( evt )
\r
63 var data = evt.data,
\r
66 // MS-WORD format sniffing.
\r
67 if ( ( mswordHtml = data[ 'html' ] )
\r
68 && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
\r
70 var isLazyLoad = this.loadFilterRules( function()
\r
72 // Event continuation with the original data.
\r
74 editor.fire( 'paste', data );
\r
75 else if ( !editor.config.pasteFromWordPromptCleanup
\r
76 || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
\r
78 data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
\r
82 // The cleanup rules are to be loaded, we should just cancel
\r
84 isLazyLoad && evt.cancel();
\r
89 loadFilterRules : function( callback )
\r
92 var isLoaded = CKEDITOR.cleanWord;
\r
98 var filterFilePath = CKEDITOR.getUrl(
\r
99 CKEDITOR.config.pasteFromWordCleanupFile
\r
100 || ( this.path + 'filter/default.js' ) );
\r
102 // Load with busy indicator.
\r
103 CKEDITOR.scriptLoader.load( filterFilePath, callback, null, true );
\r
109 requires : [ 'clipboard' ]
\r
114 * Whether to prompt the user about the clean up of content being pasted from
\r
116 * @name CKEDITOR.config.pasteFromWordPromptCleanup
\r
119 * @default undefined
\r
121 * config.pasteFromWordPromptCleanup = true;
\r
125 * The file that provides the MS Word cleanup function for pasting operations.
\r
126 * Note: This is a global configuration shared by all editor instances present
\r
128 * @name CKEDITOR.config.pasteFromWordCleanupFile
\r
131 * @default 'default'
\r
133 * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).
\r
134 * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';
\r