Skip to content

Commit 80811fc

Browse files
committed
MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish
1 parent c8c6aaf commit 80811fc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lib/web/mage/menu.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ define([
5959
}
6060

6161
this._assignControls()._listen();
62+
63+
this._setActiveMenu();
6264
},
6365

6466
/**
@@ -108,6 +110,49 @@ define([
108110
}
109111
},
110112

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+
111156
/**
112157
* Add class for expanded option.
113158
*/

0 commit comments

Comments
 (0)