Skip to content
Permalink
Browse files

Menu: Move regular expression creation outside of the loops

  • Loading branch information
kborchers committed Jul 10, 2012
1 parent 019dcc2 commit 22d078aac608628323c687d1b7fe4424f47fd37f
Showing with 5 additions and 5 deletions.
  1. +5 −5 ui/jquery.ui.menu.js
@@ -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() );
});
}

0 comments on commit 22d078a

Please sign in to comment.
You can’t perform that action at this time.