assets/themes/j1/modules/cookieConsent/js/cookieConsent.js in j1-template-2021.1.12 vs assets/themes/j1/modules/cookieConsent/js/cookieConsent.js in j1-template-2021.1.13

- old
+ new

@@ -36,20 +36,22 @@ /* eslint indent: "off" */ /* eslint JSUnfilteredForInLoop: "off" */ // ----------------------------------------------------------------------------- function BootstrapCookieConsent(props) { + var logger = log4javascript.getLogger('j1.core.bsCookieConsent'); + var modalId = 'bccs-modal'; + var self = this; + var detailedSettingsShown = false; + var url = new liteURL(window.location.href); + var secure = (url.protocol.includes('https')) ? true : false; var logText; var current_page; var whitelisted; - var logger = log4javascript.getLogger('j1.core.bsCookieConsent'); - var modalId = "bccs-modal" - var self = this - var detailedSettingsShown = false - logger.info('Initializing core module: started'); - logger.info('state: started'); + logger.info('\n' + 'initializing core module: started'); + logger.info('\n' + 'state: started'); this.props = { autoShowDialog: true, // disable autoShowModal on the privacy policy and legal notice pages, to make these pages readable language: navigator.language, // the language, in which the modal is shown languages: ["en", "de"], // supported languages (in ./content/), defaults to first in array @@ -57,11 +59,12 @@ cookieName: "cookie-consent-settings", // the name of the cookie in which the configuration is stored as JSON cookieStorageDays: 365, // the duration the cookie configuration is stored on the client postSelectionCallback: undefined, // callback function, called after the user has made his selection whitelisted: [], // pages NO consent modal page is issued xhr_data_element: "", // container for the language-specific consent modal taken from /assets/data/cookieconsent.html - sameSite: "Strict" // restrict consent cookie to first-party, do NOT send cookie to other domains + sameSite: "Strict", // restrict consent cookie to first-party, do NOT send cookie to other domains + secure: false // } for (var property in props) { this.props[property] = props[property]; } @@ -74,19 +77,23 @@ if (!this.props.languages.includes(this.language)) { this.language = this.props.languages[0]; // fallback on default language } var Cookie = { - set: function (name, value, days, samesite) { + set: function (name, value, days, samesite, secure) { var value_encoded = window.btoa(value); var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } - document.cookie = name + "=" + (value_encoded || '') + expires + '; Path=/; SameSite=' + samesite + ';'; + if (secure) { + document.cookie = name + "=" + (value_encoded || '') + expires + '; Path=/; SameSite=' + samesite + '; ' + 'secure=' + secure + ';'; + } else { + document.cookie = name + "=" + (value_encoded || '') + expires + '; Path=/; SameSite=' + samesite + ';'; + } }, get: function (name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { @@ -117,11 +124,11 @@ function showDialog(options) { Events.documentReady(function () { self.modal = document.getElementById(modalId); if (!self.modal) { - logger.info('Load consent modal'); + logger.info('\n' + 'load consent modal'); self.modal = document.createElement("div"); self.modal.id = modalId; self.modal.setAttribute("class", "modal fade"); self.modal.setAttribute("tabindex", "-1"); self.modal.setAttribute("role", "dialog"); @@ -138,11 +145,11 @@ // load modal content // var templateUrl = self.props.contentURL + '/' + 'index.html'; $.get(templateUrl) .done(function (data) { - logger.info('Loading Consent modal: successfully'); + logger.info('\n' + 'loading consent modal: successfully'); self.modal.innerHTML = data; self.modal.innerHTML = $('#' + self.props.xhr_data_element).eq(0).html(); $(self.modal).modal({ backdrop: "static", @@ -152,11 +159,11 @@ self.$buttonDoNotAgree = $("#bccs-buttonDoNotAgree"); self.$buttonAgree = $("#bccs-buttonAgree"); self.$buttonSave = $("#bccs-buttonSave"); self.$buttonAgreeAll = $("#bccs-buttonAgreeAll"); - logger.info('Load/Initialze options from cookie'); + logger.info('\n' + 'load/initialze options from cookie'); updateButtons(); updateOptionsFromCookie(); $("#bccs-options").on("hide.bs.collapse", function () { @@ -165,11 +172,11 @@ }).on("show.bs.collapse", function () { detailedSettingsShown = true; updateButtons(); }); - logger.info('Initialze event handler'); + logger.info('\n' + 'initialze event handler'); self.$buttonDoNotAgree.click(function () { doNotAgree(); }); self.$buttonAgree.click(function () { @@ -185,12 +192,12 @@ agreeAll(); updateOptionsFromCookie(); }); }) .fail(function () { - logger.error('Loading Consent modal: failed'); - logger.info('Probably no `contentURL` set'); + logger.error('\n' + 'loading consent modal: failed'); + logger.warn('\n' + 'probably no `contentURL` set'); }) } else { self.$modal.modal("show") } }.bind(this)) @@ -237,16 +244,16 @@ } return options } function agreeAll() { - Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays, self.props.sameSite); + Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays, self.props.sameSite, self.props.secure); self.$modal.modal("hide"); } function doNotAgree() { - Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays, self.props.sameSite); + Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays, self.props.sameSite, self.props.secure); // 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'); @@ -255,11 +262,11 @@ self.$modal.modal('hide') j1.goHome(); } function saveSettings() { - Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions()), self.props.cookieStorageDays, self.props.sameSite); + Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions()), self.props.cookieStorageDays, self.props.sameSite, self.props.secure); self.$modal.modal("hide"); } // call consent dialog if no cookie found (except pages whitelisted) // @@ -269,11 +276,11 @@ } // API functions // --------------------------------------------------------------------------- - logger.info('Initializing core module finished'); - logger.info('state: finished'); + logger.info('\n' + 'initializing core module finished'); + logger.info('\n' + 'state: finished'); // show the consent dialog (modal) // --------------------------------------------------------------------------- this.showDialog = function () { whitelisted = (this.props.whitelisted.indexOf(window.location.pathname) > -1);