// Dean note: set default cookie parameter values if we don't have any if(typeof mycookieconsentname === 'undefined' || mycookieconsentname.trim() === '') { var mycookieconsentname = "CMSCookieLevel"; } if(typeof mycookiedomain === 'undefined' || mycookiedomain.trim() === '') { var mycookiedomain = ".alz.org"; } if(typeof mycookievalue === 'undefined' || mycookievalue === '') { var mycookievalue = 1000; } if(typeof mycookietime === 'undefined' || mycookietime === '') { var mycookietime = 60*60*24*30; } // returns the cookie value or undefined if not found function getCookie(name) { let matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : undefined; } // Set cookie by cookie name and give values, options, etc. // Example of use: // setCookie('user', 'John', {secure: true, 'max-age': 3600}); function setCookie(name, value, options = {}) { options = { path: '/', // add other defaults here if necessary ...options }; if (options.expires instanceof Date) { options.expires = options.expires.toUTCString(); } let updatedCookie = encodeURIComponent(name) + "=" + encodeURIComponent(value); for (let optionKey in options) { updatedCookie += "; " + optionKey; let optionValue = options[optionKey]; if (optionValue !== true) { updatedCookie += "=" + optionValue; } } document.cookie = updatedCookie; } // Dean note: this will set our cookies when the user clicks on the consent buttons function setCookieConsent() { // Dean note: hide cookie consent bar document.querySelector(".CookieConsentContainer").style.visibility = 'hidden'; // Dean note: error check section to make sure we have all of our required cookie variables. let myerrormessage = ""; if(typeof mycookieconsentname === 'undefined') { myerrormessage += "The variable mycookieconsentname is not defined. You must create this variable for the cookie name and give it a value.\n"; } else if(mycookieconsentname.trim() === '') { myerrormessage += "The variable mycookieconsentname has no value. You must give this variable a value for the cookie name.\n"; } if(typeof mycookietime === 'undefined') { myerrormessage += "The variable mycookietime is not defined. You must create this variable for the cookie maximum age and give it a value (in seconds).\n"; } else if(mycookietime === '') { myerrormessage += "The variable mycookietime has no value. You must give this variable a value for the cookie maximum age (in seconds).\n"; } if(typeof mycookiedomain === 'undefined') { myerrormessage += "The variable mycookiedomain is not defined. You must create this variable for the cookie domain and give it a value.\n"; } else if(mycookiedomain.trim() === '') { myerrormessage += "The variable mycookiedomain has no value. You must give this variable a value for the cookie value.\n"; } // Dean note: check to make sure we have all of our variables needed to set the cookie. If not, then log the error to the console. if(myerrormessage === "") { setCookie(mycookieconsentname.trim(), mycookievalue, {'domain': mycookiedomain.trim(), 'max-age': mycookietime}); } else { console.log(myerrormessage); } } function checkCookie() { // Dean note: create an array of all the buttons that can the user can click on to close the cookie bar. let cookieconsentbuttons = document.querySelectorAll("#CookieConsentButtonAllowAll, #CookieConsentButtonClose"); // Dean note: add a click event listener for each of the buttons above. cookieconsentbuttons.forEach((element) => { element.addEventListener("click", setCookieConsent); }); let myretrievedcookie = getCookie(mycookieconsentname); // Dean note: if don't find the cookie, display the cookie consent bar if(myretrievedcookie != mycookievalue) { document.querySelector(".CookieConsentContainer").style.visibility = 'visible'; } } // Dean note: use this function if relying solely on javascript on remote server without SSI (server side includes) function remoteCheckCookie() { fetch ("https://www.alz.org/global/includes/global-cookie-consent/global-cookie-policy.asp").then(function (response) { return response.text(); }).then(function (mycookiehtml) { // Dean note: if the site wants to add the cookie to a specific element with an ID, we check for the variable mycookiecustomcontainerid // Otherwise, append it at the end of the html before the closing body tag. if(typeof mycookiecustomcontainerid !== 'undefined' && mycookiecustomcontainerid !== '') { document.querySelector('#' + mycookiecustomcontainerid).insertAdjacentHTML("afterend", mycookiehtml); } else { document.querySelector('body').insertAdjacentHTML('beforeend', mycookiehtml); } checkCookie(); }).catch(function (err) { console.error(err); }); }