Skip to content

Commit 3960c42

Browse files
author
Ihor Melnychenko
committed
MAGETWO-27300: Category menu items go out of screen when page side is reached
- fixed delay function and improved sub-menu reverse
1 parent 9eb9317 commit 3960c42

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lib/web/css/source/lib/_navigation.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@
329329
margin: 0 !important;
330330
position: absolute;
331331
left: 0;
332-
top: 100%;
333332
z-index: 1;
334333
.css(background, @_submenu-background-color);
335334
.css(border, @_submenu-border-width @_submenu-border-style @_submenu-border-color);

lib/web/mage/menu.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,23 +333,26 @@ define([
333333
}
334334
},
335335
"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+
}
341352

342353
// Remove ui-state-active class from siblings of the newly focused menu item
343354
// to avoid a jump caused by adjacent elements both having a class with a border
344355
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-
}
353356
this.focus(event, target);
354357
},
355358
"mouseleave": function (event) {
@@ -370,12 +373,13 @@ define([
370373
}, 300);
371374
}
372375
},
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 );
379383
}
380384
});
381385

0 commit comments

Comments
 (0)