Ticket #8985: 8985_4.patch

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

     
    141141                        dir = editor.lang.dir,
    142142                        tabsToRemove = {},
    143143                        i,
    144                         processed;
     144                        processed, stopPropagation;
    145145
    146146                        if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) ||    // The buttons in MacOS Apps are in reverse order (#4750)
    147147                                ( buttonsOrder == 'rtl' && dir == 'ltr' ) ||
     
    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 )
    404404                                return;
    405405
    406406                        var keystroke = evt.data.getKeystroke(),
    407                                 rtl = editor.lang.dir == 'rtl';
     407                                rtl = editor.lang.dir == 'rtl',
     408                                button;
    408409
    409                         processed = 0;
     410                        processed = stopPropagation = 0;
     411
    410412                        if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
    411413                        {
    412414                                var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
     
    450452                                changeFocus( 1 );
    451453                                processed = 1;
    452454                        }
    453 
    454                         if ( processed )
     455                        // If user presses enter key in a text box, it implies clicking OK for the dialog.
     456                        else if ( keystroke == 13 /*ENTER*/ )
    455457                        {
    456                                 evt.stop();
    457                                 evt.data.preventDefault();
     458                                // Don't do that for a target that handles ENTER.
     459                                var target = evt.data.getTarget();
     460                                if ( !target.is( 'a', 'button', 'select' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) )
     461                                {
     462                                        button = this.getButton( 'ok' );
     463                                        button && CKEDITOR.tools.setTimeout( button.click, 0, button );
     464                                        processed = 1
     465                                }
     466                                stopPropagation = 1; // Always block the propagation (#4269)
    458467                        }
     468                        else if ( keystroke == 27 /*ESC*/ )
     469                        {
     470                                button = this.getButton( 'cancel' );
     471
     472                                // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.
     473                                if ( button )
     474                                        CKEDITOR.tools.setTimeout( button.click, 0, button );
     475                                else
     476                                {
     477                                        if ( this.fire( 'cancel', { hide : true } ).hide !== false )
     478                                                this.hide();
     479                                }
     480                                stopPropagation = 1; // Always block the propagation (#4269)
     481                        }
     482                        else
     483                                return;
     484
     485                        keypressHandler( evt );
    459486                }
    460487
    461                 function focusKeyPressHandler( evt )
     488                function keypressHandler( evt )
    462489                {
    463                         processed && evt.data.preventDefault();
     490                        if ( processed )
     491                                evt.data.preventDefault(1);
     492                        else if ( stopPropagation )
     493                                evt.data.stopPropagation();
    464494                }
    465495
    466496                var dialogElement = this._.element;
    467497                // Add the dialog keyboard handlers.
    468498                this.on( 'show', function()
    469499                        {
    470                                 dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
     500                                dialogElement.on( 'keydown', keydownHandler, this );
     501
    471502                                // 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 );
     503                                // keypress. So we must do a longer trip in those cases. (#4531,#8985)
     504                                if ( CKEDITOR.env.opera || CKEDITOR.env.gecko )
     505                                        dialogElement.on( 'keypress', keypressHandler, this );
    475506
    476507                        } );
    477508                this.on( 'hide', function()
    478509                        {
    479                                 dialogElement.removeListener( 'keydown', focusKeydownHandler );
    480                                 if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
    481                                         dialogElement.removeListener( 'keypress', focusKeyPressHandler );
     510                                dialogElement.removeListener( 'keydown', keydownHandler );
     511                                if ( CKEDITOR.env.opera || CKEDITOR.env.gecko )
     512                                        dialogElement.removeListener( 'keypress', keypressHandler );
    482513
    483514                                // Reset fields state when closing dialog.
    484515                                iterContents( function( item ) { resetField.apply( item ); } );
     
    486517                this.on( 'iframeAdded', function( evt )
    487518                        {
    488519                                var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
    489                                 doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
     520                                doc.on( 'keydown', keydownHandler, this, null, 0 );
    490521                        } );
    491522
    492523                // Auto-focus logic in dialog.
     
    815846                        element.on( 'keydown', accessKeyDownHandler );
    816847                        element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
    817848
    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 
    836849                        // Reset the hasFocus state.
    837850                        this._.hasFocus = false;
    838851
     
    979992                                element.removeListener( 'keydown', accessKeyDownHandler );
    980993                                element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
    981994
    982                                 // Remove bubbling-prevention handler. (#4269)
    983                                 for ( var event in { keyup :1, keydown :1, keypress :1 } )
    984                                         element.removeListener( event, preventKeyBubbling );
    985 
    986995                                var editor = this._.editor;
    987996                                editor.focus();
    988997
     
    21992208        {
    22002209        };
    22012210
    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 
    22102211        (function()
    22112212        {
    22122213                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                                {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy