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FrB,KAAKsC,MAAMJ,UAAUE,IAAI,QACzBb,SAASgB,KAAKL,UAAUE,IAAI,YAAY,GAG9C,CA3FAK,WAAAA,CAAYC,GACV1C,KAAK2C,UAAYD,EACjB1C,KAAKG,OAASoB,SAASC,cAAc,gBACrCxB,KAAKC,SAAWsB,SAASqB,eAAe,cACxC5C,KAAKgB,MAAQhB,KAAK2C,UAAUb,iBAAiB,kCAC7C9B,KAAKsC,MAAQtC,KAAK2C,UAAUnB,cAAc,mCAC1CxB,KAAKwC,UAAYxC,KAAK2C,UAAUnB,cAAc,oCAC9CxB,KAAKqC,WAAarC,KAAK2C,UAAUnB,cAAc,mCAC/CxB,KAAK0B,eAAiB1B,KAAK2C,UAAUb,iBAAiB,qCAEtD9B,KAAKe,MACP,ECZa,IAAkB8B,ID+FxB,KACP,MAAMC,EAAYvB,SAASO,iBAAiB,4BAC1B,OAAdgB,GACFA,EAAU7B,SAAQ8B,GAAa,IAAIzD,EAAeyD,IACpD,EClG4B,YAAxBxB,SAASyB,WACXH,IAEAtB,SAASJ,iBAAiB,oBAAoB,KAC5C0B,GAAU,G","sources":["webpack://golf-wp/./wp-content/themes/golf/src/js/blocks/product-roundup.js","webpack://golf-wp/./wp-content/themes/golf/src/js/utils/DOMReady.js"],"sourcesContent":["import DOMReady from '../utils/DOMReady'\n\n// eslint-disable-next-line no-unused-vars\nimport css from '../../css/blocks/product-roundup.scss'\n\nclass ProductRoundUp {\n constructor(el) {\n this.container = el\n this.header = document.querySelector('.site-header')\n this.adminBar = document.getElementById('wpadminbar')\n this.links = this.container.querySelectorAll('.g-block-product-roundup__link')\n this.modal = this.container.querySelector('.g-block-product-roundup__modal')\n this.openModal = this.container.querySelector('.g-block-product-roundup__toggle')\n this.closeModal = this.container.querySelector('.g-block-product-roundup__close')\n this.compareModules = this.container.querySelectorAll('.g-block-product-roundup__compare')\n\n this.init()\n }\n\n /**\n * Scroll to the section\n *\n * @param {HTMLElement} section The section element\n */\n scroll(section) {\n const scrollPos = window.scrollY || window.pageYOffset\n const rect = section.getBoundingClientRect()\n const paddingSize = this.adminBar\n ? this.adminBar.offsetHeight + this.header.offsetHeight\n : this.header.offsetHeight\n\n window.scroll({\n top: scrollPos + rect.top - (paddingSize + 20),\n behavior: 'smooth',\n })\n }\n\n /**\n * Push History State with Hash\n *\n * @param {String} hash\n */\n pushHistory(hash) {\n const url = new URL(window.location.href)\n url.hash = hash\n window.history.pushState(null, null, url.toString())\n }\n\n init() {\n if (this.links) {\n this.links.forEach(link => {\n link.addEventListener('click', e => {\n e.preventDefault()\n const href = link.getAttribute('href')\n const section = document.querySelector(href)\n if (section) {\n this.pushHistory(href)\n this.scroll(section)\n }\n e.stopPropagation()\n })\n })\n }\n\n if (this.compareModules) {\n this.compareModules.forEach(compareContainer => {\n const select = compareContainer.querySelector('select')\n const cards = compareContainer.querySelectorAll('.g-block-product-roundup__compare__card')\n\n select.addEventListener('input', e => {\n e.preventDefault()\n const target = compareContainer.querySelector(`[data-target=\"${select.value}\"]`)\n if (target) {\n cards.forEach(card => {\n card.classList.remove('selected')\n })\n target.classList.add('selected')\n }\n })\n })\n }\n\n if (this.closeModal) {\n this.closeModal.addEventListener('click', e => {\n e.preventDefault()\n this.modal.classList.remove('open')\n document.body.classList.remove('no-scroll')\n })\n }\n\n if (this.openModal) {\n this.openModal.addEventListener('click', e => {\n e.preventDefault()\n this.modal.classList.add('open')\n document.body.classList.add('no-scroll')\n })\n }\n }\n}\n\nDOMReady(() => {\n const wrapperEl = document.querySelectorAll('.g-block-product-roundup')\n if (wrapperEl !== null) {\n wrapperEl.forEach(component => new ProductRoundUp(component))\n }\n})\n","/**\n * Triggers a callback function once the DOM is ready\n *\n * @param {function} callback The function to trigger\n */\nexport default function DOMReady(callback) {\n if (document.readyState !== 'loading') {\n callback()\n } else {\n document.addEventListener('DOMContentLoaded', () => {\n callback()\n })\n }\n}\n"],"names":["ProductRoundUp","scroll","section","scrollPos","window","scrollY","pageYOffset","rect","getBoundingClientRect","paddingSize","this","adminBar","offsetHeight","header","top","behavior","pushHistory","hash","url","URL","location","href","history","pushState","toString","init","links","forEach","link","addEventListener","e","preventDefault","getAttribute","document","querySelector","stopPropagation","compareModules","compareContainer","select","cards","querySelectorAll","target","value","card","classList","remove","add","closeModal","modal","body","openModal","constructor","el","container","getElementById","callback","wrapperEl","component","readyState"],"sourceRoot":""}