@@ -136,7 +136,7 @@ return $.widget( "ui.menu", {
136136
137137 // If there's already an active item, keep it active
138138 // If not, activate the first item
139- var item = this . active || this . element . find ( this . options . items ) . eq ( 0 ) ;
139+ var item = this . active || this . _menuItems ( ) . first ( ) ;
140140
141141 if ( ! keepActiveItem ) {
142142 this . focus ( event , item ) ;
@@ -538,11 +538,7 @@ return $.widget( "ui.menu", {
538538 } ,
539539
540540 expand : function ( event ) {
541- var newItem = this . active &&
542- this . active
543- . children ( ".ui-menu " )
544- . find ( this . options . items )
545- . first ( ) ;
541+ var newItem = this . active && this . _menuItems ( this . active . children ( ".ui-menu" ) ) . first ( ) ;
546542
547543 if ( newItem && newItem . length ) {
548544 this . _open ( newItem . parent ( ) ) ;
@@ -570,21 +566,27 @@ return $.widget( "ui.menu", {
570566 return this . active && ! this . active . nextAll ( ".ui-menu-item" ) . length ;
571567 } ,
572568
569+ _menuItems : function ( menu ) {
570+ return ( menu || this . element )
571+ . find ( this . options . items )
572+ . filter ( ".ui-menu-item" ) ;
573+ } ,
574+
573575 _move : function ( direction , filter , event ) {
574576 var next ;
575577 if ( this . active ) {
576578 if ( direction === "first" || direction === "last" ) {
577579 next = this . active
578580 [ direction === "first" ? "prevAll" : "nextAll" ] ( ".ui-menu-item" )
579- . eq ( - 1 ) ;
581+ . last ( ) ;
580582 } else {
581583 next = this . active
582584 [ direction + "All" ] ( ".ui-menu-item" )
583- . eq ( 0 ) ;
585+ . first ( ) ;
584586 }
585587 }
586588 if ( ! next || ! next . length || ! this . active ) {
587- next = this . activeMenu . find ( this . options . items ) [ filter ] ( ) ;
589+ next = this . _menuItems ( this . activeMenu ) [ filter ] ( ) ;
588590 }
589591
590592 this . focus ( event , next ) ;
@@ -610,7 +612,7 @@ return $.widget( "ui.menu", {
610612
611613 this . focus ( event , item ) ;
612614 } else {
613- this . focus ( event , this . activeMenu . find ( this . options . items )
615+ this . focus ( event , this . _menuItems ( this . activeMenu )
614616 [ ! this . active ? "first" : "last" ] ( ) ) ;
615617 }
616618 } ,
@@ -634,7 +636,7 @@ return $.widget( "ui.menu", {
634636
635637 this . focus ( event , item ) ;
636638 } else {
637- this . focus ( event , this . activeMenu . find ( this . options . items ) . first ( ) ) ;
639+ this . focus ( event , this . _menuItems ( this . activeMenu ) . first ( ) ) ;
638640 }
639641 } ,
640642
0 commit comments