{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/loader.ts"], "sourcesContent": ["import { breakpoint } from 'utility/breakpoints'\nimport gsap from 'gsap'\n\nconst loader = {\n el: {\n header: document.querySelector('.header'),\n links: {\n all: document.querySelectorAll(`\n .header__logo,\n .header__navigation-link,\n .header__book-time-button,\n .mobile-header__logo,\n .mobile-header__menu-link,\n .featured-block__button,\n .featured-products-block__button,\n .footer__navigation-link,\n .footer__contact-button\n `),\n cartTriggers: document.querySelectorAll('.header__cart-trigger, .mobile-header__cart-trigger'),\n footer: document.querySelectorAll('.footer__navigation-link'),\n header: document.querySelectorAll('.header__navigation-link'),\n mobile: document.querySelectorAll('.mobile-header__menu-link'),\n },\n loader: document.querySelector('.loader'),\n productsBannerWhiteBackground: document.querySelector('.products-banner__white-background'),\n },\n\n init(): void {\n if (sessionStorage.getItem('pageLoaded') !== 'true') {\n this.initialPageLoad()\n }\n\n if (sessionStorage.getItem('pageTransition') === 'true') {\n this.renderSquares(this.calculateAmount())\n this.setPosition()\n this.animateOnPageEnter()\n }\n\n this.el.links.all.forEach((link) => {\n link.addEventListener('click', (event) => {\n this.redirect(event, link)\n })\n })\n\n this.el.links.cartTriggers.forEach((link) => {\n link.addEventListener('click', (event) => {\n if (Number.parseFloat(link.dataset.count) < 1) {\n this.redirect(event, link)\n }\n })\n })\n },\n\n animateOnPageEnter(): void {\n this.handleProductsBanner('onPageEnter')\n\n gsap.fromTo(\n this.el.loader.children,\n {\n opacity: 1,\n },\n {\n duration: 0.3,\n ease: 'none',\n onComplete: () => {\n sessionStorage.setItem('pageTransition', 'false')\n },\n opacity: 0,\n stagger: 0.006,\n }\n )\n },\n\n animateOnPageLeave(link): void {\n gsap\n .timeline()\n .set(document.body, { pointerEvents: 'none' })\n .to(this.el.loader.children, {\n duration: 0.2,\n ease: 'none',\n onComplete: () => {\n sessionStorage.setItem('pageTransition', 'true')\n window.location.href = link.getAttribute('href')\n },\n onStart: () => {\n this.handleActiveLink(link)\n this.handleProductsBanner('onPageLeave')\n },\n opacity: 1,\n stagger: 0.006,\n })\n },\n\n calculateAmount(): number {\n const viewportWidth = window.innerWidth\n const viewportHeight = window.innerHeight\n const columnCount =\n viewportWidth < breakpoint.tablet ? 4 : viewportWidth < breakpoint.desktop.s ? 6 : viewportWidth < breakpoint.desktop.l ? 8 : 12\n const squareWidth = viewportWidth / columnCount\n const squaresHorizontal = Math.floor(viewportWidth / squareWidth)\n const squaresVertical = Math.floor(viewportHeight / squareWidth)\n const totalSquares = squaresHorizontal * squaresVertical\n\n return totalSquares + columnCount\n },\n\n handleActiveLink(link): void {\n this.el.links.footer.forEach((link) => link.classList.remove('footer__navigation-link--active'))\n this.el.links.header.forEach((link) => link.classList.remove('header__navigation-link--active'))\n this.el.links.mobile.forEach((link) => link.classList.remove('mobile-header__menu-link--active'))\n\n link.classList.contains('footer__navigation-link') && link.classList.add('footer__navigation-link--active')\n link.classList.contains('header__navigation-link') && link.classList.add('header__navigation-link--active')\n link.classList.contains('mobile-header__menu-link') && link.classList.add('mobile-header__menu-link--active')\n },\n\n handleProductsBanner(action): void {\n if (!this.el.productsBannerWhiteBackground) {\n return\n }\n\n switch (action) {\n case 'onPageLeave':\n gsap.to(this.el.productsBannerWhiteBackground, {\n duration: 0.321,\n ease: 'none',\n opacity: 1,\n })\n\n this.el.header.classList.remove('header--black-friday')\n break\n case 'onPageEnter':\n gsap\n .timeline()\n .set(this.el.productsBannerWhiteBackground, {\n opacity: 1,\n })\n .to(\n this.el.productsBannerWhiteBackground,\n {\n clearProps: 'all',\n duration: 1.234,\n ease: 'power3.out',\n opacity: 0,\n },\n 0.1\n )\n break\n }\n },\n\n initialPageLoad(): void {\n document.body.classList.remove('preload')\n\n gsap\n .timeline()\n .set(this.el.loader, {\n background: '#fff',\n zIndex: 999,\n })\n .to(this.el.loader, {\n clearProps: 'all',\n delay: 0.234,\n duration: 1.234,\n ease: 'power3.out',\n opacity: 0,\n })\n .call(\n () => {\n sessionStorage.setItem('pageLoaded', 'true')\n },\n null,\n '<0.5'\n )\n },\n\n redirect(event, link): void {\n if (link.getAttribute('href') !== window.location.pathname) {\n event.preventDefault()\n this.renderSquares(this.calculateAmount())\n this.setPosition()\n this.animateOnPageLeave(link)\n }\n },\n\n renderSquares(amount): void {\n this.el.loader.innerHTML = ''\n\n Array.from({ length: amount }).forEach(() => {\n this.el.loader.insertAdjacentHTML('beforeend', '
')\n })\n },\n\n setPosition(): void {\n const top = this.el.header.getBoundingClientRect().bottom\n\n gsap.set(this.el.loader, {\n top: top > 0 && window.innerWidth >= breakpoint.tablet ? top : 0,\n })\n },\n}\n\nexport default loader\n"], "mappings": "mFAGA,IAAMA,EAAS,CACb,GAAI,CACF,OAAQ,SAAS,cAA2B,SAAS,EACrD,MAAO,CACL,IAAK,SAAS,iBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAU3C,EACD,aAAc,SAAS,iBAA8B,qDAAqD,EAC1G,OAAQ,SAAS,iBAA8B,0BAA0B,EACzE,OAAQ,SAAS,iBAA8B,0BAA0B,EACzE,OAAQ,SAAS,iBAA8B,2BAA2B,CAC5E,EACA,OAAQ,SAAS,cAA2B,SAAS,EACrD,8BAA+B,SAAS,cAA2B,oCAAoC,CACzG,EAEA,MAAa,CACP,eAAe,QAAQ,YAAY,IAAM,QAC3C,KAAK,gBAAgB,EAGnB,eAAe,QAAQ,gBAAgB,IAAM,SAC/C,KAAK,cAAc,KAAK,gBAAgB,CAAC,EACzC,KAAK,YAAY,EACjB,KAAK,mBAAmB,GAG1B,KAAK,GAAG,MAAM,IAAI,QAASC,GAAS,CAClCA,EAAK,iBAAiB,QAAUC,GAAU,CACxC,KAAK,SAASA,EAAOD,CAAI,CAC3B,CAAC,CACH,CAAC,EAED,KAAK,GAAG,MAAM,aAAa,QAASA,GAAS,CAC3CA,EAAK,iBAAiB,QAAUC,GAAU,CACpC,OAAO,WAAWD,EAAK,QAAQ,KAAK,EAAI,GAC1C,K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9D,CAAC,CACH,EAEA,aAAoB,CAClB,IAAMC,EAAM,KAAK,GAAG,OAAO,sBAAsB,EAAE,OAEnDV,EAAK,IAAI,KAAK,GAAG,OAAQ,CACvB,IAAKU,EAAM,GAAK,OAAO,YAAcN,EAAW,OAASM,EAAM,CACjE,CAAC,CACH,CACF,EAEOC,EAAQd", "names": ["loader", "link", "event", "gsapWithCSS", "viewportWidth", "viewportHeight", "columnCount", "breakpoint", "squareWidth", "squaresHorizontal", "squaresVertical", "action", "amount", "top", "loader_default"] }