@@ -23,6 +23,7 @@ $.widget( "ui.menu", {
2323 icons : {
2424 submenu : "ui-icon-carat-1-e"
2525 } ,
26+ items : "> *" ,
2627 menus : "ul" ,
2728 position : {
2829 my : "left top" ,
@@ -110,7 +111,7 @@ $.widget( "ui.menu", {
110111 focus : function ( event , keepActiveItem ) {
111112 // If there's already an active item, keep it active
112113 // If not, activate the first item
113- var item = this . active || this . element . children ( ".ui-menu-item" ) . eq ( 0 ) ;
114+ var item = this . active || this . element . find ( this . options . items ) . eq ( 0 ) ;
114115
115116 if ( ! keepActiveItem ) {
116117 this . focus ( event , item ) ;
@@ -234,7 +235,7 @@ $.widget( "ui.menu", {
234235 }
235236
236237 regex = new RegExp ( "^" + escape ( character ) , "i" ) ;
237- match = this . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
238+ match = this . activeMenu . find ( this . options . items ) . filter ( function ( ) {
238239 return regex . test ( $ ( this ) . text ( ) ) ;
239240 } ) ;
240241 match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
@@ -246,7 +247,7 @@ $.widget( "ui.menu", {
246247 if ( ! match . length ) {
247248 character = String . fromCharCode ( event . keyCode ) ;
248249 regex = new RegExp ( "^" + escape ( character ) , "i" ) ;
249- match = this . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
250+ match = this . activeMenu . find ( this . options . items ) . filter ( function ( ) {
250251 return regex . test ( $ ( this ) . text ( ) ) ;
251252 } ) ;
252253 }
@@ -283,6 +284,7 @@ $.widget( "ui.menu", {
283284
284285 refresh : function ( ) {
285286 var menus ,
287+ items ,
286288 icon = this . options . icons . submenu ,
287289 submenus = this . element . find ( this . options . menus ) ;
288290
@@ -311,9 +313,10 @@ $.widget( "ui.menu", {
311313 } ) ;
312314
313315 menus = submenus . add ( this . element ) ;
316+ items = menus . find ( this . options . items ) ;
314317
315- // Initialize unlinked menu-items containing spaces and/or dashes only as dividers
316- menus . children ( ":not( .ui-menu-item) " ) . each ( function ( ) {
318+ // Initialize menu-items containing spaces and/or dashes only as dividers
319+ items . not ( ".ui-menu-item" ) . each ( function ( ) {
317320 var item = $ ( this ) ;
318321 // hyphen, em dash, en dash
319322 if ( ! / [ ^ \- \u2014 \u2013 \s ] / . test ( item . text ( ) ) ) {
@@ -322,7 +325,7 @@ $.widget( "ui.menu", {
322325 } ) ;
323326
324327 // Don't refresh list items that are already adapted
325- menus . children ( ":not( .ui-menu-item,.ui-menu-divider) " )
328+ items . not ( ".ui-menu-item, .ui-menu-divider" )
326329 . addClass ( "ui-menu-item" )
327330 . uniqueId ( )
328331 . addClass ( "ui-corner-all" )
@@ -332,7 +335,7 @@ $.widget( "ui.menu", {
332335 } ) ;
333336
334337 // Add aria-disabled attribute to any disabled menu item
335- menus . children ( ".ui-state-disabled" ) . attr ( "aria-disabled" , "true" ) ;
338+ items . filter ( ".ui-state-disabled" ) . attr ( "aria-disabled" , "true" ) ;
336339
337340 // If the active item has been removed, blur the menu
338341 if ( this . active && ! $ . contains ( this . element [ 0 ] , this . active [ 0 ] ) ) {
@@ -516,7 +519,7 @@ $.widget( "ui.menu", {
516519 var newItem = this . active &&
517520 this . active
518521 . children ( ".ui-menu " )
519- . children ( ".ui-menu-item" )
522+ . find ( this . options . items )
520523 . first ( ) ;
521524
522525 if ( newItem && newItem . length ) {
@@ -559,7 +562,7 @@ $.widget( "ui.menu", {
559562 }
560563 }
561564 if ( ! next || ! next . length || ! this . active ) {
562- next = this . activeMenu . children ( ".ui-menu-item" ) [ filter ] ( ) ;
565+ next = this . activeMenu . find ( this . options . items ) [ filter ] ( ) ;
563566 }
564567
565568 this . focus ( event , next ) ;
@@ -585,7 +588,7 @@ $.widget( "ui.menu", {
585588
586589 this . focus ( event , item ) ;
587590 } else {
588- this . focus ( event , this . activeMenu . children ( ".ui-menu-item" )
591+ this . focus ( event , this . activeMenu . find ( this . options . items )
589592 [ ! this . active ? "first" : "last" ] ( ) ) ;
590593 }
591594 } ,
@@ -609,7 +612,7 @@ $.widget( "ui.menu", {
609612
610613 this . focus ( event , item ) ;
611614 } else {
612- this . focus ( event , this . activeMenu . children ( ".ui-menu-item" ) . first ( ) ) ;
615+ this . focus ( event , this . activeMenu . find ( this . options . items ) . first ( ) ) ;
613616 }
614617 } ,
615618
0 commit comments