1/* 2 * Bootstrap Cookie Alert by Wruczek 3 * https://github.com/Wruczek/Bootstrap-Cookie-Alert 4 * Released under MIT license 5 */ 6(function () { 7 "use strict"; 8 9 var cookieAlert = document.querySelector(".cookiealert"); 10 var acceptCookies = document.querySelectorAll(".signup-slider-dismiss"); 11 var wdHero = document.querySelector("#wd-hero"); 12 13 if (!cookieAlert) { 14 return; 15 } 16 17 cookieAlert.offsetHeight; // Force browser to trigger reflow (https://stackoverflow.com/a/39451131) 18 19 // Show the alert if we cant find the "acceptCookies" cookie 20 if (!getCookie("x-content-slider")) { 21 cookieAlert.classList.add("show"); 22 } 23 24 if (getCookie("x-content-sub")) { 25 cookieAlert.classList.remove("show"); 26 wdHero.classList.remove("show"); 27 wdHero.classList.add("collapse"); 28 } 29 30 // When clicking on the agree button, create a 1 year 31 // cookie to remember user's choice and close the banner 32 for (var i = 0; i < acceptCookies.length; i++) { 33 acceptCookies[i].addEventListener("click", function () { 34 setCookie("x-content-slider", true, 365); 35 cookieAlert.classList.remove("show"); 36 37 // dispatch the accept event 38 window.dispatchEvent(new Event("cookieAlertAccept")) 39 }); 40 } 41 42 // Cookie functions from w3schools 43 function setCookie(cname, cvalue, exdays) { 44 var d = new Date(); 45 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 46 var expires = "expires=" + d.toUTCString(); 47 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 48 } 49 50 function getCookie(cname) { 51 var name = cname + "="; 52 var decodedCookie = decodeURIComponent(document.cookie); 53 var ca = decodedCookie.split(';'); 54 for (var i = 0; i < ca.length; i++) { 55 var c = ca[i]; 56 while (c.charAt(0) === ' ') { 57 c = c.substring(1); 58 } 59 if (c.indexOf(name) === 0) { 60 return c.substring(name.length, c.length); 61 } 62 } 63 return ""; 64 } 65 66 function checkAndSetCookie() { 67 var cookieAlert = document.querySelector(".cookiealert"); 68 var wdHero = document.querySelector("#wd-hero"); 69 70 // Obtain the query string from the current URL 71 const queryParams = new URLSearchParams(window.location.search); 72 73 // Check if the 'utm_optipub' query parameter exists 74 if (queryParams.has('utm_optipub')) { 75 // Run the function to set the cookie 76 setCookie("x-content-sub", true, 365); 77 cookieAlert.classList.remove("show"); 78 wdHero.classList.remove("show"); 79 wdHero.classList.add("collapse"); 80 } 81 } 82 83 checkAndSetCookie(); 84 85})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.