{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/tabs.ts"], "sourcesContent": ["import { breakpoint } from 'utility/breakpoints'\nimport { getParameterFromUrl } from 'utility/helpers'\nimport { lenisScroll } from 'utility/smooth-scroll'\n\nconst tabs = {\n init(): void {\n document.querySelectorAll('.tabs').forEach((target: HTMLElement) => {\n this.handleTabs(target)\n })\n },\n\n handleTabs(target): void {\n const el = {\n buttons: target.querySelectorAll('.tabs__button'),\n listPage: document.querySelector('.list-page'),\n productsPage: document.querySelector('.products-page'),\n searchModal: document.querySelector('.search'),\n searchPage: document.querySelector('.search-page'),\n }\n\n const method = {\n init(): void {\n // Regular tabs behaviour\n\n method.toggleTabOnHashChange(null)\n window.addEventListener('hashchange', method.toggleTabOnHashChange)\n\n // Search modal tabs behaviour\n\n el.buttons.forEach((button) => {\n if (!button.href.includes('#tab:')) {\n button.addEventListener('click', (event) => {\n method.toggleTab(button, event, true)\n })\n }\n })\n\n // Additional functionality for tabs on Products page - injecting page parameter into URL + modyfiying pagination\n\n if (el.productsPage) {\n el.buttons.forEach((button) => {\n if (button.href.includes('#tab:')) {\n const collection = getParameterFromUrl(new URL(button.href), 'collection')\n const hash = button.href.split('#')[1]\n\n button.href = !collection ? `/hudvorur/?page=1#${hash}` : `/hudvorur/?collection=${collection}&page=1#${hash}`\n }\n })\n\n el.buttons.forEach((button) => {\n if (button.href.includes('#tab:')) {\n const tabsContent = document.querySelector(`.tabs-content[aria-labelled-by='${button.id}']`)\n const pagination = tabsContent.querySelector('.pagination')\n\n if (pagination) {\n pagination.querySelectorAll('.pagination__button').forEach((button: HTMLAnchorElement) => {\n const collection = getParameterFromUrl(new URL(window.location.href), 'collection')\n const page = getParameterFromUrl(new URL(button.href), 'page')\n const hash = button.href.split('#')[1]\n\n button.href = !collection ? `/hudvorur/?page=${page}#${hash}` : `/hudvorur/?collection=${collection}&page=${page}#${hash}`\n })\n }\n }\n })\n\n // el.productsPage.querySelectorAll('.tabs-content').forEach((tabsContent) => {\n // const pagination = tabsContent.querySelector('.pagination')\n\n // console.log(pagination)\n // })\n }\n\n // Removing search query from URL when switching tabs (used on Products page) - obsolete\n\n // el.buttons.forEach((button) => {\n // button.addEventListener('click', () => {\n // if (window.location.search && window.location.hash !== button.getAttribute('href')) {\n // setTimeout(() => {\n // window.location.search = ''\n // }, 12)\n // }\n // })\n // })\n },\n\n handleScrolling: () => {\n // Edge case if the search modal is open\n\n if (el.searchModal.classList.contains('search--active')) {\n setTimeout(() => {\n el.searchModal.querySelector('.search__results').scrollTop = 0\n }, 1)\n\n return\n }\n\n // Different scroll behaviours for different pages\n\n if (!lenisScroll) {\n return\n }\n\n if (window.scrollY > 123) {\n if (el.listPage) {\n lenisScroll.scrollTo(el.listPage.querySelector('.list-page__column--right'), {\n offset: window.innerWidth < breakpoint.tablet ? -30 : -40,\n })\n }\n\n if (el.productsPage) {\n lenisScroll.scrollTo(el.productsPage.querySelector('.products-page__dropdown'), {\n offset:\n el.productsPage.querySelector('.products-page__dropdown').offsetHeight -\n (window.innerWidth < breakpoint.tablet ? 30 : 40),\n })\n }\n\n if (el.searchPage) {\n lenisScroll.scrollTo(el.searchPage.querySelector('.search-page__column--search'), {\n offset:\n window.innerWidth < breakpoint.tablet ? el.searchPage.querySelector('.search-page__column--search').offsetHeight : -40,\n })\n }\n } else {\n lenisScroll.scrollTo(window.scrollY)\n }\n },\n\n toggleTab(button, event, preventDefault = false): void {\n if (preventDefault) {\n event.preventDefault()\n }\n\n const currentTabsContent = document.querySelector(`.tabs-content[id='${button.href.split('#')[1]}-tab']`)\n\n el.buttons.forEach((button) => {\n button.classList.remove('tabs__button--active')\n button.ariaExpanded = 'false'\n })\n\n currentTabsContent.parentElement.querySelectorAll('.tabs-content').forEach((tabsContent) => {\n tabsContent.classList.remove('tabs-content--active')\n })\n\n button.classList.add('tabs__button--active')\n button.ariaExpanded = 'true'\n currentTabsContent.classList.add('tabs-content--active')\n\n method.handleScrolling()\n },\n\n toggleTabOnHashChange(event): void {\n el.buttons.forEach((button) => {\n if (button.href.includes('#tab:')) {\n // Switching between tabs\n\n if (button.getAttribute('href').includes(window.location.hash)) {\n method.toggleTab(button, event)\n }\n\n // Opening first tab if no hash\n\n if (window.location.hash === '') {\n method.toggleTab(el.buttons[0], event)\n }\n }\n })\n },\n }\n\n method.init()\n },\n}\n\nexport default tabs\n"], "mappings": "oOAIA,IAAMA,EAAO,CACX,MAAa,CACX,SAAS,iBAA8B,OAAO,EAAE,QAASC,GAAwB,CAC/E,KAAK,WAAWA,CAAM,CACxB,CAAC,CACH,EAEA,WAAWA,EAAc,CACvB,IAAMC,EAAK,CACT,QAASD,EAAO,iBAAiB,eAAe,EAChD,SAAU,SAAS,cAAc,YAAY,EAC7C,aAAc,SAAS,cAAc,gBAAgB,EACrD,YAAa,SAAS,cAAc,SAAS,EAC7C,WAAY,SAAS,cAAc,cAAc,CACnD,EAEME,EAAS,CACb,MAAa,CAGXA,EAAO,sBAAsB,IAAI,EACjC,OAAO,iBAAiB,aAAcA,EAAO,qBAAqB,EAIlED,EAAG,QAAQ,QAASE,GAAW,CACxBA,EAAO,KAAK,SAAS,OAAO,GAC/BA,EAAO,iBAAiB,QAAUC,GAAU,CAC1CF,EAAO,UAAUC,EAAQC,EAAO,EAAI,CACtC,CAAC,CAEL,CAAC,EAIGH,EAAG,eACLA,EAAG,QAAQ,QAASE,GAAW,CAC7B,GAAIA,EAAO,KAAK,SAAS,OAAO,EAAG,CACjC,IAAME,EAAaC,EAAoB,IAAI,IAAIH,EAAO,IAAI,EAAG,YAAY,EACnEI,EAAOJ,EAAO,KAAK,MAAM,GAAG,EAAE,CAAC,EAErCA,EAAO,KAAQE,EAA2C,yBAAyBA,CAAU,WAAWE,CAAI,GAAhF,qBAAqBA,CAAI,EACvD,CACF,CAAC,EAEDN,EAAG,QAAQ,QAASE,GAAW,CAC7B,GAAIA,EAAO,KAAK,SAAS,OAAO,EAAG,CAEjC,IAAMK,EADc,SAAS,cAAc,mCAAmCL,EAAO,EAA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GF,EAAG,QAAQ,QAASE,GAAW,CAC7BA,EAAO,UAAU,OAAO,sBAAsB,EAC9CA,EAAO,aAAe,OACxB,CAAC,EAEDU,EAAmB,cAAc,iBAAiB,eAAe,EAAE,QAASC,GAAgB,CAC1FA,EAAY,UAAU,OAAO,sBAAsB,CACrD,CAAC,EAEDX,EAAO,UAAU,IAAI,sBAAsB,EAC3CA,EAAO,aAAe,OACtBU,EAAmB,UAAU,IAAI,sBAAsB,EAEvDX,EAAO,gBAAgB,CACzB,EAEA,sBAAsBE,EAAa,CACjCH,EAAG,QAAQ,QAASE,GAAW,CACzBA,EAAO,KAAK,SAAS,OAAO,IAG1BA,EAAO,aAAa,MAAM,EAAE,SAAS,OAAO,SAAS,IAAI,GAC3DD,EAAO,UAAUC,EAAQC,CAAK,EAK5B,OAAO,SAAS,OAAS,IAC3BF,EAAO,UAAUD,EAAG,QAAQ,CAAC,EAAGG,CAAK,EAG3C,CAAC,CACH,CACF,EAEAF,EAAO,KAAK,CACd,CACF,EAEOa,EAAQhB", "names": ["tabs", "target", "el", "method", "button", "event", "collection", "getParameterFromUrl", "hash", "pagination", "page", "lenisScroll", "breakpoint", "preventDefault", "currentTabsContent", "tabsContent", "tabs_default"] }