@@ -9,18 +9,23 @@ define('globalNavigationScroll', [
9
9
'use strict' ;
10
10
11
11
var win = $ ( window ) ,
12
+ subMenuClass = '.submenu' ,
13
+ overlapClassName = '_overlap' ,
14
+ fixedClassName = '_fixed' ,
12
15
menu = $ ( '.menu-wrapper' ) ,
13
16
content = $ ( '.page-wrapper' ) ,
17
+ menuItems = $ ( '#nav' ) . children ( 'li' ) ,
18
+ subMenus = menuItems . children ( subMenuClass ) ,
14
19
winHeight ,
15
20
menuHeight = menu . height ( ) ,
16
21
menuHeightRest = 0 ,
17
22
menuScrollMax = 0 ,
23
+ submenuHeight = 0 ,
18
24
contentHeight ,
19
25
winTop = 0 ,
20
26
winTopLast = 0 ,
21
27
scrollStep = 0 ,
22
- nextTop = 0 ,
23
- fixedClass = '_fixed' ;
28
+ nextTop = 0 ;
24
29
25
30
/**
26
31
* Check if menu is fixed
@@ -31,22 +36,24 @@ define('globalNavigationScroll', [
31
36
}
32
37
33
38
/**
34
- * Add fixed menu class
39
+ * Check if class exist than add or do nothing
35
40
* @param {jQuery } el
41
+ * @param $class string
36
42
*/
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 ) ;
40
46
}
41
47
}
42
48
43
49
/**
44
- * Remove fixed menu class
50
+ * Check if class exist than remove or do nothing
45
51
* @param {jQuery } el
52
+ * @param $class string
46
53
*/
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 ) ;
50
57
}
51
58
}
52
59
@@ -64,7 +71,7 @@ define('globalNavigationScroll', [
64
71
65
72
if ( isMenuFixed ( ) ) { // fixed menu cases
66
73
67
- addFixed ( menu ) ;
74
+ checkAddClass ( menu , fixedClassName ) ;
68
75
69
76
if ( menuHeight > winHeight ) { // smart scroll cases
70
77
@@ -89,7 +96,7 @@ define('globalNavigationScroll', [
89
96
}
90
97
91
98
} else { // static menu cases
92
- removeFixed ( menu ) ;
99
+ checkRemoveClass ( menu , fixedClassName ) ;
93
100
}
94
101
95
102
// Save previous window scrollTop
@@ -111,10 +118,24 @@ define('globalNavigationScroll', [
111
118
// Reset position if fixed and out of smart scroll
112
119
if ( ( menuHeight < contentHeight ) && ( menuHeight <= winHeight ) ) {
113
120
menu . removeAttr ( 'style' ) ;
121
+ // Remove overlap classes from submenus and clear overlap adding event
122
+ subMenus . removeClass ( overlapClassName ) ;
123
+ menuItems . off ( ) ;
114
124
}
115
125
116
126
} ) ;
117
127
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
+
118
139
} ) ;
119
140
120
141
define ( 'globalNavigation' , [
0 commit comments