Ticket #8985: 8985_2.patch
File 8985_2.patch, 6.5 KB (added by , 12 years ago) |
---|
-
_source/plugins/dialog/plugin.js
397 397 this.changeFocus = changeFocus; 398 398 399 399 400 function focusKeydownHandler( evt )400 function keydownHandler( evt ) 401 401 { 402 402 // If I'm not the top dialog, ignore. 403 403 if ( me != CKEDITOR.dialog._.currentTop ) … … 407 407 rtl = editor.lang.dir == 'rtl'; 408 408 409 409 processed = 0; 410 410 411 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) 411 412 { 412 413 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 ); … … 450 451 changeFocus( 1 ); 451 452 processed = 1; 452 453 } 454 // If user presses enter key in a text box, it implies clicking OK for the dialog. 455 else if ( keystroke == 13 /*ENTER*/ ) 456 { 457 var button = this.getButton( 'ok' ); 458 button && CKEDITOR.tools.setTimeout( button.click, 0, button ); 459 processed = 1; // Always block the propagation (#4269) 453 460 454 if ( processed ) 461 } 462 else if ( keystroke == 27 /*ESC*/ ) 455 463 { 456 evt.stop(); 457 evt.data.preventDefault(); 464 var button = this.getButton( 'cancel' ); 465 466 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog. 467 if ( button ) 468 CKEDITOR.tools.setTimeout( button.click, 0, button ); 469 else 470 { 471 if ( this.fire( 'cancel', { hide : true } ).hide !== false ) 472 this.hide(); 473 } 474 processed = 1; // Always block the propagation (#4269) 458 475 } 476 477 processed && keypressHandler( evt ); 459 478 } 460 479 461 function focusKeyPressHandler( evt )480 function keypressHandler( evt ) 462 481 { 463 processed && evt.data.preventDefault( );482 processed && evt.data.preventDefault( 1 ); 464 483 } 465 484 466 485 var dialogElement = this._.element; 467 486 // Add the dialog keyboard handlers. 468 487 this.on( 'show', function() 469 488 { 470 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 ); 489 dialogElement.on( 'keydown', keydownHandler, this ); 490 471 491 // Some browsers instead, don't cancel key events in the keydown, but in the 472 // keypress. So we must do a longer trip in those cases. (#4531 )473 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ))474 dialogElement.on( 'keypress', focusKeyPressHandler, this );492 // keypress. So we must do a longer trip in those cases. (#4531,#8985) 493 if ( CKEDITOR.env.opera || CKEDITOR.env.gecko ) 494 dialogElement.on( 'keypress', keypressHandler, this ); 475 495 476 496 } ); 477 497 this.on( 'hide', function() 478 498 { 479 dialogElement.removeListener( 'keydown', focusKeydownHandler );480 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ))481 dialogElement.removeListener( 'keypress', focusKeyPressHandler );499 dialogElement.removeListener( 'keydown', keydownHandler ); 500 if ( CKEDITOR.env.opera || CKEDITOR.env.gecko ) 501 dialogElement.removeListener( 'keypress', keypressHandler ); 482 502 483 503 // Reset fields state when closing dialog. 484 504 iterContents( function( item ) { resetField.apply( item ); } ); … … 486 506 this.on( 'iframeAdded', function( evt ) 487 507 { 488 508 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document ); 489 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );509 doc.on( 'keydown', keydownHandler, this, null, 0 ); 490 510 } ); 491 511 492 512 // Auto-focus logic in dialog. … … 815 835 element.on( 'keydown', accessKeyDownHandler ); 816 836 element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); 817 837 818 // Prevent some keys from bubbling up. (#4269)819 for ( var event in { keyup :1, keydown :1, keypress :1 } )820 element.on( event, preventKeyBubbling );821 822 // Register the Esc hotkeys.823 registerAccessKey( this, this, '\x1b', null, function()824 {825 var button = this.getButton( 'cancel' );826 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog827 if ( button )828 button.click();829 else830 {831 if ( this.fire( 'cancel', { hide : true } ).hide !== false )832 this.hide();833 }834 } );835 836 838 // Reset the hasFocus state. 837 839 this._.hasFocus = false; 838 840 … … 979 981 element.removeListener( 'keydown', accessKeyDownHandler ); 980 982 element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler ); 981 983 982 // Remove bubbling-prevention handler. (#4269)983 for ( var event in { keyup :1, keydown :1, keypress :1 } )984 element.removeListener( event, preventKeyBubbling );985 986 984 var editor = this._.editor; 987 985 editor.focus(); 988 986 … … 2199 2197 { 2200 2198 }; 2201 2199 2202 // ESC, ENTER2203 var preventKeyBubblingKeys = { 27 :1, 13 :1 };2204 var preventKeyBubbling = function( e )2205 {2206 if ( e.data.getKeystroke() in preventKeyBubblingKeys )2207 e.data.stopPropagation();2208 };2209 2210 2200 (function() 2211 2201 { 2212 2202 CKEDITOR.ui.dialog = -
_source/plugins/dialogui/plugin.js
240 240 if ( elementDefinition.inputStyle ) 241 241 attributes.style = elementDefinition.inputStyle; 242 242 243 // If user presses Enter in a text box, it implies clicking OK for the dialog.244 var me = this, keyPressedOnMe = false;245 dialog.on( 'load', function()246 {247 me.getInputElement().on( 'keydown', function( evt )248 {249 if ( evt.data.getKeystroke() == 13 )250 keyPressedOnMe = true;251 } );252 253 // Lower the priority this 'keyup' since 'ok' will close the dialog.(#3749)254 me.getInputElement().on( 'keyup', function( evt )255 {256 if ( evt.data.getKeystroke() == 13 && keyPressedOnMe )257 {258 dialog.getButton( 'ok' ) && setTimeout( function ()259 {260 dialog.getButton( 'ok' ).click();261 }, 0 );262 keyPressedOnMe = false;263 }264 }, null, null, 1000 );265 } );266 267 243 /** @ignore */ 268 244 var innerHTML = function() 269 245 { … … 530 506 531 507 element.on( 'keydown', function( evt ) 532 508 { 533 if ( evt.data.getKeystroke() in { 32:1 } )509 if ( evt.data.getKeystroke() in { 32:1 /*SPACE*/, 13:1 /*ENTER*/ } ) 534 510 { 535 511 me.click(); 536 evt.data.preventDefault( );512 evt.data.preventDefault( 1 ); 537 513 } 538 514 } ); 539 515 })();