Menu: Move regular expression creation outside of the loops

This commit is contained in:
kborchers 2012-07-09 23:37:27 -05:00
parent 019dcc26e3
commit 22d078aac6

10
ui/jquery.ui.menu.js vendored
View File

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