@@ -54,14 +54,13 @@ $.widget( "ui.menu", {
5454 } ,
5555 "click .ui-menu-item:has(a)" : function ( event ) {
5656 event . stopImmediatePropagation ( ) ;
57- var target = $ ( event . currentTarget ) ;
58- // it's possible to click an item without hovering it (#7085)
59- if ( ! this . active || ( this . active [ 0 ] !== target [ 0 ] ) ) {
60- this . focus ( event , target ) ;
61- }
6257 this . select ( event ) ;
63- // Redirect focus to the menu.
64- this . element . focus ( ) ;
58+ // Redirect focus to the menu with a delay for firefox
59+ this . _delay ( function ( ) {
60+ if ( ! this . element . is ( ":focus" ) ) {
61+ this . element . focus ( ) ;
62+ }
63+ } , 20 ) ;
6564 } ,
6665 "mouseover .ui-menu-item" : function ( event ) {
6766 event . stopImmediatePropagation ( ) ;
@@ -72,9 +71,21 @@ $.widget( "ui.menu", {
7271 } ,
7372 "mouseleave" : "collapseAll" ,
7473 "mouseleave .ui-menu" : "collapseAll" ,
75- "mouseout .ui-menu-item" : "blur" ,
7674 "focus" : function ( event ) {
77- this . focus ( event , $ ( event . target ) . children ( ".ui-menu-item:first" ) ) ;
75+ var firstItem = this . element . children ( ".ui-menu-item" ) . eq ( 0 ) ;
76+ if ( this . _hasScroll ( ) && ! this . active ) {
77+ var menu = this . element ;
78+ menu . children ( ) . each ( function ( ) {
79+ var currentItem = $ ( this ) ;
80+ if ( currentItem . offset ( ) . top - menu . offset ( ) . top >= 0 ) {
81+ firstItem = currentItem ;
82+ return false ;
83+ }
84+ } ) ;
85+ } else if ( this . active ) {
86+ firstItem = this . active ;
87+ }
88+ this . focus ( event , firstItem ) ;
7889 } ,
7990 blur : function ( event ) {
8091 this . _delay ( function ( ) {
@@ -283,21 +294,6 @@ $.widget( "ui.menu", {
283294 focus : function ( event , item ) {
284295 this . blur ( event ) ;
285296
286- if ( this . _hasScroll ( ) ) {
287- var borderTop = parseFloat ( $ . curCSS ( this . activeMenu [ 0 ] , "borderTopWidth" , true ) ) || 0 ,
288- paddingTop = parseFloat ( $ . curCSS ( this . activeMenu [ 0 ] , "paddingTop" , true ) ) || 0 ,
289- offset = item . offset ( ) . top - this . activeMenu . offset ( ) . top - borderTop - paddingTop ,
290- scroll = this . activeMenu . scrollTop ( ) ,
291- elementHeight = this . activeMenu . height ( ) ,
292- itemHeight = item . height ( ) ;
293-
294- if ( offset < 0 ) {
295- this . activeMenu . scrollTop ( scroll + offset ) ;
296- } else if ( offset + itemHeight > elementHeight ) {
297- this . activeMenu . scrollTop ( scroll + offset - elementHeight + itemHeight ) ;
298- }
299- }
300-
301297 this . active = item . first ( )
302298 . children ( "a" )
303299 . addClass ( "ui-state-focus" )
@@ -463,15 +459,14 @@ $.widget( "ui.menu", {
463459 } ,
464460
465461 nextPage : function ( event ) {
462+ if ( ! this . active ) {
463+ this . focus ( event , this . activeMenu . children ( ".ui-menu-item" ) . first ( ) ) ;
464+ return ;
465+ }
466+ if ( this . last ( ) ) {
467+ return ;
468+ }
466469 if ( this . _hasScroll ( ) ) {
467- if ( ! this . active ) {
468- this . focus ( event , this . activeMenu . children ( ".ui-menu-item" ) . first ( ) ) ;
469- return ;
470- }
471- if ( this . last ( ) ) {
472- return ;
473- }
474-
475470 var base = this . active . offset ( ) . top ,
476471 height = this . element . height ( ) ,
477472 result ;
@@ -488,15 +483,14 @@ $.widget( "ui.menu", {
488483 } ,
489484
490485 previousPage : function ( event ) {
486+ if ( ! this . active ) {
487+ this . focus ( event , this . activeMenu . children ( ".ui-menu-item" ) . first ( ) ) ;
488+ return ;
489+ }
490+ if ( this . first ( ) ) {
491+ return ;
492+ }
491493 if ( this . _hasScroll ( ) ) {
492- if ( ! this . active ) {
493- this . focus ( event , this . activeMenu . children ( ".ui-menu-item" ) . first ( ) ) ;
494- return ;
495- }
496- if ( this . first ( ) ) {
497- return ;
498- }
499-
500494 var base = this . active . offset ( ) . top ,
501495 height = this . element . height ( ) ,
502496 result ;
@@ -512,7 +506,7 @@ $.widget( "ui.menu", {
512506 } ,
513507
514508 _hasScroll : function ( ) {
515- return this . element . height ( ) < this . element . prop ( "scrollHeight" ) ;
509+ return this . element . outerHeight ( ) < this . element . prop ( "scrollHeight" ) ;
516510 } ,
517511
518512 select : function ( event ) {
0 commit comments