From 6a32309f2ce847b517d04e6e0e93c2c56feb3970 Mon Sep 17 00:00:00 2001 From: Marco Monti Date: Tue, 9 Apr 2024 11:38:27 +0200 Subject: [PATCH] COC-30 | Req changes: displaying modals, changed layout mode prop from config obj --- build/cookieconsent.js | 46 +++++++++++++-------- build/cookieconsent.min.js | 2 +- docs_src/src/assets/js/cookieconsent.min.js | 2 +- readme.md | 2 + src/lib/Configuration.js | 2 +- src/lib/Interface.js | 17 ++++++-- 6 files changed, 47 insertions(+), 24 deletions(-) diff --git a/build/cookieconsent.js b/build/cookieconsent.js index 338f9a8..02edb09 100644 --- a/build/cookieconsent.js +++ b/build/cookieconsent.js @@ -1359,8 +1359,8 @@ var Interface = /*#__PURE__*/function () { } that.render('style', that.buildStyle()); - //show the bar only if modal Layout config param is false - if (!window.CookieConsent.config.modalLayoutActive) { + //show the bar only if layout mode is 'bar' + if (window.CookieConsent.config.mode == 'bar') { that.render('bar', that.buildBar(), function (bar) { // Show the bar after a while if (!window.CookieConsent.config.cookieExists) { @@ -1384,8 +1384,8 @@ var Interface = /*#__PURE__*/function () { } that.render('modal', that.buildModal()); - //show init modal if modal layout param is true - if (window.CookieConsent.config.modalLayoutActive) { + //show init modal if layout mode is 'modal' + if (window.CookieConsent.config.mode == 'modal') { that.render('modalInit', that.buildInitialModal(), function (modal) { if (!window.CookieConsent.config.cookieExists) { setTimeout(function () { @@ -1416,7 +1416,7 @@ var Interface = /*#__PURE__*/function () { var _loop = function _loop() { var button = _step2.value; button.addEventListener('click', function () { - var _this$elements$bar4, _this$elements$bar5, _this$elements$bar6, _this$elements$modalI4, _this$elements$modalI5, _this$elements$modalI6, _ref5, _ref6; + var _this$elements$bar4, _this$elements$bar5, _this$elements$bar6, _this$elements$modalI13, _this$elements$modalI14, _this$elements$modalI15, _ref5, _ref6; var buttonSettings = document.querySelector('.ccb__edit'); var buttonConsentDecline = document.querySelector('.consent-decline'); @@ -1434,9 +1434,9 @@ var Interface = /*#__PURE__*/function () { _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.remove('ccm--visible'); - (_this$elements$modalI5 = _this.elements['modalInit']) === null || _this$elements$modalI5 === void 0 ? void 0 : _this$elements$modalI5.setAttribute('aria-hidden', 'true'); - (_this$elements$modalI6 = _this.elements['modalInit']) === null || _this$elements$modalI6 === void 0 ? void 0 : _this$elements$modalI6.setAttribute('tabindex', '-1'); + (_this$elements$modalI13 = _this.elements['modalInit']) === null || _this$elements$modalI13 === void 0 ? void 0 : _this$elements$modalI13.classList.remove('ccm--visible'); + (_this$elements$modalI14 = _this.elements['modalInit']) === null || _this$elements$modalI14 === void 0 ? void 0 : _this$elements$modalI14.setAttribute('aria-hidden', 'true'); + (_this$elements$modalI15 = _this.elements['modalInit']) === null || _this$elements$modalI15 === void 0 ? void 0 : _this$elements$modalI15.setAttribute('tabindex', '-1'); button.setAttribute('tabindex', '-1'); button.setAttribute('aria-hidden', 'true'); buttonSettings.setAttribute('tabindex', '-1'); @@ -1465,7 +1465,7 @@ var Interface = /*#__PURE__*/function () { var _loop2 = function _loop2() { var button = _step3.value; button.addEventListener('click', function () { - var _this$elements$bar7, _this$elements$bar8, _this$elements$bar9, _this$elements$modalI7, _this$elements$modalI8, _this$elements$modalI9; + var _this$elements$bar7, _this$elements$bar8, _this$elements$bar9, _this$elements$modalI16, _this$elements$modalI17, _this$elements$modalI18; var buttonSettings = document.querySelector('.ccb__edit'); var buttonConsentGive = document.querySelector('.consent-give'); @@ -1483,9 +1483,9 @@ var Interface = /*#__PURE__*/function () { _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.remove('ccm--visible'); - (_this$elements$modalI8 = _this.elements['modalInit']) === null || _this$elements$modalI8 === void 0 ? void 0 : _this$elements$modalI8.setAttribute('aria-hidden', 'true'); - (_this$elements$modalI9 = _this.elements['modalInit']) === null || _this$elements$modalI9 === void 0 ? void 0 : _this$elements$modalI9.setAttribute('tabindex', '-1'); + (_this$elements$modalI16 = _this.elements['modalInit']) === null || _this$elements$modalI16 === void 0 ? void 0 : _this$elements$modalI16.classList.remove('ccm--visible'); + (_this$elements$modalI17 = _this.elements['modalInit']) === null || _this$elements$modalI17 === void 0 ? void 0 : _this$elements$modalI17.setAttribute('aria-hidden', 'true'); + (_this$elements$modalI18 = _this.elements['modalInit']) === null || _this$elements$modalI18 === void 0 ? void 0 : _this$elements$modalI18.setAttribute('tabindex', '-1'); button.setAttribute('tabindex', '-1'); button.setAttribute('aria-hidden', 'true'); buttonSettings.setAttribute('tabindex', '-1'); @@ -1509,11 +1509,15 @@ var Interface = /*#__PURE__*/function () { } Array.prototype.forEach.call(document.querySelectorAll('.ccm__edit, .ccb__edit'), function (edit) { edit.addEventListener('click', function () { + var _this$elements$modalI, _this$elements$modalI2, _this$elements$modalI3; modalOpen = true; _this.elements['modal'].classList.add('ccm--visible'); _this.elements['modal'].setAttribute('aria-hidden', 'false'); _this.elements['modal'].setAttribute('tabindex', '0'); _this.elements['modal'].querySelector('.ccm__cheading__close').focus(); + (_this$elements$modalI = _this.elements['modalInit']) === null || _this$elements$modalI === void 0 ? void 0 : _this$elements$modalI.classList.remove('ccm--visible'); + (_this$elements$modalI2 = _this.elements['modalInit']) === null || _this$elements$modalI2 === void 0 ? void 0 : _this$elements$modalI2.setAttribute('aria-hidden', 'true'); + (_this$elements$modalI3 = _this.elements['modalInit']) === null || _this$elements$modalI3 === void 0 ? void 0 : _this$elements$modalI3.setAttribute('tabindex', '-1'); }); }); @@ -1571,16 +1575,24 @@ 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'); 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'); modalOpen = false; } }); @@ -1596,13 +1608,13 @@ var Interface = /*#__PURE__*/function () { var buttonConsentDecline = document.querySelector('.consent-decline'); _this.buildCookie(function (cookie) { _this.setCookie(cookie, function () { - var _this$elements$modalI, _this$elements$modalI2, _this$elements$modalI3, _this$elements$bar, _this$elements$bar2, _this$elements$bar3, _ref3, _ref4; + var _this$elements$modalI10, _this$elements$modalI11, _this$elements$modalI12, _this$elements$bar, _this$elements$bar2, _this$elements$bar3, _ref3, _ref4; _this.elements['modal'].classList.remove('ccm--visible'); _this.elements['modal'].setAttribute('aria-hidden', 'true'); _this.elements['modal'].setAttribute('tabindex', '-1'); - (_this$elements$modalI = _this.elements['modalInit']) === null || _this$elements$modalI === void 0 ? void 0 : _this$elements$modalI.classList.remove('ccm--visible'); - (_this$elements$modalI2 = _this.elements['modalInit']) === null || _this$elements$modalI2 === void 0 ? void 0 : _this$elements$modalI2.setAttribute('aria-hidden', 'true'); - (_this$elements$modalI3 = _this.elements['modalInit']) === null || _this$elements$modalI3 === void 0 ? void 0 : _this$elements$modalI3.setAttribute('tabindex', '-1'); + (_this$elements$modalI10 = _this.elements['modalInit']) === null || _this$elements$modalI10 === void 0 ? void 0 : _this$elements$modalI10.classList.remove('ccm--visible'); + (_this$elements$modalI11 = _this.elements['modalInit']) === null || _this$elements$modalI11 === void 0 ? void 0 : _this$elements$modalI11.setAttribute('aria-hidden', 'true'); + (_this$elements$modalI12 = _this.elements['modalInit']) === null || _this$elements$modalI12 === void 0 ? void 0 : _this$elements$modalI12.setAttribute('tabindex', '-1'); (_this$elements$bar = _this.elements['bar']) === null || _this$elements$bar === void 0 ? void 0 : _this$elements$bar.classList.add('ccb--hidden'); (_this$elements$bar2 = _this.elements['bar']) === null || _this$elements$bar2 === void 0 ? void 0 : _this$elements$bar2.setAttribute('aria-hidden', 'true'); (_this$elements$bar3 = _this.elements['bar']) === null || _this$elements$bar3 === void 0 ? void 0 : _this$elements$bar3.setAttribute('tabindex', '-1'); @@ -1722,7 +1734,7 @@ var Configuration = /*#__PURE__*/function () { active: true, cookieExists: false, cookieVersion: 1, - modalLayoutActive: false, + mode: 'bar', modalMainTextMoreLink: null, showRejectAllButton: false, UITimeout: 1000, diff --git a/build/cookieconsent.min.js b/build/cookieconsent.min.js index f37775d..b896dcc 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 u(e){return u="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},u(e)}function d(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),u=this.views,d=0;d0;)n[o]=arguments[o+1];var i=typeof e;if("string"===i)t=ue(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 ue(e){return se[e]||(se[e]=L(e,ae))}function de(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 me(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n