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()
\r
17 setTimeout( function() { forceFromWord = 0; }, 0 );
\r
20 // Features bring by this command beside the normal process:
\r
21 // 1. No more bothering of user about the clean-up.
\r
22 // 2. Perform the clean-up even if content is not from MS-Word.
\r
23 // (e.g. from a MS-Word similar application.)
\r
24 editor.addCommand( 'pastefromword',
\r
30 if ( editor.execCommand( 'paste' ) === false )
\r
32 editor.on( 'dialogHide', function ( evt )
\r
34 evt.removeListener();
\r
43 // Register the toolbar button.
\r
44 editor.ui.addButton( 'PasteFromWord',
\r
46 label : editor.lang.pastefromword.toolbar,
\r
47 command : 'pastefromword'
\r
50 editor.on( 'pasteState', function( evt )
\r
52 editor.getCommand( 'pastefromword' ).setState( evt.data );
\r
55 editor.on( 'paste', function( evt )
\r
57 var data = evt.data,
\r
60 // MS-WORD format sniffing.
\r
61 if ( ( mswordHtml = data[ 'html' ] )
\r
62 && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
\r
64 var isLazyLoad = this.loadFilterRules( function()
\r
66 // Event continuation with the original data.
\r
68 editor.fire( 'paste', data );
\r
69 else if ( !editor.config.pasteFromWordPromptCleanup
\r
70 || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
\r
72 data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
\r
76 // The cleanup rules are to be loaded, we should just cancel
\r
78 isLazyLoad && evt.cancel();
\r
83 loadFilterRules : function( callback )
\r
86 var isLoaded = CKEDITOR.cleanWord;
\r
92 var filterFilePath = CKEDITOR.getUrl(
\r
93 CKEDITOR.config.pasteFromWordCleanupFile
\r
94 || ( this.path + 'filter/default.js' ) );
\r
96 // Load with busy indicator.
\r
97 CKEDITOR.scriptLoader.load( filterFilePath, callback, null, true );
\r
103 requires : [ 'clipboard' ]
\r
108 * Whether to prompt the user about the clean up of content being pasted from
\r
110 * @name CKEDITOR.config.pasteFromWordPromptCleanup
\r
113 * @default undefined
\r
115 * config.pasteFromWordPromptCleanup = true;
\r
119 * The file that provides the MS Word cleanup function for pasting operations.
\r
120 * Note: This is a global configuration shared by all editor instances present
\r
122 * @name CKEDITOR.config.pasteFromWordCleanupFile
\r
125 * @default 'default'
\r
127 * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).
\r
128 * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';
\r