@@ -311,23 +311,10 @@ $.widget( "ui.menu", {
311
311
} ,
312
312
313
313
focus : function ( event , item ) {
314
- var nested , borderTop , paddingTop , offset , scroll , elementHeight , itemHeight , focused ;
314
+ var nested , focused ;
315
315
this . blur ( event , event && event . type === "focus" ) ;
316
316
317
- if ( this . _hasScroll ( ) ) {
318
- borderTop = parseFloat ( $ . css ( this . activeMenu [ 0 ] , "borderTopWidth" ) ) || 0 ;
319
- paddingTop = parseFloat ( $ . css ( this . activeMenu [ 0 ] , "paddingTop" ) ) || 0 ;
320
- offset = item . offset ( ) . top - this . activeMenu . offset ( ) . top - borderTop - paddingTop ;
321
- scroll = this . activeMenu . scrollTop ( ) ;
322
- elementHeight = this . activeMenu . height ( ) ;
323
- itemHeight = item . height ( ) ;
324
-
325
- if ( offset < 0 ) {
326
- this . activeMenu . scrollTop ( scroll + offset ) ;
327
- } else if ( offset + itemHeight > elementHeight ) {
328
- this . activeMenu . scrollTop ( scroll + offset - elementHeight + itemHeight ) ;
329
- }
330
- }
317
+ this . _scrollIntoView ( item ) ;
331
318
332
319
this . active = item . first ( ) ;
333
320
focused = this . active . children ( "a" ) . addClass ( "ui-state-focus" ) ;
@@ -357,6 +344,24 @@ $.widget( "ui.menu", {
357
344
this . _trigger ( "focus" , event , { item : item } ) ;
358
345
} ,
359
346
347
+ _scrollIntoView : function ( item ) {
348
+ var borderTop , paddingTop , offset , scroll , elementHeight , itemHeight ;
349
+ if ( this . _hasScroll ( ) ) {
350
+ borderTop = parseFloat ( $ . css ( this . activeMenu [ 0 ] , "borderTopWidth" ) ) || 0 ;
351
+ paddingTop = parseFloat ( $ . css ( this . activeMenu [ 0 ] , "paddingTop" ) ) || 0 ;
352
+ offset = item . offset ( ) . top - this . activeMenu . offset ( ) . top - borderTop - paddingTop ;
353
+ scroll = this . activeMenu . scrollTop ( ) ;
354
+ elementHeight = this . activeMenu . height ( ) ;
355
+ itemHeight = item . height ( ) ;
356
+
357
+ if ( offset < 0 ) {
358
+ this . activeMenu . scrollTop ( scroll + offset ) ;
359
+ } else if ( offset + itemHeight > elementHeight ) {
360
+ this . activeMenu . scrollTop ( scroll + offset - elementHeight + itemHeight ) ;
361
+ }
362
+ }
363
+ } ,
364
+
360
365
blur : function ( event , fromFocus ) {
361
366
if ( ! fromFocus ) {
362
367
clearTimeout ( this . timer ) ;
0 commit comments