X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fpastefromword%2Fplugin.js;h=cc1add45cd3ec874d349ae00ef41df7a0619d6ca;hb=a272c66d841421f8bf933c16535bdcde1c4649fc;hp=2e0b3d402d6c99d3e10f16946d93ec6741a89501;hpb=941b0a9ba4e673e292510d80a5a86806994b8ea6;p=ckeditor.git diff --git a/_source/plugins/pastefromword/plugin.js b/_source/plugins/pastefromword/plugin.js index 2e0b3d4..cc1add4 100644 --- a/_source/plugins/pastefromword/plugin.js +++ b/_source/plugins/pastefromword/plugin.js @@ -1,9 +1,11 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ (function() { + function forceHtmlMode( evt ) { evt.data.mode = 'html'; } + CKEDITOR.plugins.add( 'pastefromword', { init : function( editor ) @@ -12,9 +14,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Flag indicate this command is actually been asked instead of a generic // pasting. var forceFromWord = 0; - var resetFromWord = function() + var resetFromWord = function( evt ) { - setTimeout( function() { forceFromWord = 0; }, 0 ); + evt && evt.removeListener(); + editor.removeListener( 'beforePaste', forceHtmlMode ); + forceFromWord && setTimeout( function() { forceFromWord = 0; }, 0 ); }; // Features bring by this command beside the normal process: @@ -26,15 +30,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license canUndo : false, exec : function() { + // Ensure the received data format is HTML and apply content filtering. (#6718) forceFromWord = 1; - if( editor.execCommand( 'paste' ) === false ) + editor.on( 'beforePaste', forceHtmlMode ); + + if ( editor.execCommand( 'paste', 'html' ) === false ) { - editor.on( 'dialogHide', function ( evt ) - { - evt.removeListener(); - resetFromWord(); - }); + editor.on( 'dialogShow', function ( evt ) + { + evt.removeListener(); + evt.data.on( 'cancel', resetFromWord ); + }); + + editor.on( 'dialogHide', function( evt ) + { + evt.data.removeListener( 'cancel', resetFromWord ); + } ); } + + editor.on( 'afterPaste', resetFromWord ); } }); @@ -45,6 +59,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license command : 'pastefromword' }); + editor.on( 'pasteState', function( evt ) + { + editor.getCommand( 'pastefromword' ).setState( evt.data ); + }); + editor.on( 'paste', function( evt ) { var data = evt.data, @@ -59,7 +78,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Event continuation with the original data. if ( isLazyLoad ) editor.fire( 'paste', data ); - else if( !editor.config.pasteFromWordPromptCleanup + else if ( !editor.config.pasteFromWordPromptCleanup || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) ) { data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor ); @@ -87,17 +106,21 @@ For licensing, see LICENSE.html or http://ckeditor.com/license || ( this.path + 'filter/default.js' ) ); // Load with busy indicator. - CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true ); + CKEDITOR.scriptLoader.load( filterFilePath, callback, null, true ); } return !isLoaded; - } + }, + + requires : [ 'clipboard' ] }); })(); /** - * Whether prompt the user about the clean-up of content from MS-Word. + * Whether to prompt the user about the clean up of content being pasted from + * MS Word. * @name CKEDITOR.config.pasteFromWordPromptCleanup + * @since 3.1 * @type Boolean * @default undefined * @example @@ -105,9 +128,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ /** - * The file that provides the MS-Word Filtering rules. - * Note: It's a global configuration which are shared by all editor instances. + * The file that provides the MS Word cleanup function for pasting operations. + * Note: This is a global configuration shared by all editor instances present + * in the page. * @name CKEDITOR.config.pasteFromWordCleanupFile + * @since 3.1 * @type String * @default 'default' * @example