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
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( 'paste', function( evt )
\r
52 var data = evt.data,
\r
55 // MS-WORD format sniffing.
\r
56 if ( ( mswordHtml = data[ 'html' ] )
\r
57 && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
\r
59 var isLazyLoad = this.loadFilterRules( function()
\r
61 // Event continuation with the original data.
\r
63 editor.fire( 'paste', data );
\r
64 else if ( !editor.config.pasteFromWordPromptCleanup
\r
65 || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
\r
67 data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
\r
71 // The cleanup rules are to be loaded, we should just cancel
\r
73 isLazyLoad && evt.cancel();
\r
78 loadFilterRules : function( callback )
\r
81 var isLoaded = CKEDITOR.cleanWord;
\r
87 var filterFilePath = CKEDITOR.getUrl(
\r
88 CKEDITOR.config.pasteFromWordCleanupFile
\r
89 || ( this.path + 'filter/default.js' ) );
\r
91 // Load with busy indicator.
\r
92 CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true );
\r
101 * Whether to prompt the user about the clean up of content being pasted from
\r
103 * @name CKEDITOR.config.pasteFromWordPromptCleanup
\r
106 * @default undefined
\r
108 * config.pasteFromWordPromptCleanup = true;
\r
112 * The file that provides the MS Word cleanup function for pasting operations.
\r
113 * Note: This is a global configuration shared by all editor instances present
\r
115 * @name CKEDITOR.config.pasteFromWordCleanupFile
\r
118 * @default 'default'
\r
120 * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).
\r
121 * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';
\r