@@ -54,14 +54,13 @@ $.widget( "ui.menu", {
54
54
} ,
55
55
"click .ui-menu-item:has(a)" : function ( event ) {
56
56
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
- }
62
57
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 ) ;
65
64
} ,
66
65
"mouseover .ui-menu-item" : function ( event ) {
67
66
event . stopImmediatePropagation ( ) ;
@@ -72,9 +71,21 @@ $.widget( "ui.menu", {
72
71
} ,
73
72
"mouseleave" : "collapseAll" ,
74
73
"mouseleave .ui-menu" : "collapseAll" ,
75
- "mouseout .ui-menu-item" : "blur" ,
76
74
"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 ) ;
78
89
} ,
79
90
blur : function ( event ) {
80
91
this . _delay ( function ( ) {
@@ -283,21 +294,6 @@ $.widget( "ui.menu", {
283
294
focus : function ( event , item ) {
284
295
this . blur ( event ) ;
285
296
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
-
301
297
this . active = item . first ( )
302
298
. children ( "a" )
303
299
. addClass ( "ui-state-focus" )
@@ -463,15 +459,14 @@ $.widget( "ui.menu", {
463
459
} ,
464
460
465
461
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
+ }
466
469
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
-
475
470
var base = this . active . offset ( ) . top ,
476
471
height = this . element . height ( ) ,
477
472
result ;
@@ -488,15 +483,14 @@ $.widget( "ui.menu", {
488
483
} ,
489
484
490
485
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
+ }
491
493
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
-
500
494
var base = this . active . offset ( ) . top ,
501
495
height = this . element . height ( ) ,
502
496
result ;
@@ -512,7 +506,7 @@ $.widget( "ui.menu", {
512
506
} ,
513
507
514
508
_hasScroll : function ( ) {
515
- return this . element . height ( ) < this . element . prop ( "scrollHeight" ) ;
509
+ return this . element . outerHeight ( ) < this . element . prop ( "scrollHeight" ) ;
516
510
} ,
517
511
518
512
select : function ( event ) {
0 commit comments