Skip to content

Commit cbc1c25

Browse files
author
Bogdan Plieshka
committed
MAGETWO-34929: JS: Smart fixed scroll
- Added submenus scroll for low height window cases
1 parent a2b10f6 commit cbc1c25

File tree

2 files changed

+41
-14
lines changed
  • app/design/adminhtml/Magento/backend

2 files changed

+41
-14
lines changed

app/design/adminhtml/Magento/backend/Magento_Backend/web/css/source/module/_menu.less

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
// ---------------------------------------------
125125

126126
.admin__menu {
127-
position: relative;
128127
li {
129128
display: block;
130129
}
@@ -204,12 +203,19 @@
204203
min-height: ~'calc(@{menu-logo__outer-size} + 2rem + 100%)';
205204
padding: @submenu__padding-vertical 0 0;
206205
position: absolute;
207-
top: -@menu-logo__outer-size;
206+
top: 0;
208207
transition-duration: .5s;
209208
transition-property: left, visibility;
210209
transition-timing-function: ease;
211210
visibility: hidden;
212211
z-index: @submenu__z-index;
212+
&._overlap {
213+
overflow-y: auto;
214+
height: 100%;
215+
&::-webkit-scrollbar {
216+
width: 0;
217+
}
218+
}
213219
}
214220
&._show {
215221
> .submenu {

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ define('globalNavigationScroll', [
99
'use strict';
1010

1111
var win = $(window),
12+
subMenuClass = '.submenu',
13+
overlapClassName = '_overlap',
14+
fixedClassName = '_fixed',
1215
menu = $('.menu-wrapper'),
1316
content = $('.page-wrapper'),
17+
menuItems = $('#nav').children('li'),
18+
subMenus = menuItems.children(subMenuClass),
1419
winHeight,
1520
menuHeight = menu.height(),
1621
menuHeightRest = 0,
1722
menuScrollMax = 0,
23+
submenuHeight = 0,
1824
contentHeight,
1925
winTop = 0,
2026
winTopLast = 0,
2127
scrollStep = 0,
22-
nextTop = 0,
23-
fixedClass = '_fixed';
28+
nextTop = 0;
2429

2530
/**
2631
* Check if menu is fixed
@@ -31,22 +36,24 @@ define('globalNavigationScroll', [
3136
}
3237

3338
/**
34-
* Add fixed menu class
39+
* Check if class exist than add or do nothing
3540
* @param {jQuery} el
41+
* @param $class string
3642
*/
37-
function addFixed(el) {
38-
if (!el.hasClass(fixedClass)) {
39-
el.addClass(fixedClass);
43+
function checkAddClass(el, $class) {
44+
if (!el.hasClass($class)) {
45+
el.addClass($class);
4046
}
4147
}
4248

4349
/**
44-
* Remove fixed menu class
50+
* Check if class exist than remove or do nothing
4551
* @param {jQuery} el
52+
* @param $class string
4653
*/
47-
function removeFixed(el) {
48-
if (el.hasClass(fixedClass)) {
49-
el.removeClass(fixedClass);
54+
function checkRemoveClass(el, $class) {
55+
if (el.hasClass($class)) {
56+
el.removeClass($class);
5057
}
5158
}
5259

@@ -64,7 +71,7 @@ define('globalNavigationScroll', [
6471

6572
if (isMenuFixed()) { // fixed menu cases
6673

67-
addFixed(menu);
74+
checkAddClass(menu, fixedClassName);
6875

6976
if (menuHeight > winHeight) { // smart scroll cases
7077

@@ -89,7 +96,7 @@ define('globalNavigationScroll', [
8996
}
9097

9198
} else { // static menu cases
92-
removeFixed(menu);
99+
checkRemoveClass(menu, fixedClassName);
93100
}
94101

95102
// Save previous window scrollTop
@@ -111,10 +118,24 @@ define('globalNavigationScroll', [
111118
// Reset position if fixed and out of smart scroll
112119
if ((menuHeight < contentHeight) && (menuHeight <= winHeight)) {
113120
menu.removeAttr('style');
121+
// Remove overlap classes from submenus and clear overlap adding event
122+
subMenus.removeClass(overlapClassName);
123+
menuItems.off();
114124
}
115125

116126
});
117127

128+
// Add event to menuItems to check submenu overlap
129+
menuItems.on('click', function () {
130+
131+
var submenu = $(this).children(subMenuClass);
132+
submenuHeight = submenu.height();
133+
134+
if (isMenuFixed() && (submenuHeight > winHeight)) {
135+
checkAddClass(submenu, overlapClassName);
136+
}
137+
});
138+
118139
});
119140

120141
define('globalNavigation', [

0 commit comments

Comments
 (0)