ldc-doux/resources/js/frontend/cn-inline-buttons.js
2024-06-11 12:44:47 +02:00

27 lines
1 KiB
JavaScript
Vendored

document.addEventListener("DOMContentLoaded", function () {
function handle(e) {
e.preventDefault();
const cookieEl = e.target.parentElement;
if (!window.WebCookieNotice) {
console.debug("Missing WebCookieNotice on window");
return;
}
window.WebCookieNotice.acceptCookie(
String(cookieEl.dataset.cookieName)
);
cookieEl.classList.add("d-none");
}
window.listenInlineCnButtons = () => {
const cookieInlineActivation =
document.getElementsByClassName("cn-cookie-activate");
[...cookieInlineActivation].forEach((cookieEl) => {
const cookieBtnActivation = cookieEl.querySelector("button");
if (!cookieBtnActivation) {
throw new Error("Invalid template cookie button");
}
cookieBtnActivation.removeEventListener("click", handle);
cookieBtnActivation.addEventListener("click", handle);
});
};
window.listenInlineCnButtons();
});