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.querySelector(".acceptcookies");
11
12 if (!cookieAlert) {
13 return;
14 }
15
16 cookieAlert.offsetHeight; // Force browser to trigger reflow (https://stackoverflow.com/a/39451131)
17
18 // Show the alert if we cant find the "acceptCookies" cookie
19 if (!getCookie("acceptCookies")) {
20 cookieAlert.classList.add("show");
21 }
22
23 // When clicking on the agree button, create a 1 year
24 // cookie to remember user's choice and close the banner
25 acceptCookies.addEventListener("click", function () {
26 setCookie("acceptCookies", true, 365);
27 cookieAlert.classList.remove("show");
28
29 // dispatch the accept event
30 window.dispatchEvent(new Event("cookieAlertAccept"))
31 });
32
33 // Cookie functions from w3schools
34 function setCookie(cname, cvalue, exdays) {
35 var d = new Date();
36 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
37 var expires = "expires=" + d.toUTCString();
38 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
39 }
40
...
</html>