@@ -333,23 +333,26 @@ define([
333
333
}
334
334
} ,
335
335
"mouseenter .ui-menu-item" : function ( event ) {
336
- var target = $ ( event . currentTarget ) ,
337
- ulWidth = target . find ( 'ul' ) . get ( 0 ) ? target . find ( 'ul' ) . get ( 0 ) . getBoundingClientRect ( ) . width : null ,
338
- rightThreshold = ulWidth * 2 ,
339
- leftThreshold = ( event . pageX + rightThreshold ) ,
340
- clientWindowWidth = $ ( window ) . width ( ) ;
336
+ var target = $ ( event . currentTarget ) ;
337
+
338
+ if ( target . has ( 'ul' ) ) {
339
+ var ulElement = target . find ( 'ul' ) ,
340
+ ulElementWidth = target . find ( 'ul' ) . outerWidth ( true ) ,
341
+ width = target . outerWidth ( ) * 2 ,
342
+ targetPageX = target . offset ( ) . left ,
343
+ rightBound = screen . width ;
344
+
345
+ if ( ( ulElementWidth + width + targetPageX ) > rightBound ) {
346
+ ulElement . addClass ( 'submenu-reverse' ) ;
347
+ }
348
+ if ( targetPageX - ulElementWidth < 0 ) {
349
+ ulElement . removeClass ( 'submenu-reverse' ) ;
350
+ }
351
+ }
341
352
342
353
// Remove ui-state-active class from siblings of the newly focused menu item
343
354
// to avoid a jump caused by adjacent elements both having a class with a border
344
355
target . siblings ( ) . children ( ".ui-state-active" ) . removeClass ( "ui-state-active" ) ;
345
- //reverse sub-menus direction from left to right bounds
346
- if ( leftThreshold > clientWindowWidth ) {
347
- target . find ( 'ul' ) . addClass ( 'submenu-reverse' ) ;
348
- }
349
- //redirect reverse
350
- if ( event . pageX <= rightThreshold ) {
351
- target . find ( 'ul' ) . removeClass ( 'submenu-reverse' ) ;
352
- }
353
356
this . focus ( event , target ) ;
354
357
} ,
355
358
"mouseleave" : function ( event ) {
@@ -370,12 +373,13 @@ define([
370
373
} , 300 ) ;
371
374
}
372
375
} ,
373
-
374
- _delay : function ( handler , delay ) {
375
- handler . apply ( this , arguments ) ;
376
-
377
- return setTimeout ( function ( ) {
378
- } , delay || 0 ) ;
376
+ _delay : function ( handler , delay ) {
377
+ function handlerProxy ( ) {
378
+ return ( typeof handler === "string" ? instance [ handler ] : handler )
379
+ . apply ( instance , arguments ) ;
380
+ }
381
+ var instance = this ;
382
+ return setTimeout ( handlerProxy , delay || 0 ) ;
379
383
}
380
384
} ) ;
381
385
0 commit comments