Ticket #7366: 7366_3.patch
File 7366_3.patch, 5.8 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' ) ) … … 280 296 } 281 297 } 282 298 283 var depressBefore Event;299 var depressBeforePasteEvent; 284 300 function stateFromNamedCommand( command, editor ) 285 301 { 286 302 // IE Bug: queryCommandEnabled('paste') fires also 'beforepaste(copy/cut)', 287 303 // guard to distinguish from the ordinary sources( either 288 304 // keyboard paste or execCommand ) (#4874). 289 CKEDITOR.env.ie && ( depressBefore Event = 1 );305 CKEDITOR.env.ie && ( depressBeforePasteEvent = 1 ); 290 306 291 307 var retval = CKEDITOR.TRISTATE_OFF; 292 308 try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){} 293 309 294 depressBefore Event = 0;310 depressBeforePasteEvent = 0; 295 311 return retval; 296 312 } 297 313 … … 308 324 this.fire( 'pasteState', pasteState ); 309 325 } 310 326 327 var depressPasteEvent = 0; 328 function depressPasteEventNow() 329 { 330 depressPasteEvent = 1; 331 // For safety reason we should wait longer than 0/1ms. 332 // We don't know how long execution of quite complex getClipboardData will take 333 // and in for example 'paste' listner execCommand() (which fires 'paste') is called 334 // after getClipboardData finishes. 335 // Luckily, it's impossible to immediately fire another 'paste' event we want to handle, 336 // because we only handle there native context menu and menu bar. 337 setTimeout( function() { depressPasteEvent = 0; }, 100 ); 338 } 339 311 340 // Register the plugin. 312 341 CKEDITOR.plugins.add( 'clipboard', 313 342 { … … 380 409 editor.on( 'contentDom', function() 381 410 { 382 411 var body = editor.document.getBody(); 383 body.on( CKEDITOR.env.webkit ? 'paste' : 'beforepaste', function( evt )412 body.on( mainPasteEvent, function( evt ) 384 413 { 385 if ( depressBeforeEvent )414 if ( CKEDITOR.env.ie && depressBeforePasteEvent ) 386 415 return; 387 416 388 417 // Fire 'beforePaste' event so clipboard flavor get customized … … 403 432 } ); 404 433 }); 405 434 435 CKEDITOR.env.ie && body.on( 'paste', function( evt ) 436 { 437 if ( depressPasteEvent ) 438 return; 439 440 // Cancel next 'paste' event fired by execIECommand( 'paste' ) 441 // at the end of this callback. 442 depressPasteEventNow(); 443 444 // Prevent native paste. 445 evt.data.preventDefault(); 446 447 // Fire 'beforePaste' event so clipboard flavor get customized 448 // by other plugins. 449 var eventData = { mode : 'html' }; 450 editor.fire( 'beforePaste', eventData ); 451 452 getClipboardData.call( editor, evt, eventData.mode, function ( data ) 453 { 454 // The very last guard to make sure the 455 // paste has successfully happened. 456 if ( !( data = CKEDITOR.tools.trim( data.replace( /<span[^>]+data-cke-bookmark[^<]*?<\/span>/ig,'' ) ) ) ) 457 return; 458 459 var dataTransfer = {}; 460 dataTransfer[ eventData.mode ] = data; 461 editor.fire( 'paste', dataTransfer ); 462 } ); 463 464 // Force IE to paste content into pastebin so pasteDataFromClipboard will work. 465 if ( !execIECommand( editor, 'paste' ) ) 466 editor.openDialog( 'paste' ); 467 }); 468 406 469 // Dismiss the (wrong) 'beforepaste' event fired on context menu open. (#7953) 407 470 body.on( 'contextmenu', function() 408 471 { 409 depressBefore Event = 1;410 setTimeout( function() { depressBefore Event = 0; }, 10 );472 depressBeforePasteEvent = 1; 473 setTimeout( function() { depressBeforePasteEvent = 0; }, 10 ); 411 474 }); 412 475 413 body.on( 'beforecut', function() { !depressBefore Event && fixCut( editor ); } );476 body.on( 'beforecut', function() { !depressBeforePasteEvent && fixCut( editor ); } ); 414 477 415 478 body.on( 'mouseup', function(){ setTimeout( function(){ setToolbarStates.call( editor ); }, 0 ); }, editor ); 416 479 body.on( 'keyup', setToolbarStates, editor );