{"version":3,"sources":["webpack:///./js/components/init-video-autoplay.ts"],"names":["handleAutoplay","video","promise","play","undefined","then","catch","videoParent","parentNode","overlay","document","createElement","classList","add","playHolder","innerHTML","appendChild","overlayVideo","addEventListener","querySelector","remove","playVideoOnClick","whenDomReady","querySelectorAll","forEach","item"],"mappings":"2FAAA,mBACA,MAkCMA,EAAkBC,IACpB,MAAMC,EAAUD,EAAME,YACNC,IAAZF,GACAA,EAAQG,KAAK,QAEVC,MAAM,KAnCKL,KAClB,MAAMM,EAAcN,EAAMO,WAC1B,IAAKD,EACD,OACJ,MAAME,EAAUC,SAASC,cAAc,OACvCF,EAAQG,UAAUC,IATI,mCAUtB,MAAMC,EAAaJ,SAASC,cAAc,OAC1CG,EAAWF,UAAUC,IAVI,2BAWzBC,EAAWC,UAAY,sIACvBR,EAAYK,UAAUC,IAXH,cAYnBN,EAAYK,UAAUC,IAXM,kCAY5BN,EAAYS,YAAYP,GACxBF,EAAYS,YAAYF,IAyBhBG,CAAahB,GAvBCA,KACtB,MAAMM,EAAcN,EAAMO,WACrBD,GAELA,EAAYW,iBAAiB,QAAS,KAClC,MAAMT,EAAUF,EAAYY,cAAZ,WAvBE,oCAwBZL,EAAaP,EAAYY,cAAZ,WAvBE,4BAwBfV,GAAWK,IAEjBL,EAAQW,SACRN,EAAWM,SACXb,EAAYK,UAAUQ,OA1BE,kCA2BxBb,EAAYK,UAAUQ,OA5BP,cA6BfnB,EAAME,WAWFkB,CAAiBpB,MAQ7BqB,cAAejB,MAJf,WACsBK,SAASa,iBAAiB,mBAClCC,QAAQC,GAAQzB,EAAeyB","file":"54-b18c7087c93e377f859e.js","sourcesContent":["import whenDomReady from 'when-dom-ready';\r\nconst CLASSNAME_OVERLAY = 'video-card__placeholder-overlay';\r\nconst CLASSNAME_PLAYHOLDER = 'video-card__play-holder';\r\nconst CLASSNAME_CARD = 'video-card';\r\nconst CLASSNAME_CARDPREVENTED = 'video-card--prevented-autoplay';\r\nconst overlayVideo = (video) => {\r\n const videoParent = video.parentNode;\r\n if (!videoParent)\r\n return;\r\n const overlay = document.createElement('div');\r\n overlay.classList.add(CLASSNAME_OVERLAY);\r\n const playHolder = document.createElement('div');\r\n playHolder.classList.add(CLASSNAME_PLAYHOLDER);\r\n playHolder.innerHTML = '';\r\n videoParent.classList.add(CLASSNAME_CARD);\r\n videoParent.classList.add(CLASSNAME_CARDPREVENTED);\r\n videoParent.appendChild(overlay);\r\n videoParent.appendChild(playHolder);\r\n};\r\nconst playVideoOnClick = (video) => {\r\n const videoParent = video.parentNode;\r\n if (!videoParent)\r\n return;\r\n videoParent.addEventListener('click', () => {\r\n const overlay = videoParent.querySelector(`.${CLASSNAME_OVERLAY}`);\r\n const playHolder = videoParent.querySelector(`.${CLASSNAME_PLAYHOLDER}`);\r\n if (!(overlay && playHolder))\r\n return;\r\n overlay.remove();\r\n playHolder.remove();\r\n videoParent.classList.remove(CLASSNAME_CARDPREVENTED);\r\n videoParent.classList.remove(CLASSNAME_CARD);\r\n video.play();\r\n });\r\n};\r\nconst handleAutoplay = (video) => {\r\n const promise = video.play();\r\n if (promise !== undefined) {\r\n promise.then(() => {\r\n // Autoplay started, do nothing.\r\n }).catch(() => {\r\n // Autoplay was prevented.\r\n overlayVideo(video);\r\n playVideoOnClick(video);\r\n });\r\n }\r\n};\r\nfunction initialise() {\r\n const autoplays = document.querySelectorAll('[data-autoplay]');\r\n autoplays.forEach(item => handleAutoplay(item));\r\n}\r\nwhenDomReady().then(initialise);\r\n"],"sourceRoot":""}