"use strict"; if (typeof embed === 'undefined' || embed === null) { // prevent double init const embed = document.querySelectorAll('[data-video-embed]'); // autoplay const EMBED_VIDEOS_VISIBIILITY_THRESHOLD = 0.8; function sendIframeMessage(iframe, type = 'play') { iframe.contentWindow.postMessage(type, '*'); } function playViewportVideo() { let anotherIsPlaying = false; embed.forEach((video) => { // Another video is already playing -> auto-pause video if (anotherIsPlaying) { sendIframeMessage(video, 'pause'); return; } // Play video if fraction is in viewport if (video.dataset.inViewport === 'true') { sendIframeMessage(video, 'play'); anotherIsPlaying = true; } else { // Video is not in viewport -> pause sendIframeMessage(video, 'pause'); } }); } const embedVideosOserver = new IntersectionObserver((entries) => { entries.forEach((entry) => { const iframe = entry.target; iframe.dataset.inViewport = entry.isIntersecting ? 'true' : 'false'; }); playViewportVideo(); }, {threshold: EMBED_VIDEOS_VISIBIILITY_THRESHOLD}); embed.forEach((el) => { el.addEventListener('load', (e) => { embedVideosOserver.observe(e.target); }); }); // send info about device window.addEventListener("DOMContentLoaded", () => { const device = window.innerWidth < 700 ? 'web_mobile' : 'web_desktop'; embed.forEach((video) => { sendIframeMessage(video, device); }); }); // Messages from video iframes window.addEventListener('message', function (e) { try { const message = JSON.parse(e.data); // Stop all videos if (message.type === 'stop-all') { embed.forEach((video) => { if (video.getAttribute('src') === message.src) return; // except one that plays sendIframeMessage(video, 'pause'); }); } } catch(e) {} }, false); // CMP const CMP_CALL_LIMIT = 3; embed.forEach((video) => { let clearId = null; let cmpReady = false; video.addEventListener('load', function () { const targetNode = document.body; const config = {attributes: false, childList: true, subtree: false}; const tcfIframe = window.frames['__tcfapiLocator']; // cmp iframe exist if (tcfIframe) { cmpIsReady(CMP_CALL_LIMIT); } else { // detect in DOM cmp iframe const callback = (mutationList, observer) => { for (const mutation of mutationList) { [].filter.call(mutation.addedNodes, function (node) { try { if (node?.tagName === 'IFRAME' && node?.name === '__tcfapiLocator') { observer.disconnect(); cmpIsReady(CMP_CALL_LIMIT); } } catch (e) { } }); } }; const observer = new MutationObserver(callback); observer.observe(targetNode, config); } }); // service fce of cmp api and call message to video embed function cmpIsReady(limit) { __tcfapi('addEventListener', 2, (tcData, success) => { embed.forEach((video) => { // cmp api is ready and has data if (success && tcData.eventStatus === 'tcloaded') { clearTimeout(clearId); const consent = tcData?.tcString ?? ''; video.contentWindow.postMessage(`{"consent": "${consent}"}`, '*'); // global state for last change window load cmpReady = true; } else { if (limit > 0) { limit--; clearId = setTimeout(cmpIsReady, 2000, limit); } else { // add default consent (reject consent) video.contentWindow.postMessage(`{"consent": "CPv7UwAPv7UwAAHABBENDQCgAAAAAAAAAATIAAAAAAEkoAMAARBQDQAYAAiCgKgAwABEFApABgACIKA6ADAAEQUCEAGAAIgoBIAMAARBQGQAYAAiCgIgAwABEFAA.YAAAAAAAAAAA"}`, '*'); // global state for last change window load cmpReady = true; } } }); }); } // last chance for init player without cmp framework on the page window.addEventListener('load', function () { if (cmpReady === false) { embed.forEach((video) => { // add default consent (reject consent) video.contentWindow.postMessage(`{"consent": "CPv7UwAPv7UwAAHABBENDQCgAAAAAAAAAATIAAAAAAEkoAMAARBQDQAYAAiCgKgAwABEFApABgACIKA6ADAAEQUCEAGAAIgoBIAMAARBQGQAYAAiCgIgAwABEFAA.YAAAAAAAAAAA"}`, '*'); }); } }); }); // load CSS let videoEmbedCssLink = document.createElement('link'); videoEmbedCssLink.rel = 'stylesheet'; videoEmbedCssLink.type = 'text/css'; videoEmbedCssLink.href = 'https://services.administrace.tv/video-embed/partner-css'; const videoEmbedHead = document.getElementsByTagName('head')[0]; videoEmbedHead.appendChild(videoEmbedCssLink); }