From cda2ab882ed9a0768b60d42e2ae0da4361de1e8d Mon Sep 17 00:00:00 2001 From: michnhokn Date: Tue, 20 Oct 2020 22:20:22 +0200 Subject: [PATCH 1/2] features made configurable in snippet --- assets/cookie-modal.js | 10 +++++----- package-lock.json | 2 +- package.json | 4 ++-- snippets/cookie-modal.php | 8 ++++++-- src/{js => }/cookie-modal.js | 2 +- src/{scss => }/cookie-modal.scss | 0 6 files changed, 15 insertions(+), 11 deletions(-) rename src/{js => }/cookie-modal.js (98%) rename src/{scss => }/cookie-modal.scss (100%) diff --git a/assets/cookie-modal.js b/assets/cookie-modal.js index 7c2da20..4e8514b 100644 --- a/assets/cookie-modal.js +++ b/assets/cookie-modal.js @@ -1,10 +1,10 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c ]/.test(e)?t(document.createElement("table")).html(e).children().children().nodes:/^\s* ]/.test(e)?t(document.createElement("table")).html(e).children().children().children().nodes:/^\s*-1}).attr({checked:!0}),o.updateButtons())}},{key:"updateCustomFeatures",value:function(){var e=this;e.CUSTOM_FEATURES=[],e.$FEATURES.filter(function(e){return(0,t.default)(e).is(":checked")}).each(function(o){e.CUSTOM_FEATURES.push((0,t.default)(o).data("cookie-id"))}),e.updateButtons()}},{key:"save",value:function(e){event.preventDefault(),(0,t.default)("body").trigger("cookies:saved",e),this.setCookie(e),this.CUSTOM_FEATURES=e,this.closeCookieModal()}},{key:"updateButtons",value:function(){this.CUSTOM_FEATURES.length>1?(this.$ACCEPT_BUTTON.addClass("hide"),this.$DENY_BUTTON.addClass("hide"),this.$SAVE_BUTTON.removeClass("hide")):(this.$ACCEPT_BUTTON.removeClass("hide"),this.$DENY_BUTTON.removeClass("hide"),this.$SAVE_BUTTON.addClass("hide"))}},{key:"setCookie",value:function(t){e.default.set("cookie_status",t.join(","),{expires:365,secure:!0})}},{key:"closeCookieModal",value:function(){this.$COOKIE_MODAL.addClass("cookie-modal--hidden"),this.MODAL_OPEN=!1}},{key:"openCookieModal",value:function(){this.$COOKIE_MODAL.removeClass("cookie-modal--hidden"),this.MODAL_OPEN=!0}}]),o}();(0,t.default)(document).on("DOMContentLoaded",function(e){return new s}); -},{"../scss/cookie-modal.scss":"Uqih","js-cookie":"bggZ","umbrellajs/umbrella.esm":"JBT6"}]},{},["NLXc"], null) \ No newline at end of file +"use strict";require("./cookie-modal.scss");var e=o(require("js-cookie")),t=o(require("umbrellajs/umbrella.esm"));function o(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var o=0;o-1}).attr({checked:!0}),o.updateButtons())}},{key:"updateCustomFeatures",value:function(){var e=this;e.CUSTOM_FEATURES=[],e.$FEATURES.filter(function(e){return(0,t.default)(e).is(":checked")}).each(function(o){e.CUSTOM_FEATURES.push((0,t.default)(o).data("cookie-id"))}),e.updateButtons()}},{key:"save",value:function(e){event.preventDefault(),(0,t.default)("body").trigger("cookies:saved",e),this.setCookie(e),this.CUSTOM_FEATURES=e,this.closeCookieModal()}},{key:"updateButtons",value:function(){this.CUSTOM_FEATURES.length>1?(this.$ACCEPT_BUTTON.addClass("hide"),this.$DENY_BUTTON.addClass("hide"),this.$SAVE_BUTTON.removeClass("hide")):(this.$ACCEPT_BUTTON.removeClass("hide"),this.$DENY_BUTTON.removeClass("hide"),this.$SAVE_BUTTON.addClass("hide"))}},{key:"setCookie",value:function(t){e.default.set("cookie_status",t.join(","),{expires:365,secure:!0})}},{key:"closeCookieModal",value:function(){this.$COOKIE_MODAL.addClass("cookie-modal--hidden"),this.MODAL_OPEN=!1}},{key:"openCookieModal",value:function(){this.$COOKIE_MODAL.removeClass("cookie-modal--hidden"),this.MODAL_OPEN=!0}}]),o}();(0,t.default)(document).on("DOMContentLoaded",function(e){return new s}); +},{"./cookie-modal.scss":"Xtxe","js-cookie":"PhdE","umbrellajs/umbrella.esm":"xp7R"}]},{},["NLXc"], null) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 22170dc..cb2aeba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "kirby3-cookie-banner", - "version": "1.0.2", + "version": "1.0.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7b66bae..a8bfeeb 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "", "author": "Michael Scheurich ", "scripts": { - "dev": "parcel watch ./src/js/cookie-modal.js -d ./assets --public-url ./ --no-hmr", - "build": "parcel build ./src/js/cookie-modal.js -d ./assets --public-url ./ --no-source-maps --no-content-hash" + "dev": "parcel watch ./src/cookie-modal.js -d ./assets --public-url ./ --no-hmr", + "build": "parcel build ./src/cookie-modal.js -d ./assets --public-url ./ --no-source-maps --no-content-hash" }, "devDependencies": { "@babel/core": "^7.5.5", diff --git a/snippets/cookie-modal.php b/snippets/cookie-modal.php index 747f99b..fd45e7d 100644 --- a/snippets/cookie-modal.php +++ b/snippets/cookie-modal.php @@ -1,4 +1,8 @@ - + @@ -13,7 +17,7 @@ 'key' => 'essential', 'title' => t('michnhokn.cookie-banner.essentialText') ]) ?> - $title): ?> + $title): ?> false, 'key' => $key, diff --git a/src/js/cookie-modal.js b/src/cookie-modal.js similarity index 98% rename from src/js/cookie-modal.js rename to src/cookie-modal.js index 7179133..05e3fe7 100644 --- a/src/js/cookie-modal.js +++ b/src/cookie-modal.js @@ -1,4 +1,4 @@ -import '../scss/cookie-modal.scss'; +import './cookie-modal.scss'; import Cookies from 'js-cookie'; import u from 'umbrellajs/umbrella.esm'; diff --git a/src/scss/cookie-modal.scss b/src/cookie-modal.scss similarity index 100% rename from src/scss/cookie-modal.scss rename to src/cookie-modal.scss From 66f7953fd50949bf8d5b9283be928651106a08f9 Mon Sep 17 00:00:00 2001 From: michnhokn Date: Tue, 20 Oct 2020 22:23:01 +0200 Subject: [PATCH 2/2] remove secure setting from cookie --- assets/cookie-modal.js | 2 +- src/cookie-modal.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/assets/cookie-modal.js b/assets/cookie-modal.js index 4e8514b..156b1d3 100644 --- a/assets/cookie-modal.js +++ b/assets/cookie-modal.js @@ -6,5 +6,5 @@ var e;!function(n){var t;if("function"==typeof e&&e.amd&&(e(n),t=!0),"object"==t },{}],"xp7R":[function(require,module,exports) { "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var t=function(e,n){return this instanceof t?e instanceof t?e:("string"==typeof e&&(e=this.select(e,n)),e&&e.nodeName&&(e=[e]),void(this.nodes=this.slice(e))):new t(e,n)};t.prototype={get length(){return this.nodes.length}},t.prototype.nodes=[],t.prototype.addClass=function(){return this.eacharg(arguments,function(t,e){t.classList.add(e)})},t.prototype.adjacent=function(e,n,r){return"number"==typeof n&&(n=0===n?[]:new Array(n).join().split(",").map(Number.call,Number)),this.each(function(o,i){var c=document.createDocumentFragment();t(n||{}).map(function(n,r){var c="function"==typeof e?e.call(this,n,r,o,i):e;return"string"==typeof c?this.generate(c):t(c)}).each(function(e){this.isInPage(e)?c.appendChild(t(e).clone().first()):c.appendChild(e)}),r.call(this,o,c)})},t.prototype.after=function(t,e){return this.adjacent(t,e,function(t,e){t.parentNode.insertBefore(e,t.nextSibling)})},t.prototype.append=function(t,e){return this.adjacent(t,e,function(t,e){t.appendChild(e)})},t.prototype.args=function(t,e,n){return"function"==typeof t&&(t=t(e,n)),"string"!=typeof t&&(t=this.slice(t).map(this.str(e,n))),t.toString().split(/[\s,]+/).filter(function(t){return t.length})},t.prototype.array=function(e){e=e;var n=this;return this.nodes.reduce(function(r,o,i){var c;return e?((c=e.call(n,o,i))||(c=!1),"string"==typeof c&&(c=t(c)),c instanceof t&&(c=c.nodes)):c=o.innerHTML,r.concat(!1!==c?c:[])},[])},t.prototype.attr=function(t,e,n){return n=n?"data-":"",this.pairs(t,e,function(t,e){return t.getAttribute(n+e)},function(t,e,r){t.setAttribute(n+e,r)})},t.prototype.before=function(t,e){return this.adjacent(t,e,function(t,e){t.parentNode.insertBefore(e,t)})},t.prototype.children=function(t){return this.map(function(t){return this.slice(t.children)}).filter(t)},t.prototype.clone=function(){return this.map(function(t,e){var n=t.cloneNode(!0),r=this.getAll(n);return this.getAll(t).each(function(t,e){for(var n in this.mirror)this.mirror[n]&&this.mirror[n](t,r.nodes[e])}),n})},t.prototype.getAll=function(e){return t([e].concat(t("*",e).nodes))},t.prototype.mirror={},t.prototype.mirror.events=function(e,n){if(e._e)for(var r in e._e)e._e[r].forEach(function(e){t(n).on(r,e.callback)})},t.prototype.mirror.select=function(e,n){t(e).is("select")&&(n.value=e.value)},t.prototype.mirror.textarea=function(e,n){t(e).is("textarea")&&(n.value=e.value)},t.prototype.closest=function(e){return this.map(function(n){do{if(t(n).is(e))return n}while((n=n.parentNode)&&n!==document)})},t.prototype.data=function(t,e){return this.attr(t,e,!0)},t.prototype.each=function(t){return this.nodes.forEach(t.bind(this)),this},t.prototype.eacharg=function(t,e){return this.each(function(n,r){this.args(t,n,r).forEach(function(t){e.call(this,n,t)},this)})},t.prototype.empty=function(){return this.each(function(t){for(;t.firstChild;)t.removeChild(t.firstChild)})},t.prototype.filter=function(e){var n=function(t){return t.matches=t.matches||t.msMatchesSelector||t.webkitMatchesSelector,t.matches(e||"*")};return"function"==typeof e&&(n=e),e instanceof t&&(n=function(t){return-1!==e.nodes.indexOf(t)}),t(this.nodes.filter(n))},t.prototype.find=function(e){return this.map(function(n){return t(e||"*",n)})},t.prototype.first=function(){return this.nodes[0]||!1},t.prototype.generate=function(e){return/^\s* ]/.test(e)?t(document.createElement("table")).html(e).children().children().nodes:/^\s* ]/.test(e)?t(document.createElement("table")).html(e).children().children().children().nodes:/^\s*-1}).attr({checked:!0}),o.updateButtons())}},{key:"updateCustomFeatures",value:function(){var e=this;e.CUSTOM_FEATURES=[],e.$FEATURES.filter(function(e){return(0,t.default)(e).is(":checked")}).each(function(o){e.CUSTOM_FEATURES.push((0,t.default)(o).data("cookie-id"))}),e.updateButtons()}},{key:"save",value:function(e){event.preventDefault(),(0,t.default)("body").trigger("cookies:saved",e),this.setCookie(e),this.CUSTOM_FEATURES=e,this.closeCookieModal()}},{key:"updateButtons",value:function(){this.CUSTOM_FEATURES.length>1?(this.$ACCEPT_BUTTON.addClass("hide"),this.$DENY_BUTTON.addClass("hide"),this.$SAVE_BUTTON.removeClass("hide")):(this.$ACCEPT_BUTTON.removeClass("hide"),this.$DENY_BUTTON.removeClass("hide"),this.$SAVE_BUTTON.addClass("hide"))}},{key:"setCookie",value:function(t){e.default.set("cookie_status",t.join(","),{expires:365,secure:!0})}},{key:"closeCookieModal",value:function(){this.$COOKIE_MODAL.addClass("cookie-modal--hidden"),this.MODAL_OPEN=!1}},{key:"openCookieModal",value:function(){this.$COOKIE_MODAL.removeClass("cookie-modal--hidden"),this.MODAL_OPEN=!0}}]),o}();(0,t.default)(document).on("DOMContentLoaded",function(e){return new s}); +"use strict";require("./cookie-modal.scss");var e=o(require("js-cookie")),t=o(require("umbrellajs/umbrella.esm"));function o(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var o=0;o-1}).attr({checked:!0}),o.updateButtons())}},{key:"updateCustomFeatures",value:function(){var e=this;e.CUSTOM_FEATURES=[],e.$FEATURES.filter(function(e){return(0,t.default)(e).is(":checked")}).each(function(o){e.CUSTOM_FEATURES.push((0,t.default)(o).data("cookie-id"))}),e.updateButtons()}},{key:"save",value:function(e){event.preventDefault(),(0,t.default)("body").trigger("cookies:saved",e),this.setCookie(e),this.CUSTOM_FEATURES=e,this.closeCookieModal()}},{key:"updateButtons",value:function(){this.CUSTOM_FEATURES.length>1?(this.$ACCEPT_BUTTON.addClass("hide"),this.$DENY_BUTTON.addClass("hide"),this.$SAVE_BUTTON.removeClass("hide")):(this.$ACCEPT_BUTTON.removeClass("hide"),this.$DENY_BUTTON.removeClass("hide"),this.$SAVE_BUTTON.addClass("hide"))}},{key:"setCookie",value:function(t){e.default.set("cookie_status",t.join(","),{expires:365})}},{key:"closeCookieModal",value:function(){this.$COOKIE_MODAL.addClass("cookie-modal--hidden"),this.MODAL_OPEN=!1}},{key:"openCookieModal",value:function(){this.$COOKIE_MODAL.removeClass("cookie-modal--hidden"),this.MODAL_OPEN=!0}}]),o}();(0,t.default)(document).on("DOMContentLoaded",function(e){return new s}); },{"./cookie-modal.scss":"Xtxe","js-cookie":"PhdE","umbrellajs/umbrella.esm":"xp7R"}]},{},["NLXc"], null) \ No newline at end of file diff --git a/src/cookie-modal.js b/src/cookie-modal.js index 05e3fe7..9c90ba4 100644 --- a/src/cookie-modal.js +++ b/src/cookie-modal.js @@ -86,8 +86,7 @@ class CookieModal { _this.$ACCEPT_BUTTON.addClass('hide'); _this.$DENY_BUTTON.addClass('hide'); _this.$SAVE_BUTTON.removeClass('hide'); - } - else { + } else { _this.$ACCEPT_BUTTON.removeClass('hide'); _this.$DENY_BUTTON.removeClass('hide'); _this.$SAVE_BUTTON.addClass('hide'); @@ -95,11 +94,7 @@ class CookieModal { } setCookie(features) { - Cookies.set( - 'cookie_status', - features.join(','), - {expires: 365, secure: true}, - ); + Cookies.set('cookie_status', features.join(','), {expires: 365}); } closeCookieModal() {