{"version":3,"file":"parallax.js","sources":["../../../../s/BiNo.ReactApps/apps/scripts/src/parallax.ts"],"sourcesContent":["import { onReady } from './util/onReady';\r\n\r\nfunction toggleNav(show: boolean, navbar: HTMLElement, logo: HTMLElement, peg: HTMLElement) {\r\n navbar.classList.toggle('active', show);\r\n logo.classList.toggle('hide', show);\r\n peg.classList.toggle('visible', show);\r\n}\r\n\r\nfunction toggleLabel(show: boolean, labelELementInLogo: HTMLElement, labelElementInTopMenuContainer: HTMLElement) {\r\n labelELementInLogo.classList.toggle('show', show);\r\n labelElementInTopMenuContainer.classList.toggle('hide', show);\r\n}\r\n\r\nfunction initParallax() {\r\n if (document.querySelector('.js-parallax') === null) return;\r\n\r\n const logo = document.querySelector('.original') as HTMLElement;\r\n const navbar = document.querySelector('.business-review-nav') as HTMLElement;\r\n const origY = logo.offsetTop;\r\n const peg = document.querySelector('.peg') as HTMLElement;\r\n let lastY = window.scrollY;\r\n const focusElements = document.querySelectorAll('[data-js-focus-listener]');\r\n const labelElementInTopMenu = document.querySelector('.business-review-label') as HTMLElement;\r\n const labelElementInTopMenuContainer = document.querySelector('.business-review-label-container') as HTMLElement;\r\n const labelElementInLogo = document.querySelector('.business-review-label-in-logo-parallax') as HTMLElement;\r\n\r\n focusElements.forEach((el) => el.addEventListener('focus', scrollToShowNav));\r\n\r\n function scrollToShowNav() {\r\n if (lastY < origY) {\r\n window.scrollTo({\r\n top: origY,\r\n behavior: 'smooth',\r\n });\r\n }\r\n }\r\n\r\n document.addEventListener('scroll', () => {\r\n const newY = window.scrollY;\r\n const up = newY < lastY;\r\n const down = newY > lastY;\r\n lastY = newY;\r\n\r\n const scrollStream = {\r\n y: newY,\r\n up: up,\r\n down: down,\r\n };\r\n\r\n if (scrollStream.down && scrollStream.y >= logo.offsetTop && !navbar.classList.contains('active'))\r\n toggleNav(true, navbar, logo, peg);\r\n\r\n if (\r\n scrollStream.up &&\r\n scrollStream.y + navbar.offsetHeight <= origY + logo.offsetHeight &&\r\n navbar.classList.contains('active')\r\n )\r\n toggleNav(false, navbar, logo, peg);\r\n\r\n if (!navbar.classList.contains('active')) {\r\n let delta: string | number = origY - scrollStream.y;\r\n\r\n // The logo should never be able to disappear from the screen-\r\n if (delta <= 0) delta = 0;\r\n\r\n // And the logo should never be lower than its original point.\r\n if (delta >= origY || scrollStream.y <= 30) delta = '';\r\n\r\n logo.style.top = typeof delta === 'number' ? `${delta}px` : '';\r\n }\r\n\r\n if (labelElementInTopMenuContainer) {\r\n const top = labelElementInTopMenu.getBoundingClientRect().top + window.scrollY;\r\n const elementHeight = labelElementInTopMenu.offsetHeight;\r\n const labelDelta = top + elementHeight;\r\n\r\n toggleLabel(scrollStream.y > labelDelta, labelElementInLogo, labelElementInTopMenuContainer);\r\n }\r\n });\r\n\r\n /*\r\n * Initially, if the scroll is lower than the logo, then we need to\r\n * activate the local navigation and ensure the logo is at the top of\r\n * its container.\r\n */\r\n if (window.scrollY >= origY) {\r\n toggleNav(true, navbar, logo, peg);\r\n }\r\n}\r\n\r\nonReady(() => {\r\n initParallax();\r\n});\r\n"],"names":["toggleNav","show","navbar","logo","peg","toggleLabel","labelELementInLogo","labelElementInTopMenuContainer","initParallax","origY","lastY","focusElements","labelElementInTopMenu","labelElementInLogo","el","scrollToShowNav","newY","up","down","scrollStream","delta","top","elementHeight","labelDelta","onReady"],"mappings":"0CAEA,SAASA,EAAUC,EAAeC,EAAqBC,EAAmBC,EAAkB,CACjFF,EAAA,UAAU,OAAO,SAAUD,CAAI,EACjCE,EAAA,UAAU,OAAO,OAAQF,CAAI,EAC9BG,EAAA,UAAU,OAAO,UAAWH,CAAI,CACxC,CAEA,SAASI,EAAYJ,EAAeK,EAAiCC,EAA6C,CAC3FD,EAAA,UAAU,OAAO,OAAQL,CAAI,EACjBM,EAAA,UAAU,OAAO,OAAQN,CAAI,CAChE,CAEA,SAASO,GAAe,CACpB,GAAI,SAAS,cAAc,cAAc,IAAM,KAAM,OAE/C,MAAAL,EAAO,SAAS,cAAc,WAA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