app/assets/javascripts/ckeditor/_source/plugins/clipboard/plugin.js in refinerycms-ckeditor-0.1.4 vs app/assets/javascripts/ckeditor/_source/plugins/clipboard/plugin.js in refinerycms-ckeditor-0.2.0

- old
+ new

@@ -1,7 +1,7 @@ /* -Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ /** * @file Clipboard support @@ -14,14 +14,14 @@ var execIECommand = function( editor, command ) { var doc = editor.document, body = doc.getBody(); - var enabled = 0; + var enabled = false; var onExec = function() { - enabled = 1; + enabled = true; }; // The following seems to be the only reliable way to detect that // clipboard commands are enabled in IE. It will fire the // onpaste/oncut/oncopy events only if the security settings allowed @@ -133,15 +133,12 @@ case CKEDITOR.CTRL + 86 : // CTRL+V case CKEDITOR.SHIFT + 45 : // SHIFT+INS var body = this.document.getBody(); - // Simulate 'beforepaste' event for all none-IEs. - if ( !CKEDITOR.env.ie && body.fire( 'beforepaste' ) ) - event.cancel(); // Simulate 'paste' event for Opera/Firefox2. - else if ( CKEDITOR.env.opera + if ( CKEDITOR.env.opera || CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 ) body.fire( 'paste' ); return; // Cut @@ -224,12 +221,13 @@ var editor = this; // Wait a while and grab the pasted contents window.setTimeout( function() { - mode == 'text' && CKEDITOR.env.gecko && editor.focusGrabber.focus(); - pastebin.remove(); + // Restore properly the document focus. (#5684, #8849) + editor.document.getBody().focus(); + editor.removeListener( 'selectionChange', cancel ); // Grab the HTML contents. // We need to look for a apple style wrapper on webkit it also adds // a div wrapper if you copy/paste the body of the editor. @@ -238,11 +236,13 @@ pastebin = ( CKEDITOR.env.webkit && ( bogusSpan = pastebin.getFirst() ) && ( bogusSpan.is && bogusSpan.hasClass( 'Apple-style-span' ) ) ? bogusSpan : pastebin ); + // IE7: selection must go before removing paste. (#8691) sel.selectBookmarks( bms ); + pastebin.remove(); callback( pastebin[ 'get' + ( mode == 'text' ? 'Value' : 'Html' ) ]() ); }, 0 ); } // Cutting off control type element in IE standards breaks the selection entirely. (#4881) @@ -373,15 +373,22 @@ // 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( CKEDITOR.env.webkit ? 'paste' : 'beforepaste', function( evt ) + + // Intercept the paste before it actually takes place. + body.on( !CKEDITOR.env.ie ? 'paste' : 'beforepaste', function( evt ) { if ( depressBeforeEvent ) return; + // Dismiss the (wrong) 'beforepaste' event fired on toolbar menu open. + var domEvent = evt.data && evt.data.$; + if ( CKEDITOR.env.ie && domEvent && !domEvent.ctrlKey ) + return; + // Fire 'beforePaste' event so clipboard flavor get customized // by other plugins. var eventData = { mode : 'html' }; editor.fire( 'beforePaste', eventData ); @@ -396,15 +403,34 @@ dataTransfer[ eventData.mode ] = data; editor.fire( 'paste', dataTransfer ); } ); }); - // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953) - body.on( 'contextmenu', function() + if ( CKEDITOR.env.ie ) { - depressBeforeEvent = 1; - setTimeout( function() { depressBeforeEvent = 0; }, 10 ); - }); + // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953) + body.on( 'contextmenu', function() + { + depressBeforeEvent = 1; + // Important: The following timeout will be called only after menu closed. + setTimeout( function() { depressBeforeEvent = 0; }, 0 ); + } ); + + // Handle IE's late coming "paste" event when pasting from + // browser toolbar/context menu. + body.on( 'paste', function( evt ) + { + if ( !editor.document.getById( 'cke_pastebin' ) ) + { + // Prevent native paste. + evt.data.preventDefault(); + + depressBeforeEvent = 0; + // Resort to the paste command. + pasteCmd.exec( editor ); + } + } ); + } body.on( 'beforecut', function() { !depressBeforeEvent && fixCut( editor ); } ); body.on( 'mouseup', function(){ setTimeout( function(){ setToolbarStates.call( editor ); }, 0 ); }, editor ); body.on( 'keyup', setToolbarStates, editor );