2025-06-07 06:39:19 +02:00

50 lines
1.4 KiB
JavaScript

/**
* Activate all the videos on this page.
*/
function activateVideos() {
const iframes = document.querySelectorAll('.video__iframe[data-src*="youtube-nocookie.com"]');
iframes.forEach((iframe) => {
iframe.src = iframe.dataset.src;
});
}
/**
* Activate only the video with the given video ID
*/
function activateVideo(videoId) {
const surroundingDiv = document.getElementById(videoId);
const iframes = surroundingDiv.querySelectorAll('.video__iframe[data-src*="youtube-nocookie.com"]');
iframes.forEach((iframe) => {
iframe.src = iframe.dataset.src;
});
}
/**
* Invoked by the accept buttons to activate one or all videos.
* @param videodId The ID of the video to activate. Undefined to activate all.
*/
function onConsent(videoId) {
// Activate only the given video if the videoId is defined. Otherwise,
// activate all videos permanently by setting our cookie valid for a year.
if (videoId) {
activateVideo(videoId);
}
else {
Cookies.set('grav_youtubeconsent', 'true', { expires: 365 });
activateVideos();
}
return false;
}
/**
* When the page is loaded, activate all videos in case the "grav_youtubeconsent" cookie has the value 'true'.
*/
window.addEventListener("load", function () {
if (Cookies.get('grav_youtubeconsent') === 'true') {
activateVideos();
}
});