@@ -59,6 +59,8 @@ define([
59
59
}
60
60
61
61
this . _assignControls ( ) . _listen ( ) ;
62
+
63
+ this . _setActiveMenu ( ) ;
62
64
} ,
63
65
64
66
/**
@@ -108,6 +110,49 @@ define([
108
110
}
109
111
} ,
110
112
113
+ /**
114
+ * Sets 'active' CSS class to menu item for active category if it was not set before.
115
+ * If menu item has parent categories, sets 'has-active' class to all af them
116
+ *
117
+ * @private
118
+ *
119
+ * @return void
120
+ */
121
+ _setActiveMenu : function ( ) {
122
+ var currentUrl = window . location . href . split ( '?' ) [ 0 ] ,
123
+ activeCategoryLink = this . element . find ( 'a[href="' + currentUrl + '"]' ) ;
124
+
125
+ if ( activeCategoryLink && activeCategoryLink . parent ( ) . hasClass ( 'active' ) !== true
126
+ && activeCategoryLink . hasClass ( 'ui-corner-all' )
127
+ ) {
128
+ activeCategoryLink . parent ( ) . addClass ( 'active' ) ;
129
+ var classes = activeCategoryLink . parent ( ) . attr ( 'class' ) ,
130
+ classStartPosition = classes . indexOf ( 'nav-' ) ,
131
+ classNav = classes . substring ( classStartPosition , classes . indexOf ( ' ' , classStartPosition ) ) ;
132
+
133
+ this . _setActiveParent ( classNav ) ;
134
+ }
135
+ } ,
136
+
137
+ /**
138
+ * Sets 'has-active' CSS class to all parent categories in menu has active category
139
+ *
140
+ * @private
141
+ *
142
+ * @param {String } childClassName - Class name of active category <li> element
143
+ * @return void
144
+ */
145
+ _setActiveParent : function ( childClassName ) {
146
+ var parentClass = childClassName . substr ( 0 , childClassName . lastIndexOf ( '-' ) ) ;
147
+ if ( parentClass . lastIndexOf ( '-' ) !== - 1 ) {
148
+ var parent = this . element . find ( '.' + parentClass ) ;
149
+ if ( parent ) {
150
+ parent . addClass ( 'has-active' ) ;
151
+ }
152
+ this . _setActiveParent ( parentClass ) ;
153
+ }
154
+ } ,
155
+
111
156
/**
112
157
* Add class for expanded option.
113
158
*/
0 commit comments