{"version":3,"file":"mobileHeader-e7a4beb3.js","sources":["../../../../../../src/scripts/modules/mobileHeader.ts"],"sourcesContent":["import { Component } from '@verndale/core';\n\nclass MobileHeader extends Component {\n setupDefaults() {\n this.dom = {\n navBtn: this.el.querySelector('.mobile-header__menu-container button'),\n navOpenIcon: this.el.querySelector(\n '.mobile-header__menu-button__icon-open'\n ),\n navCloseIcon: this.el.querySelector(\n '.mobile-header__menu-button__icon-close'\n ),\n navContainer: this.el.querySelector('.mobile-header__nav-container'),\n searchContainer: this.el.querySelector(\n '.mobile-header__search-button .mobile-header__nav-container'\n ),\n cartBtn: this.el.querySelector('.mobile-header__cart-button button'),\n cartContainer: document.querySelector(\n '.cart__container'\n ),\n closeCartBtn: document.querySelector(\n '.cart__item__close-button'\n ),\n keepBrowsingBtn: document.querySelector('.cart__view-basket-button--keep-browsing'),\n subMenuBtns: this.el.querySelectorAll('.has-submenu'),\n mainMenu: this.el.querySelector('.mobile-header__nav__main-nav'),\n allSubMenus: this.el.querySelectorAll(\n '.mobile-header__nav__submenu-container'\n ),\n backBtns: this.el.querySelectorAll('.mobile-header__nav__back-button'),\n accordionBtns: this.el.querySelectorAll(\n '.mobile-header__nav__submenu-item__accordion-button'\n )\n };\n }\n\n addListeners() {\n const {\n navBtn,\n cartBtn,\n subMenuBtns,\n backBtns,\n accordionBtns,\n closeCartBtn,\n keepBrowsingBtn\n } = this.dom;\n\n (navBtn as HTMLElement).addEventListener('click', this.toggleNav.bind(this));\n (cartBtn as HTMLElement).addEventListener('click', this.toggleCart.bind(this));\n (closeCartBtn as HTMLElement)?.addEventListener('click', this.closeCartNav.bind(this));\n (keepBrowsingBtn as HTMLElement)?.addEventListener('click', this.closeCartNav.bind(this));\n\n\n (subMenuBtns as NodeList).forEach(btn => {\n btn.addEventListener('click', this.toggleSubMenu.bind(this));\n });\n\n (backBtns as NodeList).forEach(btn => {\n btn.addEventListener('click', this.toggleBack.bind(this));\n });\n\n (accordionBtns as NodeList).forEach(btn => {\n btn.addEventListener('click', this.toggleAccordion.bind(this));\n });\n }\n\n lockBody() {\n document.body.style.overflow = 'hidden';\n document.body.style.position = 'fixed';\n document.body.style.overflowY = 'scroll';\n }\n\n unlockBody() {\n document.body.removeAttribute('style');\n }\n\n closeCartNav() {\n (this.dom.cartContainer as HTMLElement).setAttribute('hidden', 'true');\n (this.dom.cartBtn as HTMLElement).classList.remove('is-active');\n this.unlockBody();\n }\n\n toggleAccordion(e: Event) {\n const target = e.target as HTMLElement;\n const button = target.closest('button');\n const ariaControls = (button as HTMLElement).getAttribute('aria-controls');\n\n if (ariaControls) {\n const accordionContent = document.getElementById(ariaControls);\n const minusIcon = (button as HTMLElement).querySelector('.minus-icon');\n const plusIcon = (button as HTMLElement).querySelector('.plus-icon');\n\n if ((accordionContent as HTMLElement).hidden) {\n (accordionContent as HTMLElement).removeAttribute('hidden');\n (minusIcon as HTMLElement).removeAttribute('hidden');\n (plusIcon as HTMLElement).setAttribute('hidden', 'true');\n } else {\n (accordionContent as HTMLElement).setAttribute('hidden', 'true');\n (minusIcon as HTMLElement).setAttribute('hidden', 'true');\n (plusIcon as HTMLElement).removeAttribute('hidden');\n }\n }\n }\n\n toggleBack(e: Event) {\n const target = e.target as HTMLElement;\n const button = target.closest('button');\n const ariaControls = (button as HTMLElement).getAttribute('aria-controls');\n\n if (ariaControls) {\n const subMenu = document.getElementById(ariaControls);\n\n this.hideAllMenus();\n if ((subMenu as HTMLElement).hidden) {\n (subMenu as HTMLElement).removeAttribute('hidden');\n } else {\n (subMenu as HTMLElement).setAttribute('hidden', 'true');\n }\n }\n }\n\n toggleSubMenu(e: Event) {\n const target = e.target as HTMLElement;\n const link = target.closest('a');\n const ariaControls = (link as HTMLElement).getAttribute('aria-controls');\n\n if (ariaControls) {\n const subMenu = document.getElementById(ariaControls);\n\n this.hideAllMenus();\n if ((subMenu as HTMLElement).hidden) {\n (subMenu as HTMLElement).removeAttribute('hidden');\n } else {\n (subMenu as HTMLElement).setAttribute('hidden', 'true');\n }\n }\n }\n\n hideAllMenus() {\n (this.dom.mainMenu as HTMLElement).setAttribute('hidden', 'true');\n (this.dom.allSubMenus as NodeList).forEach(menu => {\n (menu as HTMLElement).setAttribute('hidden', 'true');\n });\n }\n\n toggleNav(e: Event) {\n const target = e.target as HTMLElement;\n const button = target.closest('button');\n this.hideMainNavs(button as HTMLButtonElement);\n (this.dom.navBtn as HTMLElement).classList.toggle('is-active');\n\n if ((this.dom.navContainer as HTMLElement).hidden) {\n (this.dom.navOpenIcon as HTMLElement).setAttribute('hidden', 'true');\n (this.dom.navCloseIcon as HTMLElement).removeAttribute('hidden');\n (this.dom.navContainer as HTMLElement).removeAttribute('hidden');\n this.lockBody();\n } else {\n (this.dom.navOpenIcon as HTMLElement).removeAttribute('hidden');\n (this.dom.navCloseIcon as HTMLElement).setAttribute('hidden', 'true');\n (this.dom.navContainer as HTMLElement).setAttribute('hidden', 'true');\n this.unlockBody();\n }\n }\n\n toggleCart(e: Event) {\n const target = e.target as HTMLElement;\n const button = target.closest('button');\n this.hideMainNavs(button as HTMLButtonElement);\n\n (this.dom.cartBtn as HTMLElement).classList.toggle('is-active');\n\n if ((this.dom.cartContainer as HTMLElement).hidden) {\n (this.dom.cartContainer as HTMLElement).removeAttribute('hidden');\n this.lockBody();\n } else {\n (this.dom.cartContainer as HTMLElement).setAttribute('hidden', 'true');\n this.unlockBody();\n }\n }\n\n hideMainNavs(button: HTMLButtonElement) {\n // closing main nav\n if (button !== this.dom.navBtn) {\n (this.dom.navBtn as HTMLElement).classList.remove('is-active');\n (this.dom.navOpenIcon as HTMLElement).removeAttribute('hidden');\n (this.dom.navCloseIcon as HTMLElement).setAttribute('hidden', \"true\");\n (this.dom.navContainer as HTMLElement).setAttribute('hidden', \"true\");\n }\n // closing cart nav\n if (button !== this.dom.cartBtn) {\n (this.dom.cartBtn as HTMLElement).classList.remove('is-active');\n (this.dom.cartContainer as HTMLElement)?.setAttribute('hidden', \"true\");\n }\n }\n}\n\nexport default MobileHeader;\n"],"names":["MobileHeader","Component","navBtn","cartBtn","subMenuBtns","backBtns","accordionBtns","closeCartBtn","keepBrowsingBtn","btn","e","button","ariaControls","accordionContent","minusIcon","plusIcon","subMenu","menu","_a"],"mappings":"oCAEA,MAAMA,UAAqBC,CAAU,CACnC,eAAgB,CACd,KAAK,IAAM,CACT,OAAQ,KAAK,GAAG,cAA2B,uCAAuC,EAClF,YAAa,KAAK,GAAG,cACnB,wCACF,EACA,aAAc,KAAK,GAAG,cACpB,yCACF,EACA,aAAc,KAAK,GAAG,cAA2B,+BAA+B,EAChF,gBAAiB,KAAK,GAAG,cACvB,6DACF,EACA,QAAS,KAAK,GAAG,cAA2B,oCAAoC,EAChF,cAAe,SAAS,cACtB,kBACF,EACA,aAAc,SAAS,cACrB,2BACF,EACA,gBAAiB,SAAS,cAA2B,0CAA0C,EAC/F,YAAa,KAAK,GAAG,iBAAiB,cAAc,EACpD,SAAU,KAAK,GAAG,cAA2B,+BAA+B,EAC5E,YAAa,KAAK,GAAG,iBACnB,wCACF,EACA,SAAU,KAAK,GAAG,iBAAiB,kCAAkC,EACrE,cAAe,KAAK,GAAG,iBACrB,qDACF,CAAA,CAEJ,CAEA,cAAe,CACP,KAAA,CACJ,OAAAC,EACA,QAAAC,EACA,YAAAC,EACA,SAAAC,EACA,cAAAC,EACA,aAAAC,EACA,gBAAAC,CAAA,EACE,KAAK,IAERN,EAAuB,iBAAiB,QAAS,KAAK,UAAU,KAAK,IAAI,CAAC,EAC1EC,EAAwB,iBAAiB,QAAS,KAAK,WAAW,KAAK,IAAI,CAAC,EAC5EI,GAAA,MAAAA,EAA8B,iBAAiB,QAAS,KAAK,aAAa,KAAK,IAAI,GACnFC,GAAA,MAAAA,EAAiC,iBAAiB,QAAS,KAAK,aAAa,KAAK,IAAI,GAGtFJ,EAAyB,QAAeK,GAAA,CACvCA,EAAI,iBAAiB,QAAS,KAAK,cAAc,KAAK,IAAI,CAAC,CAAA,CAC5D,EAEAJ,EAAsB,QAAeI,GAAA,C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