menu.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'matchMedia',
  8. 'jquery/ui',
  9. 'jquery/jquery.mobile.custom',
  10. 'mage/translate'
  11. ], function ($, mediaCheck) {
  12. 'use strict';
  13. /**
  14. * Menu Widget - this widget is a wrapper for the jQuery UI Menu
  15. */
  16. $.widget('mage.menu', $.ui.menu, {
  17. options: {
  18. responsive: false,
  19. expanded: false,
  20. showDelay: 42,
  21. hideDelay: 300,
  22. delay: 0,
  23. mediaBreakpoint: '(max-width: 768px)'
  24. },
  25. /**
  26. * @private
  27. */
  28. _create: function () {
  29. var self = this;
  30. this.delay = this.options.delay;
  31. this._super();
  32. $(window).on('resize', function () {
  33. self.element.find('.submenu-reverse').removeClass('submenu-reverse');
  34. });
  35. },
  36. /**
  37. * @private
  38. */
  39. _init: function () {
  40. this._super();
  41. if (this.options.expanded === true) {
  42. this.isExpanded();
  43. }
  44. if (this.options.responsive === true) {
  45. mediaCheck({
  46. media: this.options.mediaBreakpoint,
  47. entry: $.proxy(function () {
  48. this._toggleMobileMode();
  49. }, this),
  50. exit: $.proxy(function () {
  51. this._toggleDesktopMode();
  52. }, this)
  53. });
  54. }
  55. this._assignControls()._listen();
  56. this._setActiveMenu();
  57. },
  58. /**
  59. * @return {Object}
  60. * @private
  61. */
  62. _assignControls: function () {
  63. this.controls = {
  64. toggleBtn: $('[data-action="toggle-nav"]'),
  65. swipeArea: $('.nav-sections')
  66. };
  67. return this;
  68. },
  69. /**
  70. * @private
  71. */
  72. _listen: function () {
  73. var controls = this.controls,
  74. toggle = this.toggle;
  75. controls.toggleBtn.off('click');
  76. controls.toggleBtn.on('click', toggle.bind(this));
  77. controls.swipeArea.off('swipeleft');
  78. controls.swipeArea.on('swipeleft', toggle.bind(this));
  79. },
  80. /**
  81. * Toggle.
  82. */
  83. toggle: function () {
  84. var html = $('html');
  85. if (html.hasClass('nav-open')) {
  86. html.removeClass('nav-open');
  87. setTimeout(function () {
  88. html.removeClass('nav-before-open');
  89. }, this.options.hideDelay);
  90. } else {
  91. html.addClass('nav-before-open');
  92. setTimeout(function () {
  93. html.addClass('nav-open');
  94. }, this.options.showDelay);
  95. }
  96. },
  97. /**
  98. * Tries to figure out the active category for current page and add appropriate classes:
  99. * - 'active' class for active category
  100. * - 'has-active' class for all parents of active category
  101. *
  102. * First, checks whether current URL is URL of category page,
  103. * otherwise tries to retrieve category URL in case of current URL is product view page URL
  104. * which has category tree path in it.
  105. *
  106. * @return void
  107. * @private
  108. */
  109. _setActiveMenu: function () {
  110. var currentUrl = window.location.href.split('?')[0];
  111. if (!this._setActiveMenuForCategory(currentUrl)) {
  112. this._setActiveMenuForProduct(currentUrl);
  113. }
  114. },
  115. /**
  116. * Looks for category with provided URL and adds 'active' CSS class to it if it was not set before.
  117. * If menu item has parent categories, sets 'has-active' class to all af them.
  118. *
  119. * @param {String} url - possible category URL
  120. * @returns {Boolean} - true if active category was founded by provided URL, otherwise return false
  121. * @private
  122. */
  123. _setActiveMenuForCategory: function (url) {
  124. var activeCategoryLink = this.element.find('a[href="' + url + '"]'),
  125. classes,
  126. classNav;
  127. if (!activeCategoryLink || !activeCategoryLink.hasClass('ui-corner-all')) {
  128. //category was not found by provided URL
  129. return false;
  130. } else if (!activeCategoryLink.parent().hasClass('active')) {
  131. activeCategoryLink.parent().addClass('active');
  132. classes = activeCategoryLink.parent().attr('class');
  133. classNav = classes.match(/(nav\-)[0-9]+(\-[0-9]+)+/gi);
  134. if (classNav) {
  135. this._setActiveParent(classNav[0]);
  136. }
  137. }
  138. return true;
  139. },
  140. /**
  141. * Sets 'has-active' CSS class to all parent categories which have part of provided class in childClassName
  142. *
  143. * @example
  144. * childClassName - 'nav-1-2-3'
  145. * CSS class 'has-active' will be added to categories have 'nav-1-2' and 'nav-1' classes
  146. *
  147. * @param {String} childClassName - Class name of active category <li> element
  148. * @return void
  149. * @private
  150. */
  151. _setActiveParent: function (childClassName) {
  152. var parentElement,
  153. parentClass = childClassName.substr(0, childClassName.lastIndexOf('-'));
  154. if (parentClass.lastIndexOf('-') !== -1) {
  155. parentElement = this.element.find('.' + parentClass);
  156. if (parentElement) {
  157. parentElement.addClass('has-active');
  158. }
  159. this._setActiveParent(parentClass);
  160. }
  161. },
  162. /**
  163. * Tries to retrieve category URL from current URL and mark this category as active
  164. * @see _setActiveMenuForCategory(url)
  165. *
  166. * @example
  167. * currentUrl - http://magento.com/category1/category12/product.html,
  168. * category URLs has extensions .phtml - http://magento.com/category1.phtml
  169. * method sets active category which has URL http://magento.com/category1/category12.phtml
  170. *
  171. * @param {String} currentUrl - current page URL without parameters
  172. * @return void
  173. * @private
  174. */
  175. _setActiveMenuForProduct: function (currentUrl) {
  176. var categoryUrlExtension,
  177. lastUrlSection,
  178. possibleCategoryUrl,
  179. //retrieve first category URL to know what extension is used for category URLs
  180. firstCategoryUrl = this.element.find('> li a').attr('href');
  181. if (firstCategoryUrl) {
  182. lastUrlSection = firstCategoryUrl.substr(firstCategoryUrl.lastIndexOf('/'));
  183. categoryUrlExtension = lastUrlSection.lastIndexOf('.') !== -1 ?
  184. lastUrlSection.substr(lastUrlSection.lastIndexOf('.')) : '';
  185. possibleCategoryUrl = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + categoryUrlExtension;
  186. this._setActiveMenuForCategory(possibleCategoryUrl);
  187. }
  188. },
  189. /**
  190. * Add class for expanded option.
  191. */
  192. isExpanded: function () {
  193. var subMenus = this.element.find(this.options.menus),
  194. expandedMenus = subMenus.find(this.options.menus);
  195. expandedMenus.addClass('expanded');
  196. },
  197. /**
  198. * @param {jQuery.Event} event
  199. * @private
  200. */
  201. _activate: function (event) {
  202. window.location.href = this.active.find('> a').attr('href');
  203. this.collapseAll(event);
  204. },
  205. /**
  206. * @param {jQuery.Event} event
  207. * @private
  208. */
  209. _keydown: function (event) {
  210. var match, prev, character, skip, regex,
  211. preventDefault = true;
  212. /* eslint-disable max-depth */
  213. /**
  214. * @param {String} value
  215. */
  216. function escape(value) {
  217. return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
  218. }
  219. if (this.active.closest(this.options.menus).attr('aria-expanded') != 'true') { //eslint-disable-line eqeqeq
  220. switch (event.keyCode) {
  221. case $.ui.keyCode.PAGE_UP:
  222. this.previousPage(event);
  223. break;
  224. case $.ui.keyCode.PAGE_DOWN:
  225. this.nextPage(event);
  226. break;
  227. case $.ui.keyCode.HOME:
  228. this._move('first', 'first', event);
  229. break;
  230. case $.ui.keyCode.END:
  231. this._move('last', 'last', event);
  232. break;
  233. case $.ui.keyCode.UP:
  234. this.previous(event);
  235. break;
  236. case $.ui.keyCode.DOWN:
  237. if (this.active && !this.active.is('.ui-state-disabled')) {
  238. this.expand(event);
  239. }
  240. break;
  241. case $.ui.keyCode.LEFT:
  242. this.previous(event);
  243. break;
  244. case $.ui.keyCode.RIGHT:
  245. this.next(event);
  246. break;
  247. case $.ui.keyCode.ENTER:
  248. case $.ui.keyCode.SPACE:
  249. this._activate(event);
  250. break;
  251. case $.ui.keyCode.ESCAPE:
  252. this.collapse(event);
  253. break;
  254. default:
  255. preventDefault = false;
  256. prev = this.previousFilter || '';
  257. character = String.fromCharCode(event.keyCode);
  258. skip = false;
  259. clearTimeout(this.filterTimer);
  260. if (character === prev) {
  261. skip = true;
  262. } else {
  263. character = prev + character;
  264. }
  265. regex = new RegExp('^' + escape(character), 'i');
  266. match = this.activeMenu.children('.ui-menu-item').filter(function () {
  267. return regex.test($(this).children('a').text());
  268. });
  269. match = skip && match.index(this.active.next()) !== -1 ?
  270. this.active.nextAll('.ui-menu-item') :
  271. match;
  272. // If no matches on the current filter, reset to the last character pressed
  273. // to move down the menu to the first item that starts with that character
  274. if (!match.length) {
  275. character = String.fromCharCode(event.keyCode);
  276. regex = new RegExp('^' + escape(character), 'i');
  277. match = this.activeMenu.children('.ui-menu-item').filter(function () {
  278. return regex.test($(this).children('a').text());
  279. });
  280. }
  281. if (match.length) {
  282. this.focus(event, match);
  283. if (match.length > 1) {
  284. this.previousFilter = character;
  285. this.filterTimer = this._delay(function () {
  286. delete this.previousFilter;
  287. }, 1000);
  288. } else {
  289. delete this.previousFilter;
  290. }
  291. } else {
  292. delete this.previousFilter;
  293. }
  294. }
  295. } else {
  296. switch (event.keyCode) {
  297. case $.ui.keyCode.DOWN:
  298. this.next(event);
  299. break;
  300. case $.ui.keyCode.UP:
  301. this.previous(event);
  302. break;
  303. case $.ui.keyCode.RIGHT:
  304. if (this.active && !this.active.is('.ui-state-disabled')) {
  305. this.expand(event);
  306. }
  307. break;
  308. case $.ui.keyCode.ENTER:
  309. case $.ui.keyCode.SPACE:
  310. this._activate(event);
  311. break;
  312. case $.ui.keyCode.LEFT:
  313. case $.ui.keyCode.ESCAPE:
  314. this.collapse(event);
  315. break;
  316. default:
  317. preventDefault = false;
  318. prev = this.previousFilter || '';
  319. character = String.fromCharCode(event.keyCode);
  320. skip = false;
  321. clearTimeout(this.filterTimer);
  322. if (character === prev) {
  323. skip = true;
  324. } else {
  325. character = prev + character;
  326. }
  327. regex = new RegExp('^' + escape(character), 'i');
  328. match = this.activeMenu.children('.ui-menu-item').filter(function () {
  329. return regex.test($(this).children('a').text());
  330. });
  331. match = skip && match.index(this.active.next()) !== -1 ?
  332. this.active.nextAll('.ui-menu-item') :
  333. match;
  334. // If no matches on the current filter, reset to the last character pressed
  335. // to move down the menu to the first item that starts with that character
  336. if (!match.length) {
  337. character = String.fromCharCode(event.keyCode);
  338. regex = new RegExp('^' + escape(character), 'i');
  339. match = this.activeMenu.children('.ui-menu-item').filter(function () {
  340. return regex.test($(this).children('a').text());
  341. });
  342. }
  343. if (match.length) {
  344. this.focus(event, match);
  345. if (match.length > 1) {
  346. this.previousFilter = character;
  347. this.filterTimer = this._delay(function () {
  348. delete this.previousFilter;
  349. }, 1000);
  350. } else {
  351. delete this.previousFilter;
  352. }
  353. } else {
  354. delete this.previousFilter;
  355. }
  356. }
  357. }
  358. /* eslint-enable max-depth */
  359. if (preventDefault) {
  360. event.preventDefault();
  361. }
  362. },
  363. /**
  364. * @private
  365. */
  366. _toggleMobileMode: function () {
  367. var subMenus;
  368. $(this.element).off('mouseenter mouseleave');
  369. this._on({
  370. /**
  371. * @param {jQuery.Event} event
  372. */
  373. 'click .ui-menu-item:has(a)': function (event) {
  374. var target;
  375. event.preventDefault();
  376. target = $(event.target).closest('.ui-menu-item');
  377. target.get(0).scrollIntoView();
  378. if (!target.hasClass('level-top') || !target.has('.ui-menu').length) {
  379. window.location.href = target.find('> a').attr('href');
  380. }
  381. },
  382. /**
  383. * @param {jQuery.Event} event
  384. */
  385. 'click .ui-menu-item:has(.ui-state-active)': function (event) {
  386. this.collapseAll(event, true);
  387. }
  388. });
  389. subMenus = this.element.find('.level-top');
  390. $.each(subMenus, $.proxy(function (index, item) {
  391. var category = $(item).find('> a span').not('.ui-menu-icon').text(),
  392. categoryUrl = $(item).find('> a').attr('href'),
  393. menu = $(item).find('> .ui-menu');
  394. this.categoryLink = $('<a>')
  395. .attr('href', categoryUrl)
  396. .text($.mage.__('All ') + category);
  397. this.categoryParent = $('<li>')
  398. .addClass('ui-menu-item all-category')
  399. .html(this.categoryLink);
  400. if (menu.find('.all-category').length === 0) {
  401. menu.prepend(this.categoryParent);
  402. }
  403. }, this));
  404. },
  405. /**
  406. * @private
  407. */
  408. _toggleDesktopMode: function () {
  409. var categoryParent, html;
  410. $(this.element).off('click mousedown mouseenter mouseleave');
  411. this._on({
  412. /**
  413. * Prevent focus from sticking to links inside menu after clicking
  414. * them (focus should always stay on UL during navigation).
  415. */
  416. 'mousedown .ui-menu-item > a': function (event) {
  417. event.preventDefault();
  418. },
  419. /**
  420. * Prevent focus from sticking to links inside menu after clicking
  421. * them (focus should always stay on UL during navigation).
  422. */
  423. 'click .ui-state-disabled > a': function (event) {
  424. event.preventDefault();
  425. },
  426. /**
  427. * @param {jQuer.Event} event
  428. */
  429. 'click .ui-menu-item:has(a)': function (event) {
  430. var target = $(event.target).closest('.ui-menu-item');
  431. if (!this.mouseHandled && target.not('.ui-state-disabled').length) {
  432. this.select(event);
  433. // Only set the mouseHandled flag if the event will bubble, see #9469.
  434. if (!event.isPropagationStopped()) {
  435. this.mouseHandled = true;
  436. }
  437. // Open submenu on click
  438. if (target.has('.ui-menu').length) {
  439. this.expand(event);
  440. } else if (!this.element.is(':focus') &&
  441. $(this.document[0].activeElement).closest('.ui-menu').length
  442. ) {
  443. // Redirect focus to the menu
  444. this.element.trigger('focus', [true]);
  445. // If the active item is on the top level, let it stay active.
  446. // Otherwise, blur the active item since it is no longer visible.
  447. if (this.active && this.active.parents('.ui-menu').length === 1) { //eslint-disable-line
  448. clearTimeout(this.timer);
  449. }
  450. }
  451. }
  452. },
  453. /**
  454. * @param {jQuery.Event} event
  455. */
  456. 'mouseenter .ui-menu-item': function (event) {
  457. var target = $(event.currentTarget),
  458. submenu = this.options.menus,
  459. ulElement,
  460. ulElementWidth,
  461. width,
  462. targetPageX,
  463. rightBound;
  464. if (target.has(submenu)) {
  465. ulElement = target.find(submenu);
  466. ulElementWidth = ulElement.outerWidth(true);
  467. width = target.outerWidth() * 2;
  468. targetPageX = target.offset().left;
  469. rightBound = $(window).width();
  470. if (ulElementWidth + width + targetPageX > rightBound) {
  471. ulElement.addClass('submenu-reverse');
  472. }
  473. if (targetPageX - ulElementWidth < 0) {
  474. ulElement.removeClass('submenu-reverse');
  475. }
  476. }
  477. // Remove ui-state-active class from siblings of the newly focused menu item
  478. // to avoid a jump caused by adjacent elements both having a class with a border
  479. target.siblings().children('.ui-state-active').removeClass('ui-state-active');
  480. this.focus(event, target);
  481. },
  482. /**
  483. * @param {jQuery.Event} event
  484. */
  485. 'mouseleave': function (event) {
  486. this.collapseAll(event, true);
  487. },
  488. /**
  489. * Mouse leave.
  490. */
  491. 'mouseleave .ui-menu': 'collapseAll'
  492. });
  493. categoryParent = this.element.find('.all-category');
  494. html = $('html');
  495. categoryParent.remove();
  496. if (html.hasClass('nav-open')) {
  497. html.removeClass('nav-open');
  498. setTimeout(function () {
  499. html.removeClass('nav-before-open');
  500. }, this.options.hideDelay);
  501. }
  502. },
  503. /**
  504. * @param {*} handler
  505. * @param {Number} delay
  506. * @return {Number}
  507. * @private
  508. */
  509. _delay: function (handler, delay) {
  510. var instance = this,
  511. /**
  512. * @return {*}
  513. */
  514. handlerProxy = function () {
  515. return (typeof handler === 'string' ? instance[handler] : handler).apply(instance, arguments);
  516. };
  517. return setTimeout(handlerProxy, delay || 0);
  518. },
  519. /**
  520. * @param {jQuery.Event} event
  521. */
  522. expand: function (event) {
  523. var newItem = this.active &&
  524. this.active
  525. .children('.ui-menu')
  526. .children('.ui-menu-item')
  527. .first();
  528. if (newItem && newItem.length) {
  529. if (newItem.closest('.ui-menu').is(':visible') &&
  530. newItem.closest('.ui-menu').has('.all-categories')
  531. ) {
  532. return;
  533. }
  534. // remove the active state class from the siblings
  535. this.active.siblings().children('.ui-state-active').removeClass('ui-state-active');
  536. this._open(newItem.parent());
  537. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  538. this._delay(function () {
  539. this.focus(event, newItem);
  540. });
  541. }
  542. },
  543. /**
  544. * @param {jQuery.Event} event
  545. */
  546. select: function (event) {
  547. var ui;
  548. this.active = this.active || $(event.target).closest('.ui-menu-item');
  549. if (this.active.is('.all-category')) {
  550. this.active = $(event.target).closest('.ui-menu-item');
  551. }
  552. ui = {
  553. item: this.active
  554. };
  555. if (!this.active.has('.ui-menu').length) {
  556. this.collapseAll(event, true);
  557. }
  558. this._trigger('select', event, ui);
  559. }
  560. });
  561. $.widget('mage.navigation', $.mage.menu, {
  562. options: {
  563. responsiveAction: 'wrap', //option for responsive handling
  564. maxItems: null, //option to set max number of menu items
  565. container: '#menu', //container to check against navigation length
  566. moreText: $.mage.__('more'),
  567. breakpoint: 768
  568. },
  569. /**
  570. * @private
  571. */
  572. _init: function () {
  573. var that, responsive;
  574. this._super();
  575. that = this;
  576. responsive = this.options.responsiveAction;
  577. this.element
  578. .addClass('ui-menu-responsive')
  579. .attr('responsive', 'main');
  580. this.setupMoreMenu();
  581. this.setMaxItems();
  582. //check responsive option
  583. if (responsive == 'onResize') { //eslint-disable-line eqeqeq
  584. $(window).on('resize', function () {
  585. if ($(window).width() > that.options.breakpoint) {
  586. that._responsive();
  587. $('[responsive=more]').show();
  588. } else {
  589. that.element.children().show();
  590. $('[responsive=more]').hide();
  591. }
  592. });
  593. } else if (responsive == 'onReload') { //eslint-disable-line eqeqeq
  594. this._responsive();
  595. }
  596. },
  597. /**
  598. * Setup more menu.
  599. */
  600. setupMoreMenu: function () {
  601. var moreListItems = this.element.children().clone(),
  602. moreLink = $('<a>' + this.options.moreText + '</a>');
  603. moreListItems.hide();
  604. moreLink.attr('href', '#');
  605. this.moreItemsList = $('<ul>')
  606. .append(moreListItems);
  607. this.moreListContainer = $('<li>')
  608. .append(moreLink)
  609. .append(this.moreItemsList);
  610. this.responsiveMenu = $('<ul>')
  611. .addClass('ui-menu-more')
  612. .attr('responsive', 'more')
  613. .append(this.moreListContainer)
  614. .menu({
  615. position: {
  616. my: 'right top',
  617. at: 'right bottom'
  618. }
  619. })
  620. .insertAfter(this.element);
  621. },
  622. /**
  623. * @private
  624. */
  625. _responsive: function () {
  626. var container = $(this.options.container),
  627. containerSize = container.width(),
  628. width = 0,
  629. items = this.element.children('li'),
  630. more = $('.ui-menu-more > li > ul > li a');
  631. items = items.map(function () {
  632. var item = {};
  633. item.item = $(this);
  634. item.itemSize = $(this).outerWidth();
  635. return item;
  636. });
  637. $.each(items, function (index) {
  638. var itemText = items[index].item
  639. .find('a:first')
  640. .text();
  641. width += parseInt(items[index].itemSize, null); //eslint-disable-line radix
  642. if (width < containerSize) {
  643. items[index].item.show();
  644. more.each(function () {
  645. var text = $(this).text();
  646. if (text === itemText) {
  647. $(this).parent().hide();
  648. }
  649. });
  650. } else if (width > containerSize) {
  651. items[index].item.hide();
  652. more.each(function () {
  653. var text = $(this).text();
  654. if (text === itemText) {
  655. $(this).parent().show();
  656. }
  657. });
  658. }
  659. });
  660. },
  661. /**
  662. * Set max items.
  663. */
  664. setMaxItems: function () {
  665. var items = this.element.children('li'),
  666. itemsCount = items.length,
  667. maxItems = this.options.maxItems,
  668. overflow = itemsCount - maxItems,
  669. overflowItems = items.slice(overflow);
  670. overflowItems.hide();
  671. overflowItems.each(function () {
  672. var itemText = $(this).find('a:first').text();
  673. $(this).hide();
  674. $('.ui-menu-more > li > ul > li a').each(function () {
  675. var text = $(this).text();
  676. if (text === itemText) {
  677. $(this).parent().show();
  678. }
  679. });
  680. });
  681. }
  682. });
  683. return {
  684. menu: $.mage.menu,
  685. navigation: $.mage.navigation
  686. };
  687. });