Ticket #7366: 7366.patch
File 7366.patch, 5.7 KB (added by , 12 years ago) |
---|
-
_source/plugins/clipboard/plugin.js
9 9 10 10 (function() 11 11 { 12 // Safari doesn't like 'beforepaste' event - it sometimes doesn't 13 // properly handles ctrl+c. Probably some race-condition between events. 14 // Chrome and Firefox works well with both events, so better to use 'paste' 15 // which will handle pasting from e.g. browsers' menu bars. 16 // IE7/8 doesn't like 'paste' event for which it's throwing random errors. 17 var mainPasteEvent = CKEDITOR.env.ie ? 'beforepaste' : 'paste'; 18 12 19 // Tries to execute any of the paste, cut or copy commands in IE. Returns a 13 20 // boolean indicating that the operation succeeded. 14 21 var execIECommand = function( editor, command ) … … 92 99 // Prevent IE from pasting at the begining of the document. 93 100 editor.focus(); 94 101 95 if ( !editor.document.getBody().fire( 'beforepaste' ) 102 // Command will be handled by 'beforepaste', but as 103 // execIECommand( 'paste' ) will fire also 'paste' event 104 // we're canceling it. 105 depressPasteEventNow(); 106 107 if ( !editor.document.getBody().fire( mainPasteEvent ) 96 108 && !execIECommand( editor, 'paste' ) ) 97 109 { 98 110 editor.fire( 'pasteDialog' ); … … 104 116 { 105 117 try 106 118 { 107 if ( !editor.document.getBody().fire( 'beforepaste')119 if ( !editor.document.getBody().fire( mainPasteEvent ) 108 120 && !editor.document.$.execCommand( 'Paste', false, null ) ) 109 121 { 110 122 throw 0; … … 134 146 case CKEDITOR.SHIFT + 45 : // SHIFT+INS 135 147 136 148 var body = this.document.getBody(); 149 150 // Cancel 'paste' event because ctrl+v is for IE handled 151 // by 'beforepaste'. 152 depressPasteEventNow(); 137 153 138 154 // Simulate 'beforepaste' event for all none-IEs. 139 155 if ( !CKEDITOR.env.ie && body.fire( 'beforepaste' ) ) … … 275 291 } 276 292 } 277 293 278 var depressBefore Event;294 var depressBeforePasteEvent; 279 295 function stateFromNamedCommand( command, editor ) 280 296 { 281 297 // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)', 282 298 // guard to distinguish from the ordinary sources( either 283 299 // keyboard paste or execCommand ) (#4874). 284 CKEDITOR.env.ie && ( depressBefore Event = 1 );300 CKEDITOR.env.ie && ( depressBeforePasteEvent = 1 ); 285 301 286 302 var retval = CKEDITOR.TRISTATE_OFF; 287 303 try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){} 288 304 289 depressBefore Event = 0;305 depressBeforePasteEvent = 0; 290 306 return retval; 291 307 } 292 308 … … 303 319 this.fire( 'pasteState', pasteState ); 304 320 } 305 321 322 var depressPasteEvent = 0; 323 function depressPasteEventNow() 324 { 325 depressPasteEvent = 1; 326 // For safety reason we should wait longer than 0/1ms. 327 // We don't know how long execution of quite complex getClipboardData will take 328 // and in for example 'paste' listner execCommand() (which fires 'paste') is called 329 // after getClipboardData finishes. 330 // Luckily, it's impossible to immediately fire another 'paste' event we want to handle, 331 // because we only handle there native context menu and menu bar. 332 setTimeout( function() { depressPasteEvent = 0; }, 100 ); 333 } 334 306 335 // Register the plugin. 307 336 CKEDITOR.plugins.add( 'clipboard', 308 337 { … … 375 404 editor.on( 'contentDom', function() 376 405 { 377 406 var body = editor.document.getBody(); 378 body.on( CKEDITOR.env.webkit ? 'paste' : 'beforepaste', function( evt )407 body.on( mainPasteEvent, function( evt ) 379 408 { 380 if ( depressBeforeEvent )409 if ( CKEDITOR.env.ie && depressBeforePasteEvent ) 381 410 return; 382 411 383 412 // Fire 'beforePaste' event so clipboard flavor get customized … … 398 427 } ); 399 428 }); 400 429 430 CKEDITOR.env.ie && body.on( 'paste', function( evt ) 431 { 432 if ( depressPasteEvent ) 433 return; 434 435 // Cancel next 'paste' event fired by execIECommand( 'paste' ) 436 // at the end of this callback. 437 depressPasteEventNow(); 438 439 // Prevent native paste. 440 evt.data.preventDefault(); 441 442 // Fire 'beforePaste' event so clipboard flavor get customized 443 // by other plugins. 444 var eventData = { mode : 'html' }; 445 editor.fire( 'beforePaste', eventData ); 446 447 getClipboardData.call( editor, evt, eventData.mode, function ( data ) 448 { 449 // The very last guard to make sure the 450 // paste has successfully happened. 451 if ( !( data = CKEDITOR.tools.trim( data.replace( /<span[^>]+data-cke-bookmark[^<]*?<\/span>/ig,'' ) ) ) ) 452 return; 453 454 var dataTransfer = {}; 455 dataTransfer[ eventData.mode ] = data; 456 editor.fire( 'paste', dataTransfer ); 457 } ); 458 459 // Force IE to paste content into pastebin so pasteDataFromClipboard will work. 460 execIECommand( editor, 'paste' ); 461 }); 462 401 463 // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953) 402 464 body.on( 'contextmenu', function() 403 465 { 404 depressBefore Event = 1;405 setTimeout( function() { depressBefore Event = 0; }, 10 );466 depressBeforePasteEvent = 1; 467 setTimeout( function() { depressBeforePasteEvent = 0; }, 10 ); 406 468 }); 407 469 408 body.on( 'beforecut', function() { !depressBefore Event && fixCut( editor ); } );470 body.on( 'beforecut', function() { !depressBeforePasteEvent && fixCut( editor ); } ); 409 471 410 472 body.on( 'mouseup', function(){ setTimeout( function(){ setToolbarStates.call( editor ); }, 0 ); }, editor ); 411 473 body.on( 'keyup', setToolbarStates, editor );