Skip to content

Commit 15c586a

Browse files
committed
MAGETWO-49796: Catalog top nav, CSS class not set to active when using Varnish
- fix code style errors
1 parent 4d9be10 commit 15c586a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/web/mage/menu.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,35 @@ define([
134134
* If menu item has parent categories, sets 'has-active' class to all af them.
135135
*
136136
* @param {String} url - possible category URL
137-
* @returns {boolean} - true if active category was founded by provided URL, otherwise return false
137+
* @returns {Boolean} - true if active category was founded by provided URL, otherwise return false
138138
* @private
139139
*/
140140
_setActiveMenuForCategory: function (url) {
141141
var activeCategoryLink = this.element.find('a[href="' + url + '"]'),
142142
classes,
143143
classNav;
144144

145-
if (activeCategoryLink && activeCategoryLink.hasClass('ui-corner-all')) {
145+
if (!activeCategoryLink || !activeCategoryLink.hasClass('ui-corner-all')) {
146146

147-
if (!activeCategoryLink.parent().hasClass('active')) {
148-
activeCategoryLink.parent().addClass('active');
149-
classes = activeCategoryLink.parent().attr('class');
150-
classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi);
147+
//category was not found by provided URL
148+
return false;
149+
} else if (!activeCategoryLink.parent().hasClass('active')) {
150+
activeCategoryLink.parent().addClass('active');
151+
classes = activeCategoryLink.parent().attr('class');
152+
classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi);
151153

152-
if (classNav) {
153-
this._setActiveParent(classNav[0]);
154-
}
154+
if (classNav) {
155+
this._setActiveParent(classNav[0]);
155156
}
156-
return true;
157157
}
158-
return false;
158+
159+
return true;
159160
},
160161

161162
/**
162163
* Sets 'has-active' CSS class to all parent categories which have part of provided class in childClassName
163164
*
164-
* @example:
165+
* @example
165166
* childClassName - 'nav-1-2-3'
166167
* CSS class 'has-active' will be added to categories have 'nav-1-2' and 'nav-1' classes
167168
*
@@ -187,7 +188,7 @@ define([
187188
* Tries to retrieve category URL from current URL and mark this category as active
188189
* @see _setActiveMenuForCategory(url)
189190
*
190-
* @example:
191+
* @example
191192
* currentUrl - http://magento.com/category1/category12/product.html,
192193
* category URLs has extensions .phtml - http://magento.com/category1.phtml
193194
* method sets active category which has URL http://magento.com/category1/category12.phtml

0 commit comments

Comments
 (0)