Skip to content

Commit 2f09a91

Browse files
author
Mykhailo Miroshnikov
committed
MAGETWO-34476: Backend Menu JS improvements
- Migrate menu interactions to clicks rather than hover - Add close button handler - Add overlay to close submenu
1 parent 6c56801 commit 2f09a91

File tree

1 file changed

+56
-59
lines changed
  • app/design/adminhtml/Magento/backend/web/js

1 file changed

+56
-59
lines changed

app/design/adminhtml/Magento/backend/web/js/theme.js

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,50 @@ define('globalNavigation', [
1919
interval: 100,
2020
timeout: 500 // number = milliseconds delay before onMouseOut
2121
},
22+
overlayClass: 'admin__menu-overlay',
2223
categoriesConfig: {
23-
'[data-ui-id="menu-mage-adminhtml-system"]': {
24-
open: 'click'
25-
},
26-
'[data-ui-id="menu-mage-adminhtml-stores"]': {
24+
'li': {
2725
open: 'click'
2826
}
2927
}
3028
},
3129

3230
_create: function () {
33-
this.menu = this.element;
34-
this.menuCategory = $(this.options.menuCategory, this.menu);
35-
this.menuLinks = $(this.options.menuLinks, this.menuCategory);
31+
this.menu = this.element;
32+
this.menuCategory = $(this.options.menuCategory, this.menu);
33+
this.menuLinks = $(this.options.menuLinks, this.menuCategory);
34+
35+
this._addOverlay();
36+
3637
this._bind();
3738
},
3839

40+
_addOverlay: function () {
41+
var wrapper = $('<div />').addClass('admin__scope');
42+
43+
this.overlay = $('<div />')
44+
.addClass(this.options.overlayClass)
45+
.appendTo('body')
46+
.hide(0);
47+
48+
/**
49+
* @todo fix LESS and remove next line and wrapper definition
50+
*/
51+
this.overlay.wrap(wrapper);
52+
},
53+
3954
_menuCategoryBind: function (category, config) {
40-
category
41-
.hoverIntent($.extend({}, this.options.hoverIntentConfig, {
42-
over: !config.open ? this._hoverEffects : $.noop,
43-
out: !config.close ? this._leaveEffects : $.noop
44-
}));
45-
46-
if (config.open) {
47-
category.on(config.open, this._hoverEffects);
48-
}
55+
var open = this._open.bind(this);
4956

50-
if (config.close) {
51-
category.on(config.close, this._leaveEffects);
57+
if (config.open) {
58+
$('> a', category).on(config.open, open);
5259
}
5360
},
5461

5562
_menuCategoryEvents: function () {
5663
this.menuCategory.each($.proxy(function (i, category) {
5764
var itemConfig = {};
65+
5866
if (this.options.categoriesConfig) {
5967
$.each(this.options.categoriesConfig, $.proxy(function (selector, conf) {
6068
if ($(category).is(selector)) {
@@ -77,61 +85,50 @@ define('globalNavigation', [
7785
});
7886
},
7987

80-
_hoverEffects: function (e) {
88+
_open: function (e) {
89+
var menuItem = $(e.target).closest('.level-0'),
90+
subMenu = $('> .submenu', menuItem);
8191

82-
// Disable current active class while hover is on level 0
83-
$(this).siblings('._active').addClass('_current').removeClass('_active');
92+
e.preventDefault();
8493

85-
$(this)
94+
menuItem
8695
.addClass('_hover _recent')
87-
.siblings('.level-0').each(function () {
88-
clearTimeout($(this).prop('hoverIntent_t'));
89-
$(this).prop('hoverIntent_s', 0);
90-
$(this).removeClass('_recent _hover');
91-
});
92-
93-
var targetSubmenu = $(e.target).closest('.submenu');
94-
if (targetSubmenu.length && targetSubmenu.is(':visible')) {
95-
return;
96-
}
97-
var availableWidth = parseInt($(this).parent().css('width')) - $(this).position().left,
98-
submenu = $('> .submenu', this),
99-
colsWidth = 0;
100-
101-
submenu.addClass('_show');
96+
.siblings('._active')
97+
.addClass('_current')
98+
.removeClass('_active');
10299

103-
$.each($('> .submenu > ul li.column', this), function () {
104-
colsWidth = colsWidth + parseInt($(this).css('width'));
105-
});
100+
menuItem
101+
.siblings('.level-0')
102+
.removeClass('_hover _recent');
106103

107-
var containerPaddings = parseInt(submenu.css('padding-left')) + parseInt(submenu.css('padding-right'));
104+
subMenu
105+
.attr('aria-expanded', 'true');
108106

109-
$(this).toggleClass('reverse', (containerPaddings + colsWidth) > availableWidth);
107+
subMenu.find('button._close').on('click', this._close.bind(this));
110108

111-
submenu.removeClass('_show');
109+
this.overlay
110+
.on('click', this._close.bind(this))
111+
.show(0);
112112
},
113113

114-
_leaveEffects: function (e) {
114+
_close: function (e) {
115+
var navigation = this.element,
116+
menuItem = $('.level-0._hover', navigation),
117+
subMenu = $('> submenu', menuItem);
115118

116-
// Disable current active class while hover is on level 0
117-
$(this).siblings('._current').addClass('_active').removeClass('_current');
119+
e.preventDefault();
118120

119-
var targetSubmenu = $(e.target).closest('.submenu'),
120-
self = $(this),
121-
submenu = $('> .submenu', this);
121+
this.overlay.off('click').hide(0);
122122

123-
if (targetSubmenu.length && targetSubmenu.is(':hidden')) {
124-
return;
125-
}
123+
subMenu.find('button._close').off('click');
126124

127-
if (submenu.length) {
128-
submenu.removeClass('_show', function () {
129-
self.removeClass('_hover');
130-
});
131-
} else {
132-
self.removeClass('_hover');
133-
}
125+
menuItem.addClass('_active').removeClass('_current');
126+
127+
subMenu
128+
.removeClass('_show')
129+
.attr('aria-expanded', 'false');
134130

131+
menuItem.removeClass('_hover _active');
135132
}
136133
});
137134

0 commit comments

Comments
 (0)