Ticket #2924: 2924.patch

File 2924.patch, 4.7 KB (added by Garry Yao, 15 years ago)
  • _samples/api_dialog.html

     
    7575                                        {
    7676                                                id : 'myField1',
    7777                                                type : 'text',
    78                                                 label : 'My Text Field'
     78                                                label : 'My Text Field',
     79                                                onEnterKey : function(evt)
     80                                                {
     81                                                        this.getDialog().getContentElement( 'customTab', 'myField2' ).focus();
     82                                                        evt.cancel();
     83                                                },
    7984                                        },
    8085                                        {
    8186                                                id : 'myField2',
  • _source/plugins/dialogui/plugin.js

     
    6060                {
    6161                        return this._.initValue;
    6262                }
     63        };
     64       
     65        //SpecialKeyMap
     66        var keystrokeEnum = {
     67                ENTER : 13,
     68                CTRLENTER : 1013
    6369        },
    64         commonEventProcessors = CKEDITOR.tools.extend( {}, CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
     70        //special-keystroke handlers in elementDefinition
     71        keystrokeHandlers = {};
     72       
     73        var commonEventProcessors = CKEDITOR.tools.extend( {}, CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
    6574                {
    6675                        onChange : function( dialog, func )
    6776                        {
     
    7584                                }
    7685
    7786                                this.on( 'change', func );
     87                        },
     88                       
     89                        /**
     90                         * Dispatch special-keystroke to their corresponding named handler function in element definition.
     91                         * @param {Object} dialog
     92                         * @param {Object} func
     93                         * @param {Object} keystrokeName        The shortcut name for keystroke combination
     94                         */
     95                        onSpecialKey : function( dialog, func, keystrokeName )
     96                        {
     97                                keystrokeHandlers[ keystrokeName.toUpperCase() ] = func;
     98                                if ( !this._.specialKeyRegistered )
     99                                {
     100                                        dialog.on( 'load', function()
     101                                        {
     102                                                this.getInputElement().on( 'keyup', function( evt ){
     103                                                       
     104                                                        var keyStrikeCode = evt.data.getKeystroke();
     105                                                        var i ;
     106                                                        for( i in keystrokeEnum)
     107                                                        {
     108                                                                //Is special-keystroke?
     109                                                                if( keystrokeEnum[ i ] == keyStrikeCode
     110                                                                        //Is handler defined?
     111                                                                        && keystrokeHandlers[ i ])
     112                                                                        keystrokeHandlers[ i ].call( this, evt );
     113                                                        }
     114                                                       
     115                                                }, this );
     116                                        }, this );
     117                                        this._.specialKeyRegistered = true;
     118                                }
    78119                        }
    79120                }, true ),
    80121        eventRegex = /^on([A-Z]\w+)/,
     
    207248                                if ( elementDefinition.size )
    208249                                        attributes.size = elementDefinition.size;
    209250
    210                                 // If user presses Enter in a text box, it implies clicking OK for the dialog.
    211                                 var me = this;
    212                                 dialog.on( 'load', function()
    213                                         {
    214                                                 me.getInputElement().on( 'keyup', function( evt )
    215                                                         {
    216                                                                 if ( evt.data.$.keyCode == 13 )
    217                                                                         dialog.getButton( 'ok' ) && dialog.getButton( 'ok' ).click();
    218                                                         } );
    219                                         } );
    220 
    221251                                /** @ignore */
    222252                                var innerHTML = function()
    223253                                {
     
    230260                                        return html.join( '' );
    231261                                };
    232262                                CKEDITOR.ui.dialog.labeledElement.call( this, dialog, elementDefinition, htmlList, innerHTML );
     263                               
     264                                // If user presses Enter in a text box, it implies clicking OK for the dialog.
     265                                var me = this;
     266                                dialog.on( 'load', function()
     267                                        {
     268                                                me.getInputElement().on( 'keyup', function( evt )
     269                                                        {
     270                                                                if ( evt.data.$.keyCode == 13 )
     271                                                                        dialog.getButton( 'ok' ) && dialog.getButton( 'ok' ).click();
     272                                                        } );
     273                                        } );
     274
    233275                        },
    234276
    235277                        /**
  • _source/plugins/dialog/plugin.js

     
    20362036                registerEvents : function( definition )
    20372037                {
    20382038                        var regex = /^on([A-Z]\w+)/,
    2039                                 match;
     2039                                match,
     2040                                        specialKeyRegex = /^(Enter|Esc)Key$/,
     2041                                        specialKeyMatch;
    20402042
    20412043                        var registerDomEvent = function( uiElement, dialog, eventName, func )
    20422044                        {
     
    20522054                                        continue;
    20532055                                if ( this.eventProcessors[i] )
    20542056                                        this.eventProcessors[i].call( this, this._.dialog, definition[i] );
     2057                                //seak for specialkey handler names
     2058                                else if ( specialKeyMatch  = match[1].match( specialKeyRegex ) )
     2059                                {
     2060                                        this.eventProcessors.onSpecialKey.call( this, this._.dialog, definition[i], specialKeyMatch[1] )
     2061                                }
    20552062                                else
    20562063                                        registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
    20572064                        }
     
    20942101                        onHide : function( dialog, func )
    20952102                        {
    20962103                                dialog.on( 'hide', func );
     2104                        },
     2105                        /**
     2106                         * @see CKEDITOR.ui.dialog::eventProcessors.onSpecialKey
     2107                         */
     2108                        onSpecialKey : function( dialog,  func,  keystrokeName )
     2109                        {
    20972110                        }
    20982111                },
    20992112
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy