assets/themes/j1/modules/cookieConsent/js/cookieConsent.js in j1-template-2021.3.2 vs assets/themes/j1/modules/cookieConsent/js/cookieConsent.js in j1-template-2022.0.0

- old
+ new

@@ -22,11 +22,10 @@ # BS Cookie Consent is a MODIFIED version of bootstrap-cookie-banner # for the use with J1 Template. This modified version cannot be used # outside of J1 Template! # ----------------------------------------------------------------------------- */ -//'use strict'; // ----------------------------------------------------------------------------- // ESLint shimming // ----------------------------------------------------------------------------- /* eslint indent: "off" */ @@ -35,10 +34,11 @@ /* eslint no-redeclare: "off" */ /* eslint indent: "off" */ /* eslint JSUnfilteredForInLoop: "off" */ // ----------------------------------------------------------------------------- +'use strict'; function CookieConsent(props) { var logger = log4javascript.getLogger('j1.core.bsCookieConsent'); var self = this; var detailedSettingsShown = false; var url = new liteURL(window.location.href); @@ -87,12 +87,12 @@ this.props.cookieSecure = cookieSecure; var Cookie = { set: function (name, value, days, cookieSameSite, cookieSecure) { var value_encoded = window.btoa(value); - var expires = ""; - if (days) { + var expires = '; expires=Thu, 01 Jan 1970 00:00:00 UTC'; + if (days>0) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } if (cookieSecure) { @@ -186,12 +186,15 @@ Events.documentReady(function () { self.modal = document.getElementById(self.props.dialogContainerID); if (!self.modal) { logger.info('\n' + 'load consent modal'); + self.modal = document.createElement("div"); self.modal.id = self.props.dialogContainerID; + self.modal.style.display = 'none'; + self.modal.setAttribute("class", "modal fade"); self.modal.setAttribute("tabindex", "-1"); self.modal.setAttribute("role", "dialog"); self.modal.setAttribute("aria-labelledby", self.props.dialogContainerID); document.body.append(self.modal); @@ -213,12 +216,13 @@ // var templateUrl = self.props.contentURL + '/' + 'index.html'; $.get(templateUrl) .done(function (data) { logger.info('\n' + 'loading consent modal: successfully'); - self.modal.innerHTML = data; - self.modal.innerHTML = $('#' + self.props.xhrDataElement).eq(0).html(); + self.modal.innerHTML = data; + self.modal.innerHTML = $('#' + self.props.xhrDataElement).eq(0).html(); + self.modal.style.display = 'block'; $(self.modal).modal({ backdrop: "static", keyboard: false }); @@ -257,10 +261,12 @@ self.$buttonAgreeAll.click(function () { $("#bccs-options").collapse('hide'); agreeAll(); updateOptionsFromCookie(); }); + + self.$modal.modal('show'); }) .fail(function () { logger.error('\n' + 'loading consent modal: failed'); logger.warn('\n' + 'probably no `contentURL` set'); }); @@ -316,30 +322,26 @@ Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays, self.props.cookieSameSite, cookieSecure); self.$modal.modal('hide'); } function doNotAgree() { - Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays, self.props.cookieSameSite, cookieSecure); - - // jadams, 2021-07-15: all cookies NOT longer supported by j1.expireCookie - // TODO: Create loop over all cookies found in page - // - // logger.warn('expire all cookies'); - // j1.expireCookie('all'); - + // Remove consent cookie + Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), 0, self.props.cookieSameSite, cookieSecure); self.$modal.modal('hide'); - j1.goHome(); + // redirect to error page: blocked site + window.location.href = '/445.html'; } function saveSettings() { Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions()), self.props.cookieStorageDays, self.props.cookieSameSite, cookieSecure); self.$modal.modal('hide'); } - // call consent dialog if no cookie found (except pages whitelisted) + // call consent dialog if no cookie found or cookie NOT accepted (except whitelisted pages) // - whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1); - if (Cookie.get(this.props.cookieName) === undefined && this.props.autoShowDialog && !whitelisted) { + whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1); + var consentCookie = Cookie.get(this.props.cookieName); + if ((consentCookie === undefined || consentCookie === "false") && this.props.autoShowDialog && !whitelisted) { showDialog(); } // API functions // ---------------------------------------------------------------------------