From 9e8835266c486da52a218c16e192251d93d36a99 Mon Sep 17 00:00:00 2001 From: Marco Monti Date: Wed, 24 Apr 2024 11:22:04 +0200 Subject: [PATCH] COC-30 | Fixed bug - closed initial modal when clicking close button if cookie exists --- build/cookieconsent.js | 22 +++++++++++++-------- build/cookieconsent.min.js | 2 +- docs_src/src/assets/js/cookieconsent.min.js | 2 +- src/lib/Interface.js | 19 ++++++++++++------ src/lib/Utilities.js | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/build/cookieconsent.js b/build/cookieconsent.js index 02edb09..ab3f4f6 100644 --- a/build/cookieconsent.js +++ b/build/cookieconsent.js @@ -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 @@ -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; } }); @@ -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(); } }]); diff --git a/build/cookieconsent.min.js b/build/cookieconsent.min.js index b896dcc..41875d3 100644 --- a/build/cookieconsent.min.js +++ b/build/cookieconsent.min.js @@ -1 +1 @@ -(()=>{"use strict";function e(e,t){for(var n=0;n>16)+t;i>255?i=255:i<0&&(i=0);var r=(o>>8&255)+t;r>255?r=255:r<0&&(r=0);var c=(255&o)+t;return c>255?c=255:c<0&&(c=0),(n?"#":"")+(c|r<<8|i<<16).toString(16)}},{key:"removeCookie",value:function(){document.cookie="cconsent=; expires=Thu, 01 Jan 1980 00:00:00 UTC; path=/;",localStorage.removeItem("consentMode")}},{key:"listGlobalServices",value:function(e){var t=[];if(void 0===window.CookieConsent)return t;if(void 0===e)for(var n in window.CookieConsent.config.services)t.push(n);else for(var o in window.CookieConsent.config.services)window.CookieConsent.config.services[o].category===e&&t.push(o);return t}},{key:"dispatchEvent",value:function(e,t){"function"==typeof Event?t=new Event(t):(t=document.createEvent("Event")).initEvent(t,!0,!0),e.dispatchEvent(t)}}],(o=null)&&e(n.prototype,o),i&&e(n,i),Object.defineProperty(n,"prototype",{writable:!1}),t}();function n(e,t){for(var n=0;n=0&&!1===window.CookieConsent.config.categories[window.CookieConsent.config.services[t].category].wanted)return void window.CookieConsent.buffer.appendChild.push({this:this,category:window.CookieConsent.config.services[t].category,arguments});return Node.prototype.appendChild.apply(this,arguments)}}},{key:"overrideInsertBefore",value:function(){Element.prototype.insertBefore=function(e){if("SCRIPT"===arguments[0].tagName)for(var t in window.CookieConsent.config.services)if("dynamic-script"===window.CookieConsent.config.services[t].type&&arguments[0].outerHTML.indexOf(window.CookieConsent.config.services[t].search)>=0&&!1===window.CookieConsent.config.categories[window.CookieConsent.config.services[t].category].wanted)return void window.CookieConsent.buffer.insertBefore.push({this:this,category:window.CookieConsent.config.services[t].category,arguments});return Node.prototype.insertBefore.apply(this,arguments)}}}],n&&r(t.prototype,n),o&&r(t,o),Object.defineProperty(t,"prototype",{writable:!1}),s}(o);function d(e){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},d(e)}function u(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,c=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return c=e.done,e},e:function(e){a=!0,r=e},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw r}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1?arguments[1]:void 0;e.indexOf(t)<0&&n()}}}],n&&v(t.prototype,n),o&&v(t,o),Object.defineProperty(t,"prototype",{writable:!1}),r}(o);function T(e){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},T(e)}function j(e,t){for(var n=0;n0;)n[o]=arguments[o+1];var i=typeof e;if("string"===i)t=ee(e).cloneNode(!1);else if($(e))t=e.cloneNode(!1);else{if("function"!==i)throw new Error("At least one argument required");var r=e;t=new(Function.prototype.bind.apply(r,[null].concat(n)))}return G(X(t),n,!0),t}var Z=Q;function ee(e){return K[e]||(K[e]=L(e))}function te(e){for(var t=[],n=arguments.length-1;n-- >0;)t[n]=arguments[n+1];for(var o=ne(e,t,X(e).firstChild);o;){var i=o.nextSibling;P(e,o),o=i}}function ne(e,t,n){for(var o=n,i=new Array(t.length),r=0;r0;)t[n]=arguments[n+1];var o=ee(e);return Q.bind.apply(Q,[this,o].concat(t))};var oe=function(e,t,n){this.View=e,this.initData=n,this.oldLookup={},this.lookup={},this.oldViews=[],this.views=[],null!=t&&(this.key="function"==typeof t?t:function(e){return function(t){return t[e]}}(t))};oe.prototype.update=function(e,t){for(var n=this,o=n.View,i=n.key,r=n.initData,c=null!=i,a=this.lookup,s={},l=new Array(e.length),d=this.views,u=0;u0;)n[o]=arguments[o+1];var i=typeof e;if("string"===i)t=de(e).cloneNode(!1);else if($(e))t=e.cloneNode(!1);else{if("function"!==i)throw new Error("At least one argument required");var r=e;t=new(Function.prototype.bind.apply(r,[null].concat(n)))}return G(X(t),n,!0),t}function de(e){return se[e]||(se[e]=L(e,ae))}function ue(e,t){for(var n=0;n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,c=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return c=e.done,e},e:function(e){a=!0,r=e},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw r}}}}function _e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n