X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fclipboard%2Fplugin.js;h=3740057b50aaeb9c254a7f7410b7d87f6bb2e91c;hb=4e70ea24db840898be8cc21c950363a52a2a6aba;hp=342d70888f6b4105bdf6e612d6b82428c6d5801e;hpb=48b1db88210b4160dce439c6e3e32e14af8c106b;p=ckeditor.git diff --git a/_source/plugins/clipboard/plugin.js b/_source/plugins/clipboard/plugin.js index 342d708..3740057 100644 --- a/_source/plugins/clipboard/plugin.js +++ b/_source/plugins/clipboard/plugin.js @@ -158,6 +158,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } }; + function cancel( evt ) { evt.cancel(); } + // Allow to peek clipboard content by redirecting the // pasting content into a temporary bin and grab the content of it. function getClipboardData( evt, mode, callback ) @@ -208,19 +210,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license var bms = sel.createBookmarks(); + this.on( 'selectionChange', cancel, null, null, 0 ); + // Turn off design mode temporarily before give focus to the paste bin. if ( mode == 'text' ) - { - if ( CKEDITOR.env.ie ) - { - var ieRange = doc.getBody().$.createTextRange(); - ieRange.moveToElementText( pastebin.$ ); - ieRange.execCommand( 'Paste' ); - evt.data.preventDefault(); - } - else - pastebin.$.focus(); - } + pastebin.$.focus(); else { range.setStartAt( pastebin, CKEDITOR.POSITION_AFTER_START ); @@ -234,6 +228,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { mode == 'text' && CKEDITOR.env.gecko && editor.focusGrabber.focus(); pastebin.remove(); + editor.removeListener( 'selectionChange', cancel ); // Grab the HTML contents. // We need to look for a apple style wrapper on webkit it also adds @@ -288,7 +283,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // keyboard paste or execCommand ) (#4874). CKEDITOR.env.ie && ( depressBeforeEvent = 1 ); - var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; + var retval = CKEDITOR.TRISTATE_OFF; + try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){} + depressBeforeEvent = 0; return retval; } @@ -322,6 +319,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else if ( data[ 'text' ] ) editor.insertText( data[ 'text' ] ); + setTimeout( function () { editor.fire( 'afterPaste' ); }, 0 ); + }, null, null, 1000 ); editor.on( 'pasteDialog', function( evt ) @@ -370,29 +369,31 @@ For licensing, see LICENSE.html or http://ckeditor.com/license editor.on( 'key', onKey, editor ); - var mode = editor.config.forcePasteAsPlainText ? 'text' : 'html'; - // We'll be catching all pasted content in one line, regardless of whether the // it's introduced by a document command execution (e.g. toolbar buttons) or // user paste behaviors. (e.g. Ctrl-V) editor.on( 'contentDom', function() { var body = editor.document.getBody(); - body.on( ( ( mode == 'text' && CKEDITOR.env.ie ) || CKEDITOR.env.webkit ) ? 'paste' : 'beforepaste', - function( evt ) + body.on( CKEDITOR.env.webkit ? 'paste' : 'beforepaste', function( evt ) { if ( depressBeforeEvent ) return; - getClipboardData.call( editor, evt, mode, function ( data ) + // Fire 'beforePaste' event so clipboard flavor get customized + // by other plugins. + var eventData = { mode : 'html' }; + editor.fire( 'beforePaste', eventData ); + + getClipboardData.call( editor, evt, eventData.mode, function ( data ) { // The very last guard to make sure the // paste has successfully happened. - if ( !data ) + if ( !( data = CKEDITOR.tools.trim( data.replace( /]+data-cke-bookmark[^<]*?<\/span>/ig,'' ) ) ) ) return; var dataTransfer = {}; - dataTransfer[ mode ] = data; + dataTransfer[ eventData.mode ] = data; editor.fire( 'paste', dataTransfer ); } ); });