]> source.dussan.org Git - jquery-ui.git/commitdiff
Menu: Move regular expression creation outside of the loops
authorkborchers <kris.borchers@gmail.com>
Tue, 10 Jul 2012 04:37:27 +0000 (23:37 -0500)
committerkborchers <kris.borchers@gmail.com>
Tue, 10 Jul 2012 05:14:54 +0000 (00:14 -0500)
ui/jquery.ui.menu.js

index 3658bd8d566acd288f760e8349cd6648e36b76fc..4e565de453e478aebdddba2596b65166a0d2c171 100644 (file)
@@ -173,7 +173,7 @@ $.widget( "ui.menu", {
        },
 
        _keydown: function( event ) {
-               var match, prev, character, skip,
+               var match, prev, character, skip, regex,
                        preventDefault = true;
 
                function escape( value ) {
@@ -228,9 +228,9 @@ $.widget( "ui.menu", {
                                character = prev + character;
                        }
 
+                       regex = new RegExp( "^" + escape( character ), "i" );
                        match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
-                               return new RegExp( "^" + escape( character ), "i" )
-                                       .test( $( this ).children( "a" ).text() );
+                               return regex.test( $( this ).children( "a" ).text() );
                        });
                        match = skip && match.index( this.active.next() ) !== -1 ?
                                this.active.nextAll( ".ui-menu-item" ) :
@@ -240,9 +240,9 @@ $.widget( "ui.menu", {
                        // to move down the menu to the first item that starts with that character
                        if ( !match.length ) {
                                character = String.fromCharCode( event.keyCode );
+                               regex = new RegExp( "^" + escape( character ), "i" );
                                match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
-                                       return new RegExp( "^" + escape( character ), "i" )
-                                               .test( $( this ).children( "a" ).text() );
+                                       return regex.test( $( this ).children( "a" ).text() );
                                });
                        }