Skip to content

Commit

Permalink
COC-30 | Fixed bug - closed initial modal when clicking close button …
Browse files Browse the repository at this point in the history
…if cookie exists
  • Loading branch information
Marco Monti authored and l-besenyei committed May 8, 2024
1 parent 9d9e3e3 commit 9e88352
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
22 changes: 14 additions & 8 deletions build/cookieconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var Utilities = /*#__PURE__*/function () {
document.cookie = "cconsent=; expires=Thu, 01 Jan 1980 00:00:00 UTC; path=/;";
//remove localStorage consentMode obj
localStorage.removeItem('consentMode');
window.CookieConsent.config.cookieExists = false;
}

// Create an array of services from Cookieconsent global object
Expand Down Expand Up @@ -1575,24 +1576,28 @@ var Interface = /*#__PURE__*/function () {

// If you click close on open modal
this.elements['modal'].querySelector('.ccm__cheading__close').addEventListener('click', function (event) {
var _this$elements$modalI4, _this$elements$modalI5, _this$elements$modalI6;
_this.elements['modal'].classList.remove('ccm--visible');
_this.elements['modal'].setAttribute('aria-hidden', 'true');
_this.elements['modal'].setAttribute('tabindex', '-1');
(_this$elements$modalI4 = _this.elements['modalInit']) === null || _this$elements$modalI4 === void 0 ? void 0 : _this$elements$modalI4.classList.add('ccm--visible');
(_this$elements$modalI5 = _this.elements['modalInit']) === null || _this$elements$modalI5 === void 0 ? void 0 : _this$elements$modalI5.setAttribute('aria-hidden', 'false');
(_this$elements$modalI6 = _this.elements['modalInit']) === null || _this$elements$modalI6 === void 0 ? void 0 : _this$elements$modalI6.setAttribute('tabindex', '0');
if (!window.CookieConsent.config.cookieExists) {
var _this$elements$modalI4, _this$elements$modalI5, _this$elements$modalI6;
(_this$elements$modalI4 = _this.elements['modalInit']) === null || _this$elements$modalI4 === void 0 ? void 0 : _this$elements$modalI4.classList.add('ccm--visible');
(_this$elements$modalI5 = _this.elements['modalInit']) === null || _this$elements$modalI5 === void 0 ? void 0 : _this$elements$modalI5.setAttribute('aria-hidden', 'false');
(_this$elements$modalI6 = _this.elements['modalInit']) === null || _this$elements$modalI6 === void 0 ? void 0 : _this$elements$modalI6.setAttribute('tabindex', '0');
}
modalOpen = false;
});
document.addEventListener('keydown', function (event) {
if (modalOpen && (!event.keyCode || event.keyCode === 27)) {
var _this$elements$modalI7, _this$elements$modalI8, _this$elements$modalI9;
_this.elements['modal'].classList.remove('ccm--visible');
_this.elements['modal'].setAttribute('aria-hidden', 'true');
_this.elements['modal'].setAttribute('tabindex', '-1');
(_this$elements$modalI7 = _this.elements['modalInit']) === null || _this$elements$modalI7 === void 0 ? void 0 : _this$elements$modalI7.classList.add('ccm--visible');
(_this$elements$modalI8 = _this.elements['modalInit']) === null || _this$elements$modalI8 === void 0 ? void 0 : _this$elements$modalI8.setAttribute('aria-hidden', 'false');
(_this$elements$modalI9 = _this.elements['modalInit']) === null || _this$elements$modalI9 === void 0 ? void 0 : _this$elements$modalI9.setAttribute('tabindex', '0');
if (!window.CookieConsent.config.cookieExists) {
var _this$elements$modalI7, _this$elements$modalI8, _this$elements$modalI9;
(_this$elements$modalI7 = _this.elements['modalInit']) === null || _this$elements$modalI7 === void 0 ? void 0 : _this$elements$modalI7.classList.add('ccm--visible');
(_this$elements$modalI8 = _this.elements['modalInit']) === null || _this$elements$modalI8 === void 0 ? void 0 : _this$elements$modalI8.setAttribute('aria-hidden', 'false');
(_this$elements$modalI9 = _this.elements['modalInit']) === null || _this$elements$modalI9 === void 0 ? void 0 : _this$elements$modalI9.setAttribute('tabindex', '0');
}
modalOpen = false;
}
});
Expand Down Expand Up @@ -1704,6 +1709,7 @@ var Interface = /*#__PURE__*/function () {
value: function setCookie(cookie, callback) {
var expires_in = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toUTCString();
document.cookie = "cconsent=".concat(JSON.stringify(cookie), "; expires=").concat(expires_in, "; path=/;");
window.CookieConsent.config.cookieExists = true;
if (callback) callback();
}
}]);
Expand Down
2 changes: 1 addition & 1 deletion build/cookieconsent.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs_src/src/assets/js/cookieconsent.min.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions src/lib/Interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,20 +492,26 @@ export default class Interface {
this.elements['modal'].classList.remove('ccm--visible');
this.elements['modal'].setAttribute('aria-hidden', 'true');
this.elements['modal'].setAttribute('tabindex', '-1');
this.elements['modalInit']?.classList.add('ccm--visible');
this.elements['modalInit']?.setAttribute('aria-hidden', 'false');
this.elements['modalInit']?.setAttribute('tabindex', '0');

if (!window.CookieConsent.config.cookieExists) {
this.elements['modalInit']?.classList.add('ccm--visible');
this.elements['modalInit']?.setAttribute('aria-hidden', 'false');
this.elements['modalInit']?.setAttribute('tabindex', '0');
}
modalOpen = false;
});

document.addEventListener('keydown', (event) => {

if (modalOpen && (!event.keyCode || event.keyCode === 27)) {
this.elements['modal'].classList.remove('ccm--visible');
this.elements['modal'].setAttribute('aria-hidden', 'true');
this.elements['modal'].setAttribute('tabindex', '-1');
this.elements['modalInit']?.classList.add('ccm--visible');
this.elements['modalInit']?.setAttribute('aria-hidden', 'false');
this.elements['modalInit']?.setAttribute('tabindex', '0');
if (!window.CookieConsent.config.cookieExists) {
this.elements['modalInit']?.classList.add('ccm--visible');
this.elements['modalInit']?.setAttribute('aria-hidden', 'false');
this.elements['modalInit']?.setAttribute('tabindex', '0');
}
modalOpen = false;
}
});
Expand Down Expand Up @@ -605,6 +611,7 @@ export default class Interface {
const expires_in = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toUTCString();

document.cookie = `cconsent=${JSON.stringify(cookie)}; expires=${expires_in}; path=/;`;
window.CookieConsent.config.cookieExists = true
if (callback) callback();
}
}
1 change: 1 addition & 0 deletions src/lib/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class Utilities {
document.cookie = `cconsent=; expires=Thu, 01 Jan 1980 00:00:00 UTC; path=/;`;
//remove localStorage consentMode obj
localStorage.removeItem('consentMode')
window.CookieConsent.config.cookieExists = false
}

// Create an array of services from Cookieconsent global object
Expand Down

0 comments on commit 9e88352

Please sign in to comment.