wf.ready(()=> { console.log("Cookie consent for wf is: ", wf.getUserTrackingChoice()); class CookieConsent { constructor() { this.banner = document.querySelector(".cookie-consent-banner"); this.closeBtn = this.banner.querySelector(".cookie-consent-close"); this.acceptBtn = this.banner.querySelector( ".cookie-consent-button.accept" ); this.rejectBtn = this.banner.querySelector( ".cookie-consent-button.reject" ); this.scripts = document.querySelectorAll("[type='text/consent']"); this.check(); } check() { if (!this.getCookie("cookieconsent")) { wf.denyUserTracking(); this.init(); return; } this.banner.remove(); this.handleConsent(); } close() { this.banner.classList.remove("open"); } open() { this.banner.classList.add("open"); } scrollAdjust() { if (window.scrollY < window.innerHeight * 0.07) { this.banner.classList.remove("scrolled"); return; } if (this.banner.classList.contains("scrolled")) { return; } this.banner.classList.add("scrolled"); } accept() { if (this.getCookie("cookieconsent")) { return; } else { document.cookie = "cookieconsent=true"; } wf.allowUserTracking(); this.handleConsent(); this.close(); } reject() { if (this.getCookie("cookieconsent")) { return; } else { document.cookie = "cookieconsent=false"; } wf.denyUserTracking(); this.handleConsent(); this.close(); } handleConsent() { console.log(wf.getUserTrackingChoice()); console.log("handling..." + this.scripts); if (this.getCookie("cookieconsent") === "false") { return; } else { if (this.scripts === undefined || !this.scripts) { console.log("no scripts"); return; } this.scripts.forEach((script) => { const newScript = document.createElement("script"); newScript.src = script.src; document.body.appendChild(newScript); script.remove(); }); } } getCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(";"); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) === " ") { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { return decodeURIComponent(c.substring(nameEQ.length, c.length)); } } return null; } init() { //scrollAdjust window.addEventListener("scroll", () => { this.scrollAdjust(); }); //close this.closeBtn.addEventListener("click", () => { this.close(); }); //accept this.acceptBtn.addEventListener("click", () => { this.accept(); }); this.rejectBtn.addEventListener("click", () => { this.reject(); }); if (this.banner.classList.contains("open")) { return; } this.open(); } } const cookieConsent = new CookieConsent(); })