@@ -19,42 +19,50 @@ define('globalNavigation', [
19
19
interval : 100 ,
20
20
timeout : 500 // number = milliseconds delay before onMouseOut
21
21
} ,
22
+ overlayClass : 'admin__menu-overlay' ,
22
23
categoriesConfig : {
23
- '[data-ui-id="menu-mage-adminhtml-system"]' : {
24
- open : 'click'
25
- } ,
26
- '[data-ui-id="menu-mage-adminhtml-stores"]' : {
24
+ 'li' : {
27
25
open : 'click'
28
26
}
29
27
}
30
28
} ,
31
29
32
30
_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
+
36
37
this . _bind ( ) ;
37
38
} ,
38
39
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
+
39
54
_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 ) ;
49
56
50
- if ( config . close ) {
51
- category . on ( config . close , this . _leaveEffects ) ;
57
+ if ( config . open ) {
58
+ $ ( '> a' , category ) . on ( config . open , open ) ;
52
59
}
53
60
} ,
54
61
55
62
_menuCategoryEvents : function ( ) {
56
63
this . menuCategory . each ( $ . proxy ( function ( i , category ) {
57
64
var itemConfig = { } ;
65
+
58
66
if ( this . options . categoriesConfig ) {
59
67
$ . each ( this . options . categoriesConfig , $ . proxy ( function ( selector , conf ) {
60
68
if ( $ ( category ) . is ( selector ) ) {
@@ -77,61 +85,50 @@ define('globalNavigation', [
77
85
} ) ;
78
86
} ,
79
87
80
- _hoverEffects : function ( e ) {
88
+ _open : function ( e ) {
89
+ var menuItem = $ ( e . target ) . closest ( '.level-0' ) ,
90
+ subMenu = $ ( '> .submenu' , menuItem ) ;
81
91
82
- // Disable current active class while hover is on level 0
83
- $ ( this ) . siblings ( '._active' ) . addClass ( '_current' ) . removeClass ( '_active' ) ;
92
+ e . preventDefault ( ) ;
84
93
85
- $ ( this )
94
+ menuItem
86
95
. 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' ) ;
102
99
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' ) ;
106
103
107
- var containerPaddings = parseInt ( submenu . css ( 'padding-left' ) ) + parseInt ( submenu . css ( 'padding-right' ) ) ;
104
+ subMenu
105
+ . attr ( 'aria-expanded' , 'true' ) ;
108
106
109
- $ ( this ) . toggleClass ( 'reverse ', ( containerPaddings + colsWidth ) > availableWidth ) ;
107
+ subMenu . find ( 'button._close' ) . on ( 'click ', this . _close . bind ( this ) ) ;
110
108
111
- submenu . removeClass ( '_show' ) ;
109
+ this . overlay
110
+ . on ( 'click' , this . _close . bind ( this ) )
111
+ . show ( 0 ) ;
112
112
} ,
113
113
114
- _leaveEffects : function ( e ) {
114
+ _close : function ( e ) {
115
+ var navigation = this . element ,
116
+ menuItem = $ ( '.level-0._hover' , navigation ) ,
117
+ subMenu = $ ( '> submenu' , menuItem ) ;
115
118
116
- // Disable current active class while hover is on level 0
117
- $ ( this ) . siblings ( '._current' ) . addClass ( '_active' ) . removeClass ( '_current' ) ;
119
+ e . preventDefault ( ) ;
118
120
119
- var targetSubmenu = $ ( e . target ) . closest ( '.submenu' ) ,
120
- self = $ ( this ) ,
121
- submenu = $ ( '> .submenu' , this ) ;
121
+ this . overlay . off ( 'click' ) . hide ( 0 ) ;
122
122
123
- if ( targetSubmenu . length && targetSubmenu . is ( ':hidden' ) ) {
124
- return ;
125
- }
123
+ subMenu . find ( 'button._close' ) . off ( 'click' ) ;
126
124
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' ) ;
134
130
131
+ menuItem . removeClass ( '_hover _active' ) ;
135
132
}
136
133
} ) ;
137
134
0 commit comments