<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Nav not working, but code is working on other sites in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1041058#M40678</link>
    <description>&lt;P&gt;It looks to me like the issue is with is with the javascript you have for opening submenus&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*!*************************************************!*\
  !*** ./main/modules/global/Header/01-SubNav.js ***!
  \*************************************************/
(__unused_webpack_module,  __webpack_exports__,  __webpack_require__) =&amp;gt;  {
     "use strict";
     eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   M01SubNav: () =&amp;gt; (/* binding */ M01SubNav)\n/* harmony export */ });\n/* harmony import */ var gsap__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! gsap */ \"../node_modules/gsap/index.js\");\n/* harmony import */ var _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./01-SearchToggler */ \"./main/modules/global/Header/01-SearchToggler.js\");\n\n\nclass M01SubNav {\n  static name = 'M01-Header__navigation';\n  static control = '#module-subnav';\n  constructor(selector, searchSelector) {\n    this.elements = typeof selector === 'string' ? document.querySelectorAll(selector) : selector;\n    this.search = typeof searchSelector === 'string' ? document.querySelector(searchSelector) : searchSelector;\n\n    // Store the reference to the handleOutsideClick function\n    this.handleOutsideClick = this.handleOutsideClick.bind(this);\n    if (this.elements) this.init();\n  }\n  init() {\n    return new Promise((resolve, reject) =&amp;gt; {\n      this.bind();\n      resolve();\n    });\n  }\n  bind() {\n    this.elements.forEach(e =&amp;gt; {\n      const secondaryNav = e?.classList.contains(`${M01SubNav.name}--secondary`);\n      const attribute = secondaryNav ? 'aria-controls' : 'href';\n      this.setupSubNav(e, attribute);\n    });\n    document.querySelectorAll(`.${M01SubNav.name} .hs-item-has-children &amp;gt; a, .${M01SubNav.name} [aria-controls^=\"${M01SubNav.control}\"]`)?.forEach(e =&amp;gt; {\n      e.addEventListener('click', this.toggleNav.bind(this));\n    });\n  }\n  setupSubNav(e, attribute) {\n    e.querySelectorAll(`[${attribute}^=\"${M01SubNav.control}\"]`)?.forEach(trigger =&amp;gt; {\n      const target = trigger?.getAttribute(attribute);\n      const subNav = document.querySelector(target);\n      if (!subNav) {\n        return console.error(`No sub nav found for ${target} navigation`);\n      }\n      const cln = subNav.cloneNode(true);\n      let parent = trigger.parentNode;\n      if (trigger.tagName === 'A') {\n        const sub = trigger.closest('ul.hs-menu-children-wrapper');\n        parent = sub.parentNode;\n        parent.removeChild(sub);\n      }\n      parent.appendChild(cln);\n    });\n  }\n  toggleNav(e) {\n    e.preventDefault();\n    const target = e.target;\n    const state = target?.getAttribute('aria-expanded') === 'true' ? false : true;\n    M01SubNav.closeAll();\n    if (this.search &amp;amp;&amp;amp; !this.search.classList.contains('is-hidden') &amp;amp;&amp;amp; this.search.classList.contains('is-open')) {\n      _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__.M01HeaderSearchToggler.closeSearch(this.search);\n    }\n    const subnav = target?.parentNode.querySelector(`.${M01SubNav.name}__subnav`) || target?.parentNode.querySelector('.hs-menu-children-wrapper');\n    target?.setAttribute('aria-expanded', state);\n    subnav?.setAttribute('aria-expanded', state);\n    let tl = gsap__WEBPACK_IMPORTED_MODULE_1__.gsap.timeline();\n    if (state) {\n      tl.to(subnav, {\n        duration: 0.15,\n        display: 'flex'\n      }).to(subnav, {\n        duration: 0.15,\n        opacity: 1,\n        scaleY: 1\n      });\n\n      // Add event listener to detect click outside\n      document.addEventListener('mousedown', this.handleOutsideClick);\n    } else {\n      tl.to(subnav, {\n        duration: 0.15,\n        display: 'none',\n        opacity: 0,\n        scaleY: 0\n      });\n\n      // Remove event listener when closed\n      document.removeEventListener('mousedown', this.handleOutsideClick);\n    }\n  }\n  handleOutsideClick(event) {\n    M01SubNav.closeAll();\n\n    // Remove the event listener after closing the subnav\n    document.removeEventListener('mousedown', this.handleOutsideClick);\n  }\n  static closeAll() {\n    document.querySelectorAll(`.${M01SubNav.name} [aria-expanded=\"true\"]`)?.forEach(e =&amp;gt; {\n      e.setAttribute('aria-expanded', 'false');\n      if (e.classList.contains(`${M01SubNav.name}__subnav`) || e.classList.contains('hs-menu-children-wrapper')) {\n        gsap__WEBPACK_IMPORTED_MODULE_1__.gsap.to(e, {\n          duration: 0.15,\n          display: 'none',\n          opacity: 0,\n          scaleY: 0\n        });\n      }\n    });\n  }\n}\n\n//# sourceURL=webpack:///./main/modules/global/Header/01-SubNav.js?")
},
 "./main/modules/modules.js":
/*!*********************************!*\*/&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Seems like it's specifically the toggleNav function which uses&amp;nbsp;e.preventDefault();&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;That's preventing the click on the link from opening.&lt;BR /&gt;&lt;BR /&gt;It should only be preventing the default action if it's a submenu trigger.&lt;BR /&gt;&lt;BR /&gt;Something like&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  // Check if the clicked element is a submenu trigger or a normal link
  const isSubmenuTrigger = target?.parentNode.querySelector(`.${M01SubNav.name}__subnav`) || target?.parentNode.querySelector('.hs-menu-children-wrapper');
  
  if (isSubmenuTrigger) {
    e.preventDefault(); // Only prevent default if it's a submenu trigger

    const state = target?.getAttribute('aria-expanded') === 'true' ? false : true;
    M01SubNav.closeAll();
    
    if (this.search &amp;amp;&amp;amp; !this.search.classList.contains('is-hidden') &amp;amp;&amp;amp; this.search.classList.contains('is-open')) {
      _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__.M01HeaderSearchToggler.closeSearch(this.search);
    }&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="profile2022a" style="width: 100px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/71500iE96AB1F9E9E277B9/image-size/small?v=v2&amp;amp;px=200" role="button" title="profile2022a" alt="profile2022a" /&gt;&lt;/span&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;Barry Grennan&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&lt;A href="https://www.seoanseo.ca?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Freelance HubSpot CMS Developer&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.seoanseo.ca?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Website&lt;/A&gt; | &lt;A href="https://www.seoanseo.ca/#contact?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Contact&lt;/A&gt; | &lt;A href="https://www.linkedin.com/in/barrygrennan" target="_blank" rel="nofollow noopener noreferrer"&gt;LinkedIn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Sep 2024 07:53:07 GMT</pubDate>
    <dc:creator>BarryGrennan</dc:creator>
    <dc:date>2024-09-14T07:53:07Z</dc:date>
    <item>
      <title>Nav not working, but code is working on other sites</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1040949#M40676</link>
      <description>&lt;P&gt;the nav isn't working for the 'services' dropdown on our custom code. it is working on other sites though. It was working yesterday but not today.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.mrbundles.co/" target="_blank"&gt;https://www.mrbundles.co/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2024 20:47:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1040949#M40676</guid>
      <dc:creator>DWahl7</dc:creator>
      <dc:date>2024-09-13T20:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Nav not working, but code is working on other sites</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1041058#M40678</link>
      <description>&lt;P&gt;It looks to me like the issue is with is with the javascript you have for opening submenus&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*!*************************************************!*\
  !*** ./main/modules/global/Header/01-SubNav.js ***!
  \*************************************************/
(__unused_webpack_module,  __webpack_exports__,  __webpack_require__) =&amp;gt;  {
     "use strict";
     eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   M01SubNav: () =&amp;gt; (/* binding */ M01SubNav)\n/* harmony export */ });\n/* harmony import */ var gsap__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! gsap */ \"../node_modules/gsap/index.js\");\n/* harmony import */ var _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./01-SearchToggler */ \"./main/modules/global/Header/01-SearchToggler.js\");\n\n\nclass M01SubNav {\n  static name = 'M01-Header__navigation';\n  static control = '#module-subnav';\n  constructor(selector, searchSelector) {\n    this.elements = typeof selector === 'string' ? document.querySelectorAll(selector) : selector;\n    this.search = typeof searchSelector === 'string' ? document.querySelector(searchSelector) : searchSelector;\n\n    // Store the reference to the handleOutsideClick function\n    this.handleOutsideClick = this.handleOutsideClick.bind(this);\n    if (this.elements) this.init();\n  }\n  init() {\n    return new Promise((resolve, reject) =&amp;gt; {\n      this.bind();\n      resolve();\n    });\n  }\n  bind() {\n    this.elements.forEach(e =&amp;gt; {\n      const secondaryNav = e?.classList.contains(`${M01SubNav.name}--secondary`);\n      const attribute = secondaryNav ? 'aria-controls' : 'href';\n      this.setupSubNav(e, attribute);\n    });\n    document.querySelectorAll(`.${M01SubNav.name} .hs-item-has-children &amp;gt; a, .${M01SubNav.name} [aria-controls^=\"${M01SubNav.control}\"]`)?.forEach(e =&amp;gt; {\n      e.addEventListener('click', this.toggleNav.bind(this));\n    });\n  }\n  setupSubNav(e, attribute) {\n    e.querySelectorAll(`[${attribute}^=\"${M01SubNav.control}\"]`)?.forEach(trigger =&amp;gt; {\n      const target = trigger?.getAttribute(attribute);\n      const subNav = document.querySelector(target);\n      if (!subNav) {\n        return console.error(`No sub nav found for ${target} navigation`);\n      }\n      const cln = subNav.cloneNode(true);\n      let parent = trigger.parentNode;\n      if (trigger.tagName === 'A') {\n        const sub = trigger.closest('ul.hs-menu-children-wrapper');\n        parent = sub.parentNode;\n        parent.removeChild(sub);\n      }\n      parent.appendChild(cln);\n    });\n  }\n  toggleNav(e) {\n    e.preventDefault();\n    const target = e.target;\n    const state = target?.getAttribute('aria-expanded') === 'true' ? false : true;\n    M01SubNav.closeAll();\n    if (this.search &amp;amp;&amp;amp; !this.search.classList.contains('is-hidden') &amp;amp;&amp;amp; this.search.classList.contains('is-open')) {\n      _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__.M01HeaderSearchToggler.closeSearch(this.search);\n    }\n    const subnav = target?.parentNode.querySelector(`.${M01SubNav.name}__subnav`) || target?.parentNode.querySelector('.hs-menu-children-wrapper');\n    target?.setAttribute('aria-expanded', state);\n    subnav?.setAttribute('aria-expanded', state);\n    let tl = gsap__WEBPACK_IMPORTED_MODULE_1__.gsap.timeline();\n    if (state) {\n      tl.to(subnav, {\n        duration: 0.15,\n        display: 'flex'\n      }).to(subnav, {\n        duration: 0.15,\n        opacity: 1,\n        scaleY: 1\n      });\n\n      // Add event listener to detect click outside\n      document.addEventListener('mousedown', this.handleOutsideClick);\n    } else {\n      tl.to(subnav, {\n        duration: 0.15,\n        display: 'none',\n        opacity: 0,\n        scaleY: 0\n      });\n\n      // Remove event listener when closed\n      document.removeEventListener('mousedown', this.handleOutsideClick);\n    }\n  }\n  handleOutsideClick(event) {\n    M01SubNav.closeAll();\n\n    // Remove the event listener after closing the subnav\n    document.removeEventListener('mousedown', this.handleOutsideClick);\n  }\n  static closeAll() {\n    document.querySelectorAll(`.${M01SubNav.name} [aria-expanded=\"true\"]`)?.forEach(e =&amp;gt; {\n      e.setAttribute('aria-expanded', 'false');\n      if (e.classList.contains(`${M01SubNav.name}__subnav`) || e.classList.contains('hs-menu-children-wrapper')) {\n        gsap__WEBPACK_IMPORTED_MODULE_1__.gsap.to(e, {\n          duration: 0.15,\n          display: 'none',\n          opacity: 0,\n          scaleY: 0\n        });\n      }\n    });\n  }\n}\n\n//# sourceURL=webpack:///./main/modules/global/Header/01-SubNav.js?")
},
 "./main/modules/modules.js":
/*!*********************************!*\*/&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Seems like it's specifically the toggleNav function which uses&amp;nbsp;e.preventDefault();&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;That's preventing the click on the link from opening.&lt;BR /&gt;&lt;BR /&gt;It should only be preventing the default action if it's a submenu trigger.&lt;BR /&gt;&lt;BR /&gt;Something like&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  // Check if the clicked element is a submenu trigger or a normal link
  const isSubmenuTrigger = target?.parentNode.querySelector(`.${M01SubNav.name}__subnav`) || target?.parentNode.querySelector('.hs-menu-children-wrapper');
  
  if (isSubmenuTrigger) {
    e.preventDefault(); // Only prevent default if it's a submenu trigger

    const state = target?.getAttribute('aria-expanded') === 'true' ? false : true;
    M01SubNav.closeAll();
    
    if (this.search &amp;amp;&amp;amp; !this.search.classList.contains('is-hidden') &amp;amp;&amp;amp; this.search.classList.contains('is-open')) {
      _01_SearchToggler__WEBPACK_IMPORTED_MODULE_0__.M01HeaderSearchToggler.closeSearch(this.search);
    }&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="profile2022a" style="width: 100px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/71500iE96AB1F9E9E277B9/image-size/small?v=v2&amp;amp;px=200" role="button" title="profile2022a" alt="profile2022a" /&gt;&lt;/span&gt;&lt;STRONG&gt;&lt;FONT size="5"&gt;Barry Grennan&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&lt;A href="https://www.seoanseo.ca?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Freelance HubSpot CMS Developer&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.seoanseo.ca?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Website&lt;/A&gt; | &lt;A href="https://www.seoanseo.ca/#contact?utm_source=HubSpotCommunity" target="_blank" rel="nofollow noopener noreferrer"&gt;Contact&lt;/A&gt; | &lt;A href="https://www.linkedin.com/in/barrygrennan" target="_blank" rel="nofollow noopener noreferrer"&gt;LinkedIn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Sep 2024 07:53:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1041058#M40678</guid>
      <dc:creator>BarryGrennan</dc:creator>
      <dc:date>2024-09-14T07:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Nav not working, but code is working on other sites</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1041504#M40682</link>
      <description>&lt;P&gt;Perfect, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 14:07:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Nav-not-working-but-code-is-working-on-other-sites/m-p/1041504#M40682</guid>
      <dc:creator>DWahl7</dc:creator>
      <dc:date>2024-09-16T14:07:36Z</dc:date>
    </item>
  </channel>
</rss>

