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AAKQ,qBAEN,S,4BAIP,WAAiB,WACTI,EAAc,IAAIC,YAAY,gBAAiB,CACnDC,SAAS,EACTC,OAAQ,CACNC,YAAavC,SAASC,OACtBuC,YAAa,WACX,OAAOL,EAAYG,OAAOC,cAAgBvC,SAASC,SAE9CkC,EAAYG,OAAOC,YAAcvC,SAASC,SAEjDwC,kBAAmB,WACjBR,aAAY,WACNE,EAAYG,OAAOE,eACrBL,EAAYG,OAAOI,SAAU,EAC7BP,EAAYQ,OAAOC,cAAcT,IAEjCA,EAAYG,OAAOI,SAAU,IAE9B,MAELA,SAAS,KAIb1C,SAAS6C,iBAAiB,iBAAiB,SAACC,GAC1CA,EAAER,OAAOG,qBACgB,IAArBK,EAAER,OAAOI,SACX,EAAK/C,yBAOTiC,OAAOiB,iBAAiB,QAJM,SAACC,GAC7BA,EAAEH,OAAOC,cAAcT,W,gFA5GRhD,G","sources":["webpack://jcb-golf/./src/js/components/hero.js"],"sourcesContent":["export default class hero {\r\n constructor(el) {\r\n this.el = el;\r\n this.vimeoPlayer = null;\r\n this.cookieRequirements = {\r\n name: 'OptanonConsent',\r\n value: 'C0003%3A1',\r\n };\r\n this.init();\r\n }\r\n\r\n init() {\r\n this.shouldVideoBePlayed();\r\n this.cookieObserver();\r\n }\r\n\r\n shouldVideoBePlayed() {\r\n if (this.checkForCookieValue(this.cookieRequirements.name, this.cookieRequirements.value)) {\r\n this.createVimeoScript();\r\n this.loadVimeoVideo();\r\n }\r\n }\r\n\r\n checkForCookieValue(name, value) {\r\n var match = document.cookie.match(new RegExp('(^| )(' + name + '=)([^;]+|)(' + value + ')'));\r\n return match;\r\n }\r\n\r\n createVimeoScript() {\r\n var tag = document.createElement('script');\r\n tag.src = 'https://player.vimeo.com/api/player.js';\r\n var firstScriptTag = document.getElementsByTagName('script')[0];\r\n firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\r\n }\r\n\r\n bindVimeoEvents() {\r\n this.vimeoPlayer.setVolume(0);\r\n this.vimeoPlayer.setLoop(true);\r\n this.vimeoPlayer.play();\r\n this.vimeoPlayer.ready().then(function () {\r\n var muteVideo = true;\r\n document.querySelector('.hero--vimeo-video').classList.add('vimeo-loaded');\r\n });\r\n }\r\n\r\n loadVimeoVideo() {\r\n const vimeoHero = document.querySelector('.hero--vimeo-video');\r\n if (!vimeoHero) {\r\n return;\r\n }\r\n\r\n const vimeoUrl = vimeoHero.getAttribute('data-vimeo-url');\r\n if (vimeoUrl === '' || vimeoUrl === null) {\r\n return;\r\n }\r\n const regex = '/(player.vimeo.com/)((video/))?([0-9]+)|(vimeo.com/)?([0-9]+)/g';\r\n const urlWithoutParams = vimeoUrl.match(regex)[0];\r\n const vimeoID = urlWithoutParams.substring(urlWithoutParams.lastIndexOf('/') + 1);\r\n let vimeoOptions = {\r\n id: vimeoID,\r\n loop: 1,\r\n };\r\n\r\n if (window.Vimeo) {\r\n this.vimeoPlayer = new Vimeo.Player('hero--vimeo-video', vimeoOptions);\r\n this.bindVimeoEvents();\r\n } else {\r\n this.vimeoIntervalID = setInterval(() => {\r\n if (window.Vimeo) {\r\n window.clearInterval(this.vimeoIntervalID);\r\n this.vimeoPlayer = new Vimeo.Player('hero--vimeo-video', vimeoOptions);\r\n this.bindVimeoEvents();\r\n }\r\n }, 200);\r\n }\r\n }\r\n\r\n cookieObserver() {\r\n const cookieEvent = new CustomEvent('cookieChanged', {\r\n bubbles: true,\r\n detail: {\r\n cookieValue: document.cookie,\r\n checkChange: () => {\r\n return cookieEvent.detail.cookieValue === document.cookie\r\n ? false\r\n : (cookieEvent.detail.cookieValue = document.cookie);\r\n },\r\n listenCheckChange: () => {\r\n setInterval(() => {\r\n if (cookieEvent.detail.checkChange()) {\r\n cookieEvent.detail.changed = true;\r\n cookieEvent.target.dispatchEvent(cookieEvent);\r\n } else {\r\n cookieEvent.detail.changed = false;\r\n }\r\n }, 1000);\r\n },\r\n changed: false,\r\n },\r\n });\r\n\r\n document.addEventListener('cookieChanged', (e) => {\r\n e.detail.listenCheckChange();\r\n if (e.detail.changed === true) {\r\n this.shouldVideoBePlayed();\r\n }\r\n });\r\n const cookieEventDispatcher = (e) => {\r\n e.target.dispatchEvent(cookieEvent);\r\n };\r\n\r\n window.addEventListener('load', cookieEventDispatcher);\r\n }\r\n}\r\n"],"names":["hero","el","this","vimeoPlayer","cookieRequirements","name","value","init","shouldVideoBePlayed","cookieObserver","checkForCookieValue","createVimeoScript","loadVimeoVideo","document","cookie","match","RegExp","tag","createElement","src","firstScriptTag","getElementsByTagName","parentNode","insertBefore","setVolume","setLoop","play","ready","then","querySelector","classList","add","vimeoHero","vimeoUrl","getAttribute","urlWithoutParams","vimeoOptions","id","substring","lastIndexOf","loop","window","Vimeo","Player","bindVimeoEvents","vimeoIntervalID","setInterval","clearInterval","cookieEvent","CustomEvent","bubbles","detail","cookieValue","checkChange","listenCheckChange","changed","target","dispatchEvent","addEventListener","e"],"sourceRoot":""}