{"version":3,"file":"helpers-ce8cfe32.js","sources":["../../../src/js/modules/helpers.js"],"sourcesContent":["import FetchWrapper from './fetch-wrapper.js';\nconst thisWebsiteAPI = new FetchWrapper(`${window.location.protocol}//${window.location.host}` );\n\n// Add a class \"js-scrolled\" both on scroll and if the page is scrolled on load (e.g, on a refresh)\nfunction windowHasScrolled() {\n\tconst html = document.querySelector('html');\n\n\tif (window.scrollY > 0) {\n\t\thtml.classList.add('js-scrolled');\n\t} else {\n\t\thtml.classList.remove('js-scrolled');\n\t}\n}\n\n// Indicate to users that Sprig forms are doing something when submitted\ndocument.querySelectorAll('form[sprig]').forEach(sprigForm => {\n\tsprigForm.insertAdjacentHTML('beforeend', `\n\t\t\n\t`);\n\n\tlet dialog = sprigForm.querySelector('.sprigActionFeedback');\n\n\tdialog.querySelector('button').addEventListener('click', () => {\n\t\tdialog.close();\n\t});\n\n\tsprigForm.addEventListener('submit', () => {\n\t\tdialog.showModal();\n\t});\n});\n\n/**\n * Returns what type of interaction mechanism the current device uses\n * @returns {string}\n */\nexport function interactionType() {\n\tlet interactionType = 'mouseover';\n\n\tif( window.matchMedia('(hover: hover)') ) { // desktop\n\t\tinteractionType = 'mouseover'; }\n\tif( window.matchMedia('(hover: none) and (pointer: coarse)') ) { // touchscreen\n\t\tinteractionType = 'click'; }\n\tif( window.matchMedia('(hover: none) and (pointer: fine)') ) { // stylus\n\t\tinteractionType = 'click'; }\n\tif( window.matchMedia('(hover: hover) and (pointer: coarse)') ) { // Wii/Kinect/etc\n\t\tinteractionType = 'mouseover'; }\n\tif( window.matchMedia('(hover: hover) and (pointer: fine)') ) { // mouse\n\t\tinteractionType = 'mouseover'; }\n\n\treturn interactionType;\n}\n\n/**\n * Adds an event listener which will indicate if the page has scrolled by manipulating a class on the HTML element.\n */\nexport function initWindowHasScrolled() {\n\twindow.addEventListener('scroll', function() {\n\t\twindowHasScrolled();\n\t});\n}\n\nexport function timelineChange() {\n\tdocument.querySelectorAll('.period').forEach(period => {\n\t\tperiod.addEventListener('click', (e) => {\n\t\t\te.preventDefault();\n\t\t\tlet clickedLink = e.currentTarget;\n\t\t\tlet parser = new DOMParser();\n\t\t\tconsole.log(clickedLink);\n\t\t\tclickedLink.classList.toggle('open');\n\t\t});\n\t});\n}\n\n/**\n * Enable animated \"intro\" on blocks controlled by CSS when elements scroll into view\n */\nexport function initAnimatedIntroBlocks() {\n\tif (!!window.IntersectionObserver) {\n\t\tdocument.querySelector('html').classList.add('js-supportsIntersectionObserver');\n\n\t\tlet observer = new IntersectionObserver((watchList, observer) => {\n\t\t\twatchList.forEach(watchedElement => {\n\t\t\t\tif (watchedElement.isIntersecting) {\n\t\t\t\t\t// console.log(watchedElement);\n\n\t\t\t\t\twatchedElement.target.classList.add('js-inViewport');\n\t\t\t\t\tobserver.unobserve(watchedElement.target);\n\t\t\t\t}\n\t\t\t});\n\t\t}, {rootMargin: \"0px 0px -20% 0px\"});\n\n\t\tdocument.querySelectorAll('[data-scroll-reveal]').forEach(watchTarget => {\n\t\t\tobserver.observe(watchTarget);\n\t\t});\n\t}\n}\n\n/**\n * Handle anchors with a class of popup\n */\nexport function initPopups() {\n\tdocument.querySelectorAll('a.popup').forEach(popupLink => {\n\t\tpopupLink.addEventListener('click', (e) => {\n\t\t\te.preventDefault();\n\t\t\tlet clickedLink = e.currentTarget;\n\t\t\tlet parser = new DOMParser();\n\t\t\tclickedLink.classList.add('js-loading');\n\n\t\t\tthisWebsiteAPI.getHtml(clickedLink.getAttribute('href')).then(response => {\n\t\t\t\tlet responseAsDom = parser.parseFromString(response, \"text/html\");\n\t\t\t\tlet imageWeWant = responseAsDom.querySelector('#ajaxcontent').outerHTML;\n\t\t\t\tlet lightbox = document.querySelector('#lightbox') ?? null;\n\n\t\t\t\tif (lightbox) {\n\t\t\t\t\tdocument.querySelector('#lightbox .content').innerHTML = imageWeWant;\n\t\t\t\t\tlightbox.showModal();\n\t\t\t\t\tclickedLink.classList.remove('js-loading');\n\t\t\t\t} else {\n\t\t\t\t\tdocument.querySelector('body').insertAdjacentHTML('afterbegin', `\n\t\t\t\t\t\n\t\t\t\t`);\n\n\t\t\t\t\tlet lightbox = document.querySelector('#lightbox');\n\t\t\t\t\tlightbox.showModal();\n\t\t\t\t\tclickedLink.classList.remove('js-loading');\n\t\t\t\t}\n\t\t\t}).catch(error => {\n\t\t\t\tconsole.error(error);\n\t\t\t});\n\n\t\t\tconsole.log(clickedLink);\n\t\t});\n\t});\n\n\tdocument.querySelectorAll('a.popup-video').forEach(popupLink => {\n\t\tpopupLink.addEventListener('click', (e) => {\n\t\t\te.preventDefault();\n\t\t\tlet clickedLink = e.currentTarget;\n\t\t\tlet clickedUrl = new URL(clickedLink.href);\n\t\t\tlet videoId = clickedUrl.searchParams.get('v');\n\t\t\tlet videoWeWant = ``;\n\n\t\t\tclickedLink.classList.add('js-loading');\n\n\t\t\tdocument.querySelector('body').insertAdjacentHTML('afterbegin', `\n\t\t\t\n\t\t`);\n\n\t\t\tlet lightbox = document.querySelector('#lightbox') ?? null;\n\t\t\tlet theVideo = document.querySelector('#lightbox iframe');\n\n\t\t\tlightbox.showModal();\n\t\t\tclickedLink.classList.remove('js-loading');\n\n\t\t\t// remove the entire thing from the DOM when closed, to stop the video from continuing to play\n\t\t\tdocument.querySelector('#lightbox').addEventListener(\"close\", e => {\n\t\t\t\te.target.remove();\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * Adds a Dismiss button and behaviour to CMS generated Flash messages\n */\nexport function dismissNotice() {\n\tlet theNotice = document.querySelector(\"#notice:not(.cart)\");\n\n\tif (theNotice) {\n\t\ttheNotice.insertAdjacentHTML('beforeend', ``);\n\t\ttheNotice.querySelector('button').addEventListener('click', e => {\n\t\t\te.preventDefault();\n\t\t\ttheNotice.remove();\n\t\t});\n\t}\n}\n\n/**\n * Initiate the VAT toggle behaviour.\n * Inserts a toggle button, and handles all applicable prices.\n */\nexport function initVAT() {\n\tlet currentPreference = getPreferredVAT();\n\n\t/* Get the nav item we'll punt the dynamic toggle button before */\n\tconst changeState = document.querySelector('.nav_secondary');\n\n\tlet buttonToggle = `\n\t\t