2 Copyright (c) 2003-2010, 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
41 // Register the toolbar button.
\r
42 editor.ui.addButton( 'PasteFromWord',
\r
44 label : editor.lang.pastefromword.toolbar,
\r
45 command : 'pastefromword'
\r
48 editor.on( 'paste', function( evt )
\r
50 var data = evt.data,
\r
53 // MS-WORD format sniffing.
\r
54 if ( ( mswordHtml = data[ 'html' ] )
\r
55 && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
\r
57 var isLazyLoad = this.loadFilterRules( function()
\r
59 // Event continuation with the original data.
\r
61 editor.fire( 'paste', data );
\r
62 else if( !editor.config.pasteFromWordPromptCleanup
\r
63 || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
\r
65 data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
\r
69 // The cleanup rules are to be loaded, we should just cancel
\r
71 isLazyLoad && evt.cancel();
\r
76 loadFilterRules : function( callback )
\r
79 var isLoaded = CKEDITOR.cleanWord;
\r
85 var filterFilePath = CKEDITOR.getUrl(
\r
86 CKEDITOR.config.pasteFromWordCleanupFile
\r
87 || ( this.path + 'filter/default.js' ) );
\r
89 // Load with busy indicator.
\r
90 CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true );
\r
99 * Whether prompt the user about the clean-up of content from MS-Word.
\r
100 * @name CKEDITOR.config.pasteFromWordPromptCleanup
\r
102 * @default undefined
\r
104 * config.pasteFromWordPromptCleanup = true;
\r
108 * The file that provides the MS-Word Filtering rules.
\r
109 * Note: It's a global configuration which are shared by all editor instances.
\r
110 * @name CKEDITOR.config.pasteFromWordCleanupFile
\r
112 * @default 'default'
\r
114 * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).
\r
115 * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';
\r