Ticket #8985: 8985_2.patch

File 8985_2.patch, 6.5 KB (added by Frederico Caldeira Knabben, 12 years ago)
  • _source/plugins/dialog/plugin.js

     
    397397                this.changeFocus = changeFocus;
    398398
    399399
    400                 function focusKeydownHandler( evt )
     400                function keydownHandler( evt )
    401401                {
    402402                        // If I'm not the top dialog, ignore.
    403403                        if ( me != CKEDITOR.dialog._.currentTop )
     
    407407                                rtl = editor.lang.dir == 'rtl';
    408408
    409409                        processed = 0;
     410
    410411                        if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
    411412                        {
    412413                                var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
     
    450451                                changeFocus( 1 );
    451452                                processed = 1;
    452453                        }
     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)
    453460
    454                         if ( processed )
     461                        }
     462                        else if ( keystroke == 27 /*ESC*/ )
    455463                        {
    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)
    458475                        }
     476
     477                        processed && keypressHandler( evt );
    459478                }
    460479
    461                 function focusKeyPressHandler( evt )
     480                function keypressHandler( evt )
    462481                {
    463                         processed && evt.data.preventDefault();
     482                        processed && evt.data.preventDefault( 1 );
    464483                }
    465484
    466485                var dialogElement = this._.element;
    467486                // Add the dialog keyboard handlers.
    468487                this.on( 'show', function()
    469488                        {
    470                                 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
     489                                dialogElement.on( 'keydown', keydownHandler, this );
     490
    471491                                // 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 );
    475495
    476496                        } );
    477497                this.on( 'hide', function()
    478498                        {
    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 );
    482502
    483503                                // Reset fields state when closing dialog.
    484504                                iterContents( function( item ) { resetField.apply( item ); } );
     
    486506                this.on( 'iframeAdded', function( evt )
    487507                        {
    488508                                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 );
    490510                        } );
    491511
    492512                // Auto-focus logic in dialog.
     
    815835                        element.on( 'keydown', accessKeyDownHandler );
    816836                        element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
    817837
    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 dialog
    827                                                 if ( button )
    828                                                         button.click();
    829                                                 else
    830                                                 {
    831                                                         if ( this.fire( 'cancel', { hide : true } ).hide !== false )
    832                                                                 this.hide();
    833                                                 }
    834                                         } );
    835 
    836838                        // Reset the hasFocus state.
    837839                        this._.hasFocus = false;
    838840
     
    979981                                element.removeListener( 'keydown', accessKeyDownHandler );
    980982                                element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
    981983
    982                                 // Remove bubbling-prevention handler. (#4269)
    983                                 for ( var event in { keyup :1, keydown :1, keypress :1 } )
    984                                         element.removeListener( event, preventKeyBubbling );
    985 
    986984                                var editor = this._.editor;
    987985                                editor.focus();
    988986
     
    21992197        {
    22002198        };
    22012199
    2202         // ESC, ENTER
    2203         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 
    22102200        (function()
    22112201        {
    22122202                CKEDITOR.ui.dialog =
  • _source/plugins/dialogui/plugin.js

     
    240240                                if ( elementDefinition.inputStyle )
    241241                                        attributes.style = elementDefinition.inputStyle;
    242242
    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 
    267243                                /** @ignore */
    268244                                var innerHTML = function()
    269245                                {
     
    530506
    531507                                                        element.on( 'keydown', function( evt )
    532508                                                                {
    533                                                                         if ( evt.data.getKeystroke() in { 32:1 } )
     509                                                                        if ( evt.data.getKeystroke() in { 32:1 /*SPACE*/, 13:1 /*ENTER*/ } )
    534510                                                                        {
    535511                                                                                me.click();
    536                                                                                 evt.data.preventDefault();
     512                                                                                evt.data.preventDefault( 1 );
    537513                                                                        }
    538514                                                                } );
    539515                                                })();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy