{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/mobileNavigation.ts"], "sourcesContent": ["////\r\n/// @group Components\r\n////\r\n\r\n// import gsap from 'gsap'\r\nimport { breakpoints } from 'utility/helpers'\r\n\r\nlet lastWindowHeight = 0\r\n\r\nexport interface INavigation {\r\n /** @description Elements */\r\n el: {\r\n allNavigationLinks: NodeListOf\r\n header: HTMLElement\r\n mainList: HTMLElement\r\n wrapper: HTMLElement\r\n menu: HTMLElement\r\n languageButton: HTMLElement\r\n myPagesButton: HTMLElement\r\n trigger: HTMLElement\r\n backTriggers: NodeListOf\r\n forwardTriggers: NodeListOf\r\n hamburger: HTMLElement\r\n }\r\n\r\n /** @description Init method */\r\n init: () => void\r\n\r\n /** @description Forward clicks */\r\n handleMobileNavigationLevels: () => void\r\n\r\n /** @description Back clicks */\r\n hideMobileNavigation: () => void\r\n\r\n /** @description Resets and hides mobile navigation */\r\n hideMobileNavigationOnResize: () => void\r\n\r\n /** @description Shows mobile nav on. */\r\n showMobileNavigation: () => void\r\n\r\n /** @description Show and hide */\r\n toggleMobileNavigation: () => void\r\n\r\n /** @description Open and close */\r\n toggleSelected: (HTMLElement) => void\r\n\r\n /** @description Checks if able to scroll and shows shadow depending */\r\n checkForScroll: () => void\r\n\r\n /** @description Check screensize and modify mypages button*/\r\n handleMyPagesButton: () => void\r\n\r\n /** @description Check screensize and modify language button */\r\n handleLanguageButton: () => void\r\n}\r\n\r\nconst MobileNavigation: INavigation = {\r\n el: {\r\n allNavigationLinks: document.querySelectorAll('.navigation-mobile__link') as NodeListOf,\r\n header: document.querySelector('.header-trigger'),\r\n wrapper: document.querySelector('.header__wrap'),\r\n mainList: document.querySelector('.navigation-mobile > .navigation-mobile__list'),\r\n trigger: document.querySelector('.hamburger-trigger'),\r\n backTriggers: document.querySelectorAll('.navigation-mobile-backward-trigger') as NodeListOf,\r\n forwardTriggers: document.querySelectorAll('.navigation-mobile-forward-trigger') as NodeListOf,\r\n menu: document.querySelector('.mobile-menu'),\r\n myPagesButton: document.querySelector('.header__links--mypages'),\r\n languageButton: document.querySelector('.header__links--language'),\r\n hamburger: document.querySelector('.hamburger'),\r\n },\r\n\r\n init() {\r\n MobileNavigation.hideMobileNavigation()\r\n window.addEventListener('resize', MobileNavigation.hideMobileNavigationOnResize)\r\n\r\n MobileNavigation.handleMyPagesButton()\r\n window.addEventListener('resize', MobileNavigation.handleMyPagesButton)\r\n\r\n MobileNavigation.handleLanguageButton()\r\n window.addEventListener('resize', MobileNavigation.handleLanguageButton)\r\n\r\n\r\n if (MobileNavigation.el.trigger) {\r\n MobileNavigation.el.trigger.addEventListener('click', MobileNavigation.toggleMobileNavigation)\r\n }\r\n MobileNavigation.handleMobileNavigationLevels()\r\n MobileNavigation.checkForScroll()\r\n\r\n },\r\n\r\n handleMyPagesButton() {\r\n const currentWidth = window.innerWidth\r\n if (currentWidth >= 1200) {\r\n MobileNavigation.el.myPagesButton.classList.add('button--square')\r\n } else {\r\n MobileNavigation.el.myPagesButton.classList.remove('button--square')\r\n }\r\n },\r\n\r\n handleLanguageButton() {\r\n const text = MobileNavigation.el.languageButton.querySelector('.button__text')\r\n const currentWidth = window.innerWidth\r\n if (currentWidth >= 1200) {\r\n MobileNavigation.el.languageButton.classList.add('button--square')\r\n MobileNavigation.el.languageButton.classList.remove('button--border-primary')\r\n MobileNavigation.el.languageButton.classList.remove('button--compact')\r\n text.textContent = MobileNavigation.el.languageButton.title\r\n } else {\r\n MobileNavigation.el.languageButton.classList.remove('button--square')\r\n MobileNavigation.el.languageButton.classList.add('button--border-primary')\r\n MobileNavigation.el.languageButton.classList.add('button--compact')\r\n\r\n let ariaLabel = MobileNavigation.el.languageButton.ariaLabel\r\n const label = ariaLabel.charAt(0).toUpperCase() + ariaLabel.slice(1);\r\n text.textContent = label\r\n }\r\n },\r\n\r\n checkForScroll() {\r\n const wrap = document.querySelector('.header__wrap')\r\n if (!wrap) return\r\n const hasVerticalScrollbar = wrap.scrollHeight > wrap.clientHeight;\r\n\r\n if (hasVerticalScrollbar) {\r\n MobileNavigation.el.menu.classList.add('mobile-menu--shadow')\r\n } else {\r\n MobileNavigation.el.menu.classList.remove('mobile-menu--shadow')\r\n }\r\n },\r\n\r\n\r\n\r\n handleMobileNavigationLevels() {\r\n MobileNavigation.el.forwardTriggers.forEach((trigger) => {\r\n trigger.addEventListener('click', (event) => {\r\n if (window.innerWidth < breakpoints.desktopM) {\r\n //* parent ul child items\r\n const currentItems = Array.from(trigger.closest('.navigation-mobile__list').children)\r\n\r\n //* the ul you want to open\r\n const activeList = trigger.nextElementSibling\r\n\r\n //* parent li item\r\n const activeCurrentItem = trigger.parentElement\r\n\r\n //* child li items\r\n const activeItems = Array.from(trigger.nextElementSibling.children)\r\n console.log(activeItems + \"activeItems\")\r\n activeItems.forEach((item) => item.classList.remove('navigation-mobile__item--hidden'))\r\n\r\n //* mobile__link item\r\n const link = trigger.previousElementSibling\r\n\r\n activeList.classList.add('navigation-mobile__list--active')\r\n activeCurrentItem.classList.add('navigation-mobile__item--active')\r\n trigger.classList.add('navigation-mobile__link--hidden')\r\n\r\n if (link) {\r\n link.classList.add('navigation-mobile__link--hidden')\r\n }\r\n\r\n currentItems.forEach((item) => {\r\n item.classList.remove('navigation-mobile__item--hidden')\r\n\r\n if (!item.classList.contains('navigation-mobile__item--active'))\r\n item.classList.add('navigation-mobile__item--hidden')\r\n })\r\n\r\n MobileNavigation.checkForScroll()\r\n event.preventDefault()\r\n }\r\n })\r\n })\r\n\r\n MobileNavigation.el.backTriggers.forEach((trigger) => {\r\n trigger.addEventListener('click', (event) => {\r\n const currentList = trigger.closest('.navigation-mobile__list')\r\n const currentItem = currentList.parentElement\r\n const currentLink = currentItem.querySelector('.navigation-mobile__link')\r\n const parentItems = Array.from(currentItem.parentElement.children)\r\n const currentLinkButton = currentList.previousElementSibling\r\n\r\n currentList.classList.remove('navigation-mobile__list--active')\r\n currentItem.classList.remove('navigation-mobile__item--active')\r\n currentLink.classList.remove('navigation-mobile__link--hidden')\r\n currentLinkButton.classList.remove('navigation-mobile__link--hidden')\r\n\r\n parentItems.forEach((item) => item.classList.remove('navigation-mobile__item--hidden'))\r\n\r\n MobileNavigation.checkForScroll()\r\n event.preventDefault()\r\n })\r\n })\r\n },\r\n\r\n hideMobileNavigation() {\r\n document.documentElement.classList.remove('h--disable-scroll')\r\n MobileNavigation.el.header.classList.remove('header--navigation-active')\r\n MobileNavigation.el.hamburger.classList.remove('open')\r\n\r\n if (!MobileNavigation.el.mainList) return // last minute hack for en/pl versions with no navigation\r\n },\r\n\r\n hideMobileNavigationOnResize() {\r\n const currentHeight = window.innerHeight\r\n const verticalResize = currentHeight !== lastWindowHeight\r\n lastWindowHeight = currentHeight\r\n\r\n if (!verticalResize) MobileNavigation.hideMobileNavigation()\r\n },\r\n\r\n showMobileNavigation() {\r\n document.documentElement.classList.add('h--disable-scroll')\r\n MobileNavigation.el.header.classList.add('header--navigation-active')\r\n MobileNavigation.el.hamburger.classList.add('open')\r\n\r\n MobileNavigation.checkForScroll()\r\n },\r\n\r\n toggleMobileNavigation() {\r\n if (!MobileNavigation.el.header.classList.contains('header--navigation-active')) {\r\n MobileNavigation.showMobileNavigation()\r\n } else {\r\n MobileNavigation.hideMobileNavigation()\r\n }\r\n },\r\n\r\n toggleSelected(link) {\r\n if (!MobileNavigation.el.mainList) return // last minute hack for en/pl versions with no navigation\r\n\r\n const currentItem = MobileNavigation.el.mainList.querySelector('.navigation-mobile__item--selected')\r\n const selectedItem = link.closest('.navigation-mobile__item')\r\n\r\n if (currentItem) currentItem.classList.add('navigation-mobile__item--unselected')\r\n if (selectedItem) selectedItem.classList.add('navigation-mobile__item--selected')\r\n },\r\n}\r\n\r\nexport default MobileNavigation\r\n"], "mappings": "4EAOA,IAAIA,EAAmB,EAiDjBC,EAAgC,CACpC,GAAI,CACF,mBAAoB,SAAS,iBAAiB,0BAA0B,EACxE,OAAQ,SAAS,cAAc,iBAAiB,EAChD,QAAS,SAAS,cAAc,eAAe,EAC/C,SA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"wrap", "trigger", "event", "breakpoints", "currentItems", "activeList", "activeCurrentItem", "activeItems", "item", "link", "currentList", "currentItem", "currentLink", "parentItems", "currentLinkButton", "currentHeight", "verticalResize", "selectedItem", "mobileNavigation_default"] }