{"version":3,"file":"index-C9rTYRHt.js","sources":["../../Assets/Scripts/components/toggleClass/index.ts"],"sourcesContent":["const desktopBreakpoint = 1350;\n\nconst instance = ($el: HTMLElement) => {\n $el.addEventListener(\"click\", (event: MouseEvent) => {\n let toggleClass = \"toggled\";\n let $targetEl = $el;\n\n // If a class is specified by data attribute, use that instead of default\n if ($el.hasAttribute(\"data-class\")) {\n toggleClass = $el.getAttribute(\"data-class\")!;\n }\n\n // If a target element is specified, use that instead of self\n if ($el.hasAttribute(\"data-target\")) {\n const $specifiedTarget = document.querySelector(\n $el.getAttribute(\"data-target\")!,\n );\n\n if ($specifiedTarget) {\n $targetEl = $specifiedTarget;\n }\n }\n\n // If double click mode is enabled, and the target element is already toggled, allow links to be clicked\n // If double click mode is disabled, and screen size is desktop, allow links to be clicked\n if (\n ($el.getAttribute(\"data-double-click\") === \"true\" &&\n $targetEl.classList.contains(toggleClass)) ||\n ($el.getAttribute(\"data-double-click\") === \"false\" &&\n window.innerWidth > desktopBreakpoint)\n ) {\n return true;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n // If the element has a data-untoggle attribute, untoggle the specified elements when this one is toggled\n if (\n $el.hasAttribute(\"data-untoggle\") &&\n (!$targetEl.classList.contains(toggleClass) ||\n ($el.hasAttribute(\"data-untoggle-always\") &&\n $el.getAttribute(\"data-untoggle-always\") === \"true\"))\n ) {\n const $untoggleEls = document.querySelectorAll(\n $el.getAttribute(\"data-untoggle\")!,\n );\n\n $untoggleEls.forEach(($untoggleEl) => {\n $untoggleEl.classList.remove(toggleClass);\n });\n }\n\n $targetEl.classList.toggle(toggleClass);\n\n // If the element is set to auto close and is toggled, add an event listener to close if clicked outside\n if (\n $el.hasAttribute(\"data-auto-close\") &&\n $targetEl.classList.contains(toggleClass)\n ) {\n document.addEventListener(\"click\", (e) => {\n if (\n !$targetEl.contains(e.target as Node) &&\n !$el.contains(e.target as Node)\n ) {\n $targetEl.classList.remove(toggleClass);\n }\n });\n } else if ($el.hasAttribute(\"data-auto-close\")) {\n document.removeEventListener(\"click\", () => {\n return false;\n });\n }\n\n return false;\n });\n};\n\nexport default () => {\n const $el = document.querySelectorAll(\".js-toggle-class\");\n\n $el.forEach(($element) => {\n instance($element);\n });\n};\n"],"names":["instance","$el","event","toggleClass","$targetEl","$specifiedTarget","$untoggleEl","e","index","$element"],"mappings":"AAEA,MAAMA,EAAYC,GAAqB,CACjCA,EAAA,iBAAiB,QAAUC,GAAsB,CACnD,IAAIC,EAAc,UACdC,EAAYH,EAQZ,GALAA,EAAI,aAAa,YAAY,IACjBE,EAAAF,EAAI,aAAa,YAAY,GAIzCA,EAAI,aAAa,aAAa,EAAG,CACnC,MAAMI,EAAmB,SAAS,cAChCJ,EAAI,aAAa,aAAa,CAChC,EAEII,IACUD,EAAAC,EACd,CAKF,OACGJ,EAAI,aAAa,mBAAmB,IAAM,QACzCG,EAAU,UAAU,SAASD,CAAW,GACzCF,EAAI,aAAa,mBAAmB,IAAM,SACzC,OAAO,WAAa,KAEf,IAGTC,EAAM,eAAe,EACrBA,EAAM,gBAAgB,EAIpBD,EAAI,aAAa,eAAe,IAC/B,CAACG,EAAU,UAAU,SAASD,CAAW,GACvCF,EAAI,aAAa,sBAAsB,GACtCA,EAAI,aAAa,sBAAsB,IAAM,SAE5B,SAAS,iBAC5BA,EAAI,aAAa,eAAe,CAClC,EAEa,QAASK,GAAgB,CACxBA,EAAA,UAAU,OAAOH,CAAW,CAAA,CACzC,EAGOC,EAAA,UAAU,OAAOD,CAAW,EAIpCF,EAAI,aAAa,iBAAiB,GAClCG,EAAU,UAAU,SAASD,CAAW,EAE/B,SAAA,iBAAiB,QAAUI,GAAM,CAEtC,CAACH,EAAU,SAASG,EAAE,MAAc,GACpC,CAACN,EAAI,SAASM,EAAE,MAAc,GAEpBH,EAAA,UAAU,OAAOD,CAAW,CACxC,CACD,EACQF,EAAI,aAAa,iBAAiB,GAClC,SAAA,oBAAoB,QAAS,IAC7B,EACR,EAGI,GAAA,CACR,CACH,EAEAO,EAAe,IAAM,CACP,SAAS,iBAA8B,kBAAkB,EAEjE,QAASC,GAAa,CACxBT,EAASS,CAAQ,CAAA,CAClB,CACH"}