From 5c4899a1196933c91dab229ce5cd85ff402beb18 Mon Sep 17 00:00:00 2001 From: Josef Slezak <32373099+MysterieDev@users.noreply.github.com> Date: Thu, 3 Mar 2022 15:23:01 +0100 Subject: [PATCH] 1.1.1 Callback fix and new Status attribute (#9) * lockfiles * update * fix * add descs * update version * update readme * update callback * update banner --- cookiebanner.yaml | 4 ++-- public/cookiebanner-index.min.js | 2 +- solid-frontend-dev/package.json | 2 +- solid-frontend-dev/src/banner-handling.ts | 16 +++++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cookiebanner.yaml b/cookiebanner.yaml index 517b24d..584ef68 100644 --- a/cookiebanner.yaml +++ b/cookiebanner.yaml @@ -1,5 +1,5 @@ name: Cookie Banner -version: 1.1.0 +version: 1.1.1 description: Enables a cookie banner for websites author: Josef Slezak licence: MIT @@ -22,7 +22,7 @@ forms: label: introduction text as markdown - if you add a link to your data privacy or other links without cookiebanner requirement, add the parameter ?nocb=true javascriptcallback: type: textarea - label: callback of the banner - carries an object: { req: true/false, fun: true/false, mar: true/false} for the categories required, functional and marekting. True is for "user has consented". You can get it with 'e.detail'. You are already inside the callback, so just write javascript-statement-blocks. + label: callback of the banner - carries an object: { req: true/false, fun: true/false, mar: true/false, newConsent: true/false} for the categories required, functional and marekting.True is for "user has consented". The attribute newConsent shows, if the user set the cookies just now or if it already persisted in the storage. You can get it with 'e.detail'. You are already inside the callback, so just write javascript-statement-blocks. consentversion: type: text label: Consent Version - Increment this string number to force a new cookiebanner to show diff --git a/public/cookiebanner-index.min.js b/public/cookiebanner-index.min.js index 8827903..46a19f4 100644 --- a/public/cookiebanner-index.min.js +++ b/public/cookiebanner-index.min.js @@ -1 +1 @@ -import{c as e,t,d as n,a as o,b as i,i as r,S as c,e as s,o as a,f as l,r as d}from"./cookiebanner-vendor.min.js";!function(){const e=document.createElement("link").relList;if(!(e&&e.supports&&e.supports("modulepreload"))){for(const e of document.querySelectorAll('link[rel="modulepreload"]'))t(e);new MutationObserver((e=>{for(const n of e)if("childList"===n.type)for(const e of n.addedNodes)"LINK"===e.tagName&&"modulepreload"===e.rel&&t(e)})).observe(document,{childList:!0,subtree:!0})}function t(e){if(e.ep)return;e.ep=!0;const t=function(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerpolicy&&(t.referrerPolicy=e.referrerpolicy),"use-credentials"===e.crossorigin?t.credentials="include":"anonymous"===e.crossorigin?t.credentials="omit":t.credentials="same-origin",t}(e);fetch(e.href,t)}}();const[u,m]=e({Req:[],Fun:[],Mar:[]});const b=t("

"),g=t('


..

'),h=t('
'),w=t("");function f(e){let t=e.category,n=function(e){const t=[],n=document.querySelector("#cookieDef"+e).content.firstElementChild;if(!n)return[];const o=n.querySelector("tbody");if(!o)return[];const i=o.querySelectorAll("tr");if(!i)return[];return i.forEach((e=>{const n={name:"",host:void 0,persistence:void 0},o=e.querySelectorAll("td");let i=0;o.forEach((()=>{switch(i){case 0:n.name=o[i].innerHTML,i++;break;case 1:n.host=o[i].innerHTML,i++;break;case 2:const e=Number(o[i].innerHTML);n.persistence=function(e){switch(e){case-2:return"Localstorage";case-1:return"Sessionstorage";case 0:return"SESSION";default:return e.toString()}}(e),i=0,t.push(n)}}))})),t}(t);!function(e,t){m(e,(()=>t))}(t,n),window.cookiemeta[t].cookies=u[t];let s=window.cookiemeta.showmore,a=window.cookiemeta.showless;const[l,d]=o(!1);return i(c,{get when(){return n&&n.length>0},get children(){return[(()=>{const e=b.cloneNode(!0);return r(e,(()=>window.cookiemeta[t].headline)),e})(),(()=>{const e=g.cloneNode(!0),n=e.firstChild,o=n.nextSibling;return o.firstChild,e.$$click=()=>{d(!l())},r(e,(()=>window.cookiemeta[t]?window.cookiemeta[t].text:""),n),r(o,(()=>l()?a:s),null),e})(),i(c,{get when(){return l()},get children(){return i(k,{cookies:n,category:t,get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})}})]}})}function k(e){return(()=>{const t=h.cloneNode(!0),n=t.firstChild,o=n.firstChild.firstChild,i=o.nextSibling,c=i.nextSibling,s=n.nextSibling;return r(o,(()=>e.cookieNameTable)),r(i,(()=>e.hostNameTable)),r(c,(()=>e.persistenceNameTable)),r(s,(()=>u[e.category].map((e=>(()=>{const t=w.cloneNode(!0),n=t.firstChild,o=n.nextSibling,i=o.nextSibling;return r(n,(()=>e.name)),r(o,(()=>e.host)),r(i,(()=>e.persistence)),t})())))),t})()}n(["click"]);const v=window.cookiemeta.cookieBannerVersion?window.cookiemeta.cookieBannerVersion.toString():"0";function p(e){return s.set("cbFun",e?"TRUE":"FALSE",{expires:365})}function y(e){return s.set("cbMar",e?"TRUE":"FALSE",{expires:365})}function T(){s.remove("cbReq"),s.remove("cbFun"),s.remove("cbMar")}var C,N;(N=C||(C={})).required="Req",N.functional="Fun",N.marketing="Mar";let S={req:!0,fun:!1,mar:!1};const E=new CustomEvent("bannerconsent",{detail:S});function q(e){!function(e){void s.set("cbSet",v,{expires:365}),void s.set("cbReq","TRUE",{expires:365}),e===C.functional?(p(!0),S.fun=!0):p(!1);e===C.marketing?(p(!0),y(!0),S.fun=!0,S.mar=!0):y(!1);L(!1)}(e),document.body.classList.remove("cbPreventScroll"),document.querySelector("#solidApp").style.display="none"}function L(e){e&&(S={req:!0,fun:"TRUE"===s.get("cbFun"),mar:"TRUE"===s.get("cbMar")}),window.dispatchEvent(E)}const M=t(''),x=t('
'),R=t('
'),$=t('

'),F=()=>{function e(){return(()=>{const e=M.cloneNode(!0);return e.$$click=()=>q(C.marketing),r(e,(()=>window.cookiemeta.acceptallbtn)),e})()}return a((()=>{document.body.classList.add("cbPreventScroll")})),(()=>{const t=$.cloneNode(!0),n=t.firstChild,o=n.firstChild,s=o.firstChild,a=o.nextSibling,d=a.nextSibling,m=d.firstChild.firstChild;return r(n,i(f,{get category(){return C.required}}),d),r(n,i(f,{get category(){return C.functional}}),d),r(n,i(f,{get category(){return C.marketing}}),d),m.$$click=()=>q(C.required),r(m,(()=>window.cookiemeta.declinenonrequiredbtn)),r(d,i(c,{get when(){return 0===u.Fun.length},get children(){const t=x.cloneNode(!0);return r(t,e),t}}),null),r(n,i(c,{get when(){return u.Fun.length>0},get children(){const t=R.cloneNode(!0),n=t.firstChild,o=n.firstChild,i=n.nextSibling;return o.$$click=()=>q(C.functional),r(o,(()=>window.cookiemeta.onlyfunctionalbtn)),r(i,e),t}}),null),l((e=>{const t=window.cookiemeta.headline,n=window.cookiemeta.introduction;return t!==e._v$&&(s.data=e._v$=t),n!==e._v$2&&(a.innerHTML=e._v$2=n),e}),{_v$:void 0,_v$2:void 0}),t})()};n(["click"]),new URL(window.location.href).searchParams.get("nocb")||s.get("cbSet")===v&&s.get("cbReq")&&s.get("cbFun")&&s.get("cbMar")||(T(),0)?L(!0):d((()=>i(F,{})),document.getElementById("solidApp"));const B=document.getElementById("cbReqTable");if(B){B.outerHTML='
';const e=document.createElement("DIV");B.appendChild(e),d((()=>i(f,{get category(){return C.required},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbReqTable"))}const I=document.getElementById("cbFunTable");I&&(I.outerHTML='
',d((()=>i(f,{get category(){return C.functional},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbFunTable")));const A=document.getElementById("cbMarTable");A&&(A.outerHTML='
',d((()=>i(f,{get category(){return C.marketing},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbMarTable"))); \ No newline at end of file +var e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,c=(t,n,o)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[n]=o,a=(e,t)=>{for(var n in t||(t={}))r.call(t,n)&&c(e,n,t[n]);if(o)for(var n of o(t))i.call(t,n)&&c(e,n,t[n]);return e};import{c as s,t as l,d,a as u,b as m,i as b,S as g,e as f,o as w,f as h,r as k}from"./cookiebanner-vendor.min.js";!function(){const e=document.createElement("link").relList;if(!(e&&e.supports&&e.supports("modulepreload"))){for(const e of document.querySelectorAll('link[rel="modulepreload"]'))t(e);new MutationObserver((e=>{for(const n of e)if("childList"===n.type)for(const e of n.addedNodes)"LINK"===e.tagName&&"modulepreload"===e.rel&&t(e)})).observe(document,{childList:!0,subtree:!0})}function t(e){if(e.ep)return;e.ep=!0;const t=function(e){const t={};return e.integrity&&(t.integrity=e.integrity),e.referrerpolicy&&(t.referrerPolicy=e.referrerpolicy),"use-credentials"===e.crossorigin?t.credentials="include":"anonymous"===e.crossorigin?t.credentials="omit":t.credentials="same-origin",t}(e);fetch(e.href,t)}}();const[p,v]=s({Req:[],Fun:[],Mar:[]});const y=l("

"),T=l('


..

'),C=l('
'),S=l("");function N(e){let t=e.category,n=function(e){const t=[],n=document.querySelector("#cookieDef"+e).content.firstElementChild;if(!n)return[];const o=n.querySelector("tbody");if(!o)return[];const r=o.querySelectorAll("tr");if(!r)return[];return r.forEach((e=>{const n={name:"",host:void 0,persistence:void 0},o=e.querySelectorAll("td");let r=0;o.forEach((()=>{switch(r){case 0:n.name=o[r].innerHTML,r++;break;case 1:n.host=o[r].innerHTML,r++;break;case 2:const e=Number(o[r].innerHTML);n.persistence=function(e){switch(e){case-2:return"Localstorage";case-1:return"Sessionstorage";case 0:return"SESSION";default:return e.toString()}}(e),r=0,t.push(n)}}))})),t}(t);!function(e,t){v(e,(()=>t))}(t,n),window.cookiemeta[t].cookies=p[t];let o=window.cookiemeta.showmore,r=window.cookiemeta.showless;const[i,c]=u(!1);return m(g,{get when(){return n&&n.length>0},get children(){return[(()=>{const e=y.cloneNode(!0);return b(e,(()=>window.cookiemeta[t].headline)),e})(),(()=>{const e=T.cloneNode(!0),n=e.firstChild,a=n.nextSibling;return a.firstChild,e.$$click=()=>{c(!i())},b(e,(()=>window.cookiemeta[t]?window.cookiemeta[t].text:""),n),b(a,(()=>i()?r:o),null),e})(),m(g,{get when(){return i()},get children(){return m(E,{cookies:n,category:t,get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})}})]}})}function E(e){return(()=>{const t=C.cloneNode(!0),n=t.firstChild,o=n.firstChild.firstChild,r=o.nextSibling,i=r.nextSibling,c=n.nextSibling;return b(o,(()=>e.cookieNameTable)),b(r,(()=>e.hostNameTable)),b(i,(()=>e.persistenceNameTable)),b(c,(()=>p[e.category].map((e=>(()=>{const t=S.cloneNode(!0),n=t.firstChild,o=n.nextSibling,r=o.nextSibling;return b(n,(()=>e.name)),b(o,(()=>e.host)),b(r,(()=>e.persistence)),t})())))),t})()}d(["click"]);const q=window.cookiemeta.cookieBannerVersion?window.cookiemeta.cookieBannerVersion.toString():"0";function L(e){return f.set("cbFun",e?"TRUE":"FALSE",{expires:365})}function M(e){return f.set("cbMar",e?"TRUE":"FALSE",{expires:365})}function x(){f.remove("cbReq"),f.remove("cbFun"),f.remove("cbMar")}var R,$;($=R||(R={})).required="Req",$.functional="Fun",$.marketing="Mar";let F={req:!0,fun:!1,mar:!1};function I(e){!function(e){void f.set("cbSet",q,{expires:365}),void f.set("cbReq","TRUE",{expires:365}),e===R.functional?(L(!0),F.fun=!0):L(!1);e===R.marketing?(L(!0),M(!0),F.fun=!0,F.mar=!0):M(!1);O(!1)}(e),document.body.classList.remove("cbPreventScroll"),document.querySelector("#solidApp").style.display="none"}function O(e){var o,r,i,c;e&&(o={req:!0,fun:"TRUE"===f.get("cbFun"),mar:"TRUE"===f.get("cbMar")},F=o),window.dispatchEvent((r=!e,new CustomEvent("bannerconsent",{detail:(i=a({},F),c={newConsent:r},t(i,n(c)))})))}const B=l(''),P=l('
'),j=l('
'),A=l('

'),H=()=>{function e(){return(()=>{const e=B.cloneNode(!0);return e.$$click=()=>I(R.marketing),b(e,(()=>window.cookiemeta.acceptallbtn)),e})()}return w((()=>{document.body.classList.add("cbPreventScroll")})),(()=>{const t=A.cloneNode(!0),n=t.firstChild,o=n.firstChild,r=o.firstChild,i=o.nextSibling,c=i.nextSibling,a=c.firstChild.firstChild;return b(n,m(N,{get category(){return R.required}}),c),b(n,m(N,{get category(){return R.functional}}),c),b(n,m(N,{get category(){return R.marketing}}),c),a.$$click=()=>I(R.required),b(a,(()=>window.cookiemeta.declinenonrequiredbtn)),b(c,m(g,{get when(){return 0===p.Fun.length},get children(){const t=P.cloneNode(!0);return b(t,e),t}}),null),b(n,m(g,{get when(){return p.Fun.length>0},get children(){const t=j.cloneNode(!0),n=t.firstChild,o=n.firstChild,r=n.nextSibling;return o.$$click=()=>I(R.functional),b(o,(()=>window.cookiemeta.onlyfunctionalbtn)),b(r,e),t}}),null),h((e=>{const t=window.cookiemeta.headline,n=window.cookiemeta.introduction;return t!==e._v$&&(r.data=e._v$=t),n!==e._v$2&&(i.innerHTML=e._v$2=n),e}),{_v$:void 0,_v$2:void 0}),t})()};d(["click"]),new URL(window.location.href).searchParams.get("nocb")||f.get("cbSet")===q&&f.get("cbReq")&&f.get("cbFun")&&f.get("cbMar")||(x(),0)?O(!0):k((()=>m(H,{})),document.getElementById("solidApp"));const U=document.getElementById("cbReqTable");if(U){U.outerHTML='
';const e=document.createElement("DIV");U.appendChild(e),k((()=>m(N,{get category(){return R.required},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbReqTable"))}const _=document.getElementById("cbFunTable");_&&(_.outerHTML='
',k((()=>m(N,{get category(){return R.functional},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbFunTable")));const D=document.getElementById("cbMarTable");D&&(D.outerHTML='
',k((()=>m(N,{get category(){return R.marketing},get cookieNameTable(){return window.cookiemeta.cookienameColumn},get hostNameTable(){return window.cookiemeta.cookiehostColumn},get persistenceNameTable(){return window.cookiemeta.cookiepersistenceColumn}})),document.getElementById("cbMarTable"))); \ No newline at end of file diff --git a/solid-frontend-dev/package.json b/solid-frontend-dev/package.json index 3e07826..cde219b 100644 --- a/solid-frontend-dev/package.json +++ b/solid-frontend-dev/package.json @@ -1,6 +1,6 @@ { "name": "vite-template-solid", - "version": "1.1.0", + "version": "1.1.1", "description": "", "scripts": { "start": "vite", diff --git a/solid-frontend-dev/src/banner-handling.ts b/solid-frontend-dev/src/banner-handling.ts index c165679..add0c42 100644 --- a/solid-frontend-dev/src/banner-handling.ts +++ b/solid-frontend-dev/src/banner-handling.ts @@ -8,11 +8,13 @@ import { import { CookieCategory } from "./types"; let consent = { req: true, fun: false, mar: false }; - -const finishedConsentEvent = new CustomEvent("bannerconsent", { - detail: consent, +const getConsent = ()=> consent +const finishedConsentEvent = (didSeeCookiebannerUI: boolean) => new CustomEvent("bannerconsent", { + detail: {...getConsent(), newConsent: didSeeCookiebannerUI}, }); +const setConsent = (details)=> {consent = details}; + export const rootName = "#solidApp"; export const preventScrollClass = "cbPreventScroll"; @@ -43,11 +45,11 @@ export function handleFinishedConsentInteraction(category: CookieCategory) { fireCallback(false); } -export function fireCallback(checkCookies: boolean) { - if (checkCookies) { - consent = getConsentCookies(); +export function fireCallback(cbAlreadySeen: boolean) { + if (cbAlreadySeen) { + setConsent(getConsentCookies()); } - window.dispatchEvent(finishedConsentEvent); + window.dispatchEvent(finishedConsentEvent(!cbAlreadySeen)); } export function disableOtherUI() {