X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fplugins%2Fpastefromword%2Fplugin.js;h=2e0b3d402d6c99d3e10f16946d93ec6741a89501;hp=d7cf4b594045df065fd29709da46f06c823653f0;hb=941b0a9ba4e673e292510d80a5a86806994b8ea6;hpb=7cd80714081a8ffdf4a1a8d2c72f120ed5ef3d6d diff --git a/_source/plugins/pastefromword/plugin.js b/_source/plugins/pastefromword/plugin.js index d7cf4b5..2e0b3d4 100644 --- a/_source/plugins/pastefromword/plugin.js +++ b/_source/plugins/pastefromword/plugin.js @@ -1,54 +1,116 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ - -CKEDITOR.plugins.add( 'pastefromword', +(function() { - init : function( editor ) + CKEDITOR.plugins.add( 'pastefromword', { - // Register the command. - editor.addCommand( 'pastefromword', new CKEDITOR.dialogCommand( 'pastefromword' ) ); + init : function( editor ) + { + + // Flag indicate this command is actually been asked instead of a generic + // pasting. + var forceFromWord = 0; + var resetFromWord = function() + { + setTimeout( function() { forceFromWord = 0; }, 0 ); + }; - // Register the toolbar button. - editor.ui.addButton( 'PasteFromWord', + // Features bring by this command beside the normal process: + // 1. No more bothering of user about the clean-up. + // 2. Perform the clean-up even if content is not from MS-Word. + // (e.g. from a MS-Word similar application.) + editor.addCommand( 'pastefromword', { - label : editor.lang.pastefromword.toolbar, - command : 'pastefromword' - } ); + canUndo : false, + exec : function() + { + forceFromWord = 1; + if( editor.execCommand( 'paste' ) === false ) + { + editor.on( 'dialogHide', function ( evt ) + { + evt.removeListener(); + resetFromWord(); + }); + } + } + }); - // Register the dialog. - CKEDITOR.dialog.add( 'pastefromword', this.path + 'dialogs/pastefromword.js' ); - } -} ); + // Register the toolbar button. + editor.ui.addButton( 'PasteFromWord', + { + label : editor.lang.pastefromword.toolbar, + command : 'pastefromword' + }); -/** - * Whether the "Ignore font face definitions" checkbox is enabled by default in - * the Paste from Word dialog. - * @type Boolean - * @default true - * @example - * config.pasteFromWordIgnoreFontFace = false; - */ -CKEDITOR.config.pasteFromWordIgnoreFontFace = true; + editor.on( 'paste', function( evt ) + { + var data = evt.data, + mswordHtml; + + // MS-WORD format sniffing. + if ( ( mswordHtml = data[ 'html' ] ) + && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) ) + { + var isLazyLoad = this.loadFilterRules( function() + { + // Event continuation with the original data. + if ( isLazyLoad ) + editor.fire( 'paste', data ); + else if( !editor.config.pasteFromWordPromptCleanup + || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) ) + { + data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor ); + } + }); + + // The cleanup rules are to be loaded, we should just cancel + // this event. + isLazyLoad && evt.cancel(); + } + }, this ); + }, + + loadFilterRules : function( callback ) + { + + var isLoaded = CKEDITOR.cleanWord; + + if ( isLoaded ) + callback(); + else + { + var filterFilePath = CKEDITOR.getUrl( + CKEDITOR.config.pasteFromWordCleanupFile + || ( this.path + 'filter/default.js' ) ); + + // Load with busy indicator. + CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true ); + } + + return !isLoaded; + } + }); +})(); /** - * Whether the "Remove styles definitions" checkbox is enabled by default in - * the Paste from Word dialog. + * Whether prompt the user about the clean-up of content from MS-Word. + * @name CKEDITOR.config.pasteFromWordPromptCleanup * @type Boolean - * @default false + * @default undefined * @example - * config.pasteFromWordRemoveStyle = true; + * config.pasteFromWordPromptCleanup = true; */ -CKEDITOR.config.pasteFromWordRemoveStyle = false; /** - * Whether to keep structure markup (<h1>, <h2>, etc.) or replace - * it with elements that create more similar pasting results when pasting - * content from Microsoft Word into the Paste from Word dialog. - * @type Boolean - * @default false + * The file that provides the MS-Word Filtering rules. + * Note: It's a global configuration which are shared by all editor instances. + * @name CKEDITOR.config.pasteFromWordCleanupFile + * @type String + * @default 'default' * @example - * config.pasteFromWordKeepsStructure = true; + * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file). + * CKEDITOR.config.pasteFromWordCleanupFile = 'custom'; */ -CKEDITOR.config.pasteFromWordKeepsStructure = false;