diff --git a/__tests__/e2e.tests.js b/__tests__/e2e.tests.js index b6e0056..ec649f6 100644 --- a/__tests__/e2e.tests.js +++ b/__tests__/e2e.tests.js @@ -90,9 +90,9 @@ appVersions.forEach(([filename])=>{ test('should hide UI and save consents correctly after selecting some sections', async () => { await page.click('button[data-id=settings]') - await page.click('[for=biscuitman_analytics]') - await page.click('[for=biscuitman_functional]') - await page.click('[for=biscuitman_performance]') + await page.click('[for=bm_analytics]') + await page.click('[for=bm_functional]') + await page.click('[for=bm_performance]') await page.click('button[data-id=save]') diff --git a/dist/biscuitman.css b/dist/biscuitman.css index 1bc2a05..12003b6 100644 --- a/dist/biscuitman.css +++ b/dist/biscuitman.css @@ -1,4 +1,4 @@ -/*! biscuitman.js 0.4.0 */ +/*! biscuitman.js 0.4.1 */ .biscuitman { --ui: 0, 0, 0; --tx: #444; diff --git a/dist/biscuitman.js b/dist/biscuitman.js index 0a438f6..672297f 100644 --- a/dist/biscuitman.js +++ b/dist/biscuitman.js @@ -1,5 +1,5 @@ -/*! biscuitman.js 0.4.0 */ -((d, w, O, h, bm)=>{ +/*! biscuitman.js 0.4.1 */ +((d, w, O, h)=>{ const defaults = { key: 'myconsent', global: 'Consent', @@ -28,7 +28,7 @@ const ui = d.createElement('div'); let dialog; function render() { - ui.classList.add(bm); + ui.classList.add('biscuitman'); ui.innerHTML = `
${o.title} @@ -60,8 +60,8 @@
${o[`${section}Title`]} - @@ -101,7 +101,6 @@ }; const applyCssClasses = ()=>{ let { consentTime, ...consents } = getConsents(); - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(o.sections.slice(1).map((sectionName)=>[ sectionName, false @@ -314,4 +313,4 @@ }); openModal(); }; -})(document, window, Object, document.documentElement, 'biscuitman'); +})(document, window, Object, document.documentElement); diff --git a/dist/biscuitman.min.css b/dist/biscuitman.min.css index ef0bbaf..0a25526 100644 --- a/dist/biscuitman.min.css +++ b/dist/biscuitman.min.css @@ -1 +1 @@ -/*! biscuitman.js 0.4.0 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)} \ No newline at end of file +/*! biscuitman.js 0.4.1 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)} \ No newline at end of file diff --git a/dist/biscuitman.min.js b/dist/biscuitman.min.js index 2fd12ed..16961e8 100644 --- a/dist/biscuitman.min.js +++ b/dist/biscuitman.min.js @@ -1 +1 @@ -/*! biscuitman.js 0.4.0 */((e,t,o,a,n)=>{let i;let s={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1,...t.biscuitman},c=e.createElement("div"),l=()=>{a.style.setProperty("--bm-height",`${c.offsetHeight}px`)},r=e=>{a.classList.toggle("bm-show",e),l()},d=()=>{let{consentTime:e,...t}=$();for(let[n,i]of(e||(t=o.fromEntries(s.sections.slice(1).map(e=>[e,!1]))),o.entries(t)))a.classList.toggle(`bm-${n}`,i),a.classList.toggle(`bm-no-${n}`,!i)};function m(e){let t=e.target.dataset.id;switch(f("button",{id:t}),t){case"accept":E(!0);break;case"close":i.close();break;case"settings":b();break;case"save":E();break;case"reject":E(!1)}}function p(){f("close")}function u(e){s.force&&e.preventDefault()}function b(){f("open"),i.showModal()}function f(t,o){let a=`bm:${t}`,n={...void 0!==o&&o,time:+new Date};e.dispatchEvent(new CustomEvent(a,{detail:n})),console.debug(a,n)}let $=()=>t[s.global]||{};function g(e){t[s.global]=e,d()}function v(e,t){for(let o in e)e[o]&&!1===t[o]&&f("revoke",{section:o})}function k(){try{return JSON.parse(localStorage.getItem(s.key))}catch(e){return console.error(e),localStorage.removeItem(s.key),{}}}function h(){let t=o.fromEntries(o.entries(localStorage)),a=o.fromEntries(e.cookie.split("; ").map(e=>e.split("="))),{consentTime:n,...i}=k()||s.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[n,c]of o.entries(i)){if(c)continue;let i=o.keys(s[`${n}Cookies`]||{});for(let n of(i.filter(e=>e.endsWith("*")).map(e=>{o.keys({...a,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&i.push(t)})}),i)){if(a[n]){let t=`${n}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;e.cookie=t,e.cookie=`${t}domain=${location.hostname};`,e.cookie=`${t}domain=.${location.hostname};`,f("delete",{cookie:n})}t[n]&&(localStorage.removeItem(n),f("delete",{localStorage:n}))}}}function E(e){let t=void 0===e,o={consentTime:+new Date};s.sections.forEach(a=>{if("essential"===a)return!1;let n=c.querySelector(`[data-s=${a}]`),i=t?n.checked:e;o[a]=i,t||(n.checked=e)}),v($(),o),g(o),localStorage.setItem(s.key,JSON.stringify(o)),f("save",{data:o}),h(),y(),i.open&&i.close(),r(!1)}function y(){e.querySelectorAll("script[data-consent]").forEach(t=>{if(!$()[t.dataset.consent])return!1;let o=e.createElement("script");for(let{name:e,value:a}of t.attributes)e.startsWith("data-")||"type"===e||o.setAttribute(e,a);o.setAttribute("type",t.dataset.type||"text/javascript"),t.src||(o.textContent=t.textContent),t.parentNode.replaceChild(o,t),f("inject",{el:t,...t.id&&{id:t.id}}),t.src&&""!==t.textContent.trim()&&o.addEventListener("load",()=>{let a=e.createElement("script");a.textContent=t.textContent,t.id&&(a.id=t.id+"-after"),o.insertAdjacentElement("afterend",a),f("inject",{el:a,parent:t,...a.id&&{id:a.id}})})})}g(k()||{});let T=Intl.DateTimeFormat().resolvedOptions().timeZone,S=/^(GMT|UTC)$/.test(T)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(T);s.acceptNonEU&&!S&&(E(!0),r(!1)),function(){c.classList.add(n),c.innerHTML=`
${s.title}

${s.message}

${s.settingsTitle}

${s.message}

${s.info.split("\n").map((e,t,o)=>`${e}${o.length>1&&s.enableMore&&0==t?`${s.more}`:""}`).join("")}

${s.sections.map(e=>{let t=$()[e],a="essential"===e,i=a?"disabled":"",c=a?"checked":"";void 0!==t&&(c=t?"checked":"");let l=s[`${e}Cookies`];return`
${s[`${e}Title`]}

${s[`${e}Message`]}

${l?o.entries(l).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${s.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${s.linkText}`),c.querySelectorAll("button").forEach(e=>e.addEventListener("click",m)),(i=c.querySelector("dialog")).addEventListener("close",p),i.addEventListener("cancel",u);let a=c.querySelector(".more");a&&a.addEventListener("click",a.remove),c.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),e.body.appendChild(c),t.addEventListener("resize",l)}(),h(),t[s.global].consentTime?(r(!1),y()):(r(!0),s.force&&b()),t.bmInvalidate=()=>{f("invalidate",{data:$()}),v({}),E(!1),g({}),localStorage.removeItem(s.key),r(!0)},t.bmUpdate=()=>{f("update",{data:$()}),b()}})(document,window,Object,document.documentElement,"biscuitman"); \ No newline at end of file +/*! biscuitman.js 0.4.1 */((e,t,o,a)=>{let n;let i={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1,...t.biscuitman},s=e.createElement("div"),c=()=>{a.style.setProperty("--bm-height",`${s.offsetHeight}px`)},l=e=>{a.classList.toggle("bm-show",e),c()},r=()=>{let{consentTime:e,...t}=f();for(let[n,s]of(e||(t=o.fromEntries(i.sections.slice(1).map(e=>[e,!1]))),o.entries(t)))a.classList.toggle(`bm-${n}`,s),a.classList.toggle(`bm-no-${n}`,!s)};function d(e){let t=e.target.dataset.id;switch(b("button",{id:t}),t){case"accept":h(!0);break;case"close":n.close();break;case"settings":u();break;case"save":h();break;case"reject":h(!1)}}function m(){b("close")}function p(e){i.force&&e.preventDefault()}function u(){b("open"),n.showModal()}function b(t,o){let a=`bm:${t}`,n={...void 0!==o&&o,time:+new Date};e.dispatchEvent(new CustomEvent(a,{detail:n})),console.debug(a,n)}let f=()=>t[i.global]||{};function $(e){t[i.global]=e,r()}function g(e,t){for(let o in e)e[o]&&!1===t[o]&&b("revoke",{section:o})}function v(){try{return JSON.parse(localStorage.getItem(i.key))}catch(e){return console.error(e),localStorage.removeItem(i.key),{}}}function k(){let t=o.fromEntries(o.entries(localStorage)),a=o.fromEntries(e.cookie.split("; ").map(e=>e.split("="))),{consentTime:n,...s}=v()||i.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[n,c]of o.entries(s)){if(c)continue;let s=o.keys(i[`${n}Cookies`]||{});for(let n of(s.filter(e=>e.endsWith("*")).map(e=>{o.keys({...a,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&s.push(t)})}),s)){if(a[n]){let t=`${n}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;e.cookie=t,e.cookie=`${t}domain=${location.hostname};`,e.cookie=`${t}domain=.${location.hostname};`,b("delete",{cookie:n})}t[n]&&(localStorage.removeItem(n),b("delete",{localStorage:n}))}}}function h(e){let t=void 0===e,o={consentTime:+new Date};i.sections.forEach(a=>{if("essential"===a)return!1;let n=s.querySelector(`[data-s=${a}]`),i=t?n.checked:e;o[a]=i,t||(n.checked=e)}),g(f(),o),$(o),localStorage.setItem(i.key,JSON.stringify(o)),b("save",{data:o}),k(),E(),n.open&&n.close(),l(!1)}function E(){e.querySelectorAll("script[data-consent]").forEach(t=>{if(!f()[t.dataset.consent])return!1;let o=e.createElement("script");for(let{name:e,value:a}of t.attributes)e.startsWith("data-")||"type"===e||o.setAttribute(e,a);o.setAttribute("type",t.dataset.type||"text/javascript"),t.src||(o.textContent=t.textContent),t.parentNode.replaceChild(o,t),b("inject",{el:t,...t.id&&{id:t.id}}),t.src&&""!==t.textContent.trim()&&o.addEventListener("load",()=>{let a=e.createElement("script");a.textContent=t.textContent,t.id&&(a.id=t.id+"-after"),o.insertAdjacentElement("afterend",a),b("inject",{el:a,parent:t,...a.id&&{id:a.id}})})})}$(v()||{});let y=Intl.DateTimeFormat().resolvedOptions().timeZone,T=/^(GMT|UTC)$/.test(y)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(y);i.acceptNonEU&&!T&&(h(!0),l(!1)),function(){s.classList.add("biscuitman"),s.innerHTML=`
${i.title}

${i.message}

${i.settingsTitle}

${i.message}

${i.info.split("\n").map((e,t,o)=>`${e}${o.length>1&&i.enableMore&&0==t?`${i.more}`:""}`).join("")}

${i.sections.map(e=>{let t=f()[e],a="essential"===e,n=a?"disabled":"",s=a?"checked":"";void 0!==t&&(s=t?"checked":"");let c=i[`${e}Cookies`];return`
${i[`${e}Title`]}

${i[`${e}Message`]}

${c?o.entries(c).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${i.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${i.linkText}`),s.querySelectorAll("button").forEach(e=>e.addEventListener("click",d)),(n=s.querySelector("dialog")).addEventListener("close",m),n.addEventListener("cancel",p);let a=s.querySelector(".more");a&&a.addEventListener("click",a.remove),s.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),e.body.appendChild(s),t.addEventListener("resize",c)}(),k(),t[i.global].consentTime?(l(!1),E()):(l(!0),i.force&&u()),t.bmInvalidate=()=>{b("invalidate",{data:f()}),g({}),h(!1),$({}),localStorage.removeItem(i.key),l(!0)},t.bmUpdate=()=>{b("update",{data:f()}),u()}})(document,window,Object,document.documentElement); \ No newline at end of file diff --git a/dist/biscuitman.withcss.js b/dist/biscuitman.withcss.js index f99b1b9..451d5b3 100644 --- a/dist/biscuitman.withcss.js +++ b/dist/biscuitman.withcss.js @@ -1,5 +1,5 @@ -/*! biscuitman.js 0.4.0 */ -((d, w, O, h, bm)=>{ +/*! biscuitman.js 0.4.1 */ +((d, w, O, h)=>{ const defaults = { key: 'myconsent', global: 'Consent', @@ -28,7 +28,7 @@ const ui = d.createElement('div'); let dialog; function render() { - ui.classList.add(bm); + ui.classList.add('biscuitman'); ui.innerHTML = `
${o.title} @@ -60,8 +60,8 @@
${o[`${section}Title`]} - @@ -101,7 +101,6 @@ }; const applyCssClasses = ()=>{ let { consentTime, ...consents } = getConsents(); - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(o.sections.slice(1).map((sectionName)=>[ sectionName, false @@ -314,11 +313,11 @@ }); openModal(); }; -})(document, window, Object, document.documentElement, 'biscuitman'); +})(document, window, Object, document.documentElement); ; ((d)=>{ let css=d.createElement('style'); - css.textContent=`/*! biscuitman.js 0.4.0 */ + css.textContent=`/*! biscuitman.js 0.4.1 */ .biscuitman { --ui: 0, 0, 0; --tx: #444; diff --git a/dist/biscuitman.withcss.min.js b/dist/biscuitman.withcss.min.js index d1f2520..1c9ca95 100644 --- a/dist/biscuitman.withcss.min.js +++ b/dist/biscuitman.withcss.min.js @@ -1 +1 @@ -/*! biscuitman.js 0.4.0 */((e,t,o,a,n)=>{let i;let s={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1,...t.biscuitman},c=e.createElement("div"),l=()=>{a.style.setProperty("--bm-height",`${c.offsetHeight}px`)},r=e=>{a.classList.toggle("bm-show",e),l()},d=()=>{let{consentTime:e,...t}=$();for(let[n,i]of(e||(t=o.fromEntries(s.sections.slice(1).map(e=>[e,!1]))),o.entries(t)))a.classList.toggle(`bm-${n}`,i),a.classList.toggle(`bm-no-${n}`,!i)};function m(e){let t=e.target.dataset.id;switch(f("button",{id:t}),t){case"accept":E(!0);break;case"close":i.close();break;case"settings":b();break;case"save":E();break;case"reject":E(!1)}}function p(){f("close")}function u(e){s.force&&e.preventDefault()}function b(){f("open"),i.showModal()}function f(t,o){let a=`bm:${t}`,n={...void 0!==o&&o,time:+new Date};e.dispatchEvent(new CustomEvent(a,{detail:n})),console.debug(a,n)}let $=()=>t[s.global]||{};function g(e){t[s.global]=e,d()}function v(e,t){for(let o in e)e[o]&&!1===t[o]&&f("revoke",{section:o})}function k(){try{return JSON.parse(localStorage.getItem(s.key))}catch(e){return console.error(e),localStorage.removeItem(s.key),{}}}function h(){let t=o.fromEntries(o.entries(localStorage)),a=o.fromEntries(e.cookie.split("; ").map(e=>e.split("="))),{consentTime:n,...i}=k()||s.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[n,c]of o.entries(i)){if(c)continue;let i=o.keys(s[`${n}Cookies`]||{});for(let n of(i.filter(e=>e.endsWith("*")).map(e=>{o.keys({...a,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&i.push(t)})}),i)){if(a[n]){let t=`${n}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;e.cookie=t,e.cookie=`${t}domain=${location.hostname};`,e.cookie=`${t}domain=.${location.hostname};`,f("delete",{cookie:n})}t[n]&&(localStorage.removeItem(n),f("delete",{localStorage:n}))}}}function E(e){let t=void 0===e,o={consentTime:+new Date};s.sections.forEach(a=>{if("essential"===a)return!1;let n=c.querySelector(`[data-s=${a}]`),i=t?n.checked:e;o[a]=i,t||(n.checked=e)}),v($(),o),g(o),localStorage.setItem(s.key,JSON.stringify(o)),f("save",{data:o}),h(),y(),i.open&&i.close(),r(!1)}function y(){e.querySelectorAll("script[data-consent]").forEach(t=>{if(!$()[t.dataset.consent])return!1;let o=e.createElement("script");for(let{name:e,value:a}of t.attributes)e.startsWith("data-")||"type"===e||o.setAttribute(e,a);o.setAttribute("type",t.dataset.type||"text/javascript"),t.src||(o.textContent=t.textContent),t.parentNode.replaceChild(o,t),f("inject",{el:t,...t.id&&{id:t.id}}),t.src&&""!==t.textContent.trim()&&o.addEventListener("load",()=>{let a=e.createElement("script");a.textContent=t.textContent,t.id&&(a.id=t.id+"-after"),o.insertAdjacentElement("afterend",a),f("inject",{el:a,parent:t,...a.id&&{id:a.id}})})})}g(k()||{});let T=Intl.DateTimeFormat().resolvedOptions().timeZone,S=/^(GMT|UTC)$/.test(T)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(T);s.acceptNonEU&&!S&&(E(!0),r(!1)),function(){c.classList.add(n),c.innerHTML=`
${s.title}

${s.message}

${s.settingsTitle}

${s.message}

${s.info.split("\n").map((e,t,o)=>`${e}${o.length>1&&s.enableMore&&0==t?`${s.more}`:""}`).join("")}

${s.sections.map(e=>{let t=$()[e],a="essential"===e,i=a?"disabled":"",c=a?"checked":"";void 0!==t&&(c=t?"checked":"");let l=s[`${e}Cookies`];return`
${s[`${e}Title`]}

${s[`${e}Message`]}

${l?o.entries(l).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${s.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${s.linkText}`),c.querySelectorAll("button").forEach(e=>e.addEventListener("click",m)),(i=c.querySelector("dialog")).addEventListener("close",p),i.addEventListener("cancel",u);let a=c.querySelector(".more");a&&a.addEventListener("click",a.remove),c.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),e.body.appendChild(c),t.addEventListener("resize",l)}(),h(),t[s.global].consentTime?(r(!1),y()):(r(!0),s.force&&b()),t.bmInvalidate=()=>{f("invalidate",{data:$()}),v({}),E(!1),g({}),localStorage.removeItem(s.key),r(!0)},t.bmUpdate=()=>{f("update",{data:$()}),b()}})(document,window,Object,document.documentElement,"biscuitman");;((d)=>{let c=d.createElement('style');c.textContent=`/*! biscuitman.js 0.4.0 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)}`;d.head.appendChild(c)})(document); \ No newline at end of file +/*! biscuitman.js 0.4.1 */((e,t,o,a)=>{let n;let i={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1,...t.biscuitman},s=e.createElement("div"),c=()=>{a.style.setProperty("--bm-height",`${s.offsetHeight}px`)},l=e=>{a.classList.toggle("bm-show",e),c()},r=()=>{let{consentTime:e,...t}=f();for(let[n,s]of(e||(t=o.fromEntries(i.sections.slice(1).map(e=>[e,!1]))),o.entries(t)))a.classList.toggle(`bm-${n}`,s),a.classList.toggle(`bm-no-${n}`,!s)};function d(e){let t=e.target.dataset.id;switch(b("button",{id:t}),t){case"accept":h(!0);break;case"close":n.close();break;case"settings":u();break;case"save":h();break;case"reject":h(!1)}}function m(){b("close")}function p(e){i.force&&e.preventDefault()}function u(){b("open"),n.showModal()}function b(t,o){let a=`bm:${t}`,n={...void 0!==o&&o,time:+new Date};e.dispatchEvent(new CustomEvent(a,{detail:n})),console.debug(a,n)}let f=()=>t[i.global]||{};function $(e){t[i.global]=e,r()}function g(e,t){for(let o in e)e[o]&&!1===t[o]&&b("revoke",{section:o})}function v(){try{return JSON.parse(localStorage.getItem(i.key))}catch(e){return console.error(e),localStorage.removeItem(i.key),{}}}function k(){let t=o.fromEntries(o.entries(localStorage)),a=o.fromEntries(e.cookie.split("; ").map(e=>e.split("="))),{consentTime:n,...s}=v()||i.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[n,c]of o.entries(s)){if(c)continue;let s=o.keys(i[`${n}Cookies`]||{});for(let n of(s.filter(e=>e.endsWith("*")).map(e=>{o.keys({...a,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&s.push(t)})}),s)){if(a[n]){let t=`${n}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;e.cookie=t,e.cookie=`${t}domain=${location.hostname};`,e.cookie=`${t}domain=.${location.hostname};`,b("delete",{cookie:n})}t[n]&&(localStorage.removeItem(n),b("delete",{localStorage:n}))}}}function h(e){let t=void 0===e,o={consentTime:+new Date};i.sections.forEach(a=>{if("essential"===a)return!1;let n=s.querySelector(`[data-s=${a}]`),i=t?n.checked:e;o[a]=i,t||(n.checked=e)}),g(f(),o),$(o),localStorage.setItem(i.key,JSON.stringify(o)),b("save",{data:o}),k(),E(),n.open&&n.close(),l(!1)}function E(){e.querySelectorAll("script[data-consent]").forEach(t=>{if(!f()[t.dataset.consent])return!1;let o=e.createElement("script");for(let{name:e,value:a}of t.attributes)e.startsWith("data-")||"type"===e||o.setAttribute(e,a);o.setAttribute("type",t.dataset.type||"text/javascript"),t.src||(o.textContent=t.textContent),t.parentNode.replaceChild(o,t),b("inject",{el:t,...t.id&&{id:t.id}}),t.src&&""!==t.textContent.trim()&&o.addEventListener("load",()=>{let a=e.createElement("script");a.textContent=t.textContent,t.id&&(a.id=t.id+"-after"),o.insertAdjacentElement("afterend",a),b("inject",{el:a,parent:t,...a.id&&{id:a.id}})})})}$(v()||{});let y=Intl.DateTimeFormat().resolvedOptions().timeZone,T=/^(GMT|UTC)$/.test(y)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(y);i.acceptNonEU&&!T&&(h(!0),l(!1)),function(){s.classList.add("biscuitman"),s.innerHTML=`
${i.title}

${i.message}

${i.settingsTitle}

${i.message}

${i.info.split("\n").map((e,t,o)=>`${e}${o.length>1&&i.enableMore&&0==t?`${i.more}`:""}`).join("")}

${i.sections.map(e=>{let t=f()[e],a="essential"===e,n=a?"disabled":"",s=a?"checked":"";void 0!==t&&(s=t?"checked":"");let c=i[`${e}Cookies`];return`
${i[`${e}Title`]}

${i[`${e}Message`]}

${c?o.entries(c).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${i.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${i.linkText}`),s.querySelectorAll("button").forEach(e=>e.addEventListener("click",d)),(n=s.querySelector("dialog")).addEventListener("close",m),n.addEventListener("cancel",p);let a=s.querySelector(".more");a&&a.addEventListener("click",a.remove),s.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),e.body.appendChild(s),t.addEventListener("resize",c)}(),k(),t[i.global].consentTime?(l(!1),E()):(l(!0),i.force&&u()),t.bmInvalidate=()=>{b("invalidate",{data:f()}),g({}),h(!1),$({}),localStorage.removeItem(i.key),l(!0)},t.bmUpdate=()=>{b("update",{data:f()}),u()}})(document,window,Object,document.documentElement);;((d)=>{let c=d.createElement('style');c.textContent=`/*! biscuitman.js 0.4.1 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)}`;d.head.appendChild(c)})(document); \ No newline at end of file diff --git a/dist/esm/biscuitman.min.mjs b/dist/esm/biscuitman.min.mjs index cd8a817..dc4557f 100644 --- a/dist/esm/biscuitman.min.mjs +++ b/dist/esm/biscuitman.min.mjs @@ -1 +1 @@ -/*! biscuitman.js 0.4.0 */let e,t,o;let{document:n,window:a,Object:i}=globalThis,s=n.documentElement,c="biscuitman",l={},r={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1},d=document.createElement("div"),u=()=>{s.style.setProperty("--bm-height",`${d.offsetHeight}px`)},m=e=>{s.classList.toggle("bm-show",e),u()},p=()=>{let{consentTime:e,...o}=h();for(let[n,a]of(e||(o=i.fromEntries(t.sections.slice(1).map(e=>[e,!1]))),i.entries(o)))s.classList.toggle(`bm-${n}`,a),s.classList.toggle(`bm-no-${n}`,!a)};function f(e){let t=e.target.dataset.id;switch(v("button",{id:t}),t){case"accept":C(!0);break;case"close":o.close();break;case"settings":g();break;case"save":C();break;case"reject":C(!1)}}function b(){v("close")}function $(e){t.force&&e.preventDefault()}function g(){v("open"),o.showModal()}function v(e,t){let o=`bm:${e}`,a={...void 0!==t&&t,time:+new Date};n.dispatchEvent(new CustomEvent(o,{detail:a})),console.debug(o,a),l[o]&&l[o].forEach(e=>e(a))}let h=()=>a[t.global]||{};function k(e){a[t.global]=e,p()}let E=e=>!!h()[e];function y(e,t){for(let o in e)e[o]&&!1===t[o]&&v("revoke",{section:o})}function T(){try{return JSON.parse(localStorage.getItem(t.key))}catch(e){return console.error(e),localStorage.removeItem(t.key),{}}}function S(){let e=i.fromEntries(i.entries(localStorage)),o=i.fromEntries(n.cookie.split("; ").map(e=>e.split("="))),{consentTime:a,...s}=T()||t.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[a,c]of i.entries(s)){if(c)continue;let s=i.keys(t[`${a}Cookies`]||{});for(let t of(s.filter(e=>e.endsWith("*")).map(t=>{i.keys({...o,...e}).map(e=>{e.startsWith(t.slice(0,-1))&&s.push(e)})}),s)){if(o[t]){let e=`${t}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;n.cookie=e,n.cookie=`${e}domain=${location.hostname};`,n.cookie=`${e}domain=.${location.hostname};`,v("delete",{cookie:t})}e[t]&&(localStorage.removeItem(t),v("delete",{localStorage:t}))}}}function C(e){let n=void 0===e,a={consentTime:+new Date};t.sections.forEach(t=>{if("essential"===t)return!1;let o=d.querySelector(`[data-s=${t}]`),i=n?o.checked:e;a[t]=i,n||(o.checked=e)}),y(h(),a),k(a),localStorage.setItem(t.key,JSON.stringify(a)),v("save",{data:a}),S(),j(),o.open&&o.close(),m(!1)}function j(){n.querySelectorAll("script[data-consent]").forEach(e=>{if(!h()[e.dataset.consent])return!1;let t=n.createElement("script");for(let{name:o,value:n}of e.attributes)o.startsWith("data-")||"type"===o||t.setAttribute(o,n);t.setAttribute("type",e.dataset.type||"text/javascript"),e.src||(t.textContent=e.textContent),e.parentNode.replaceChild(t,e),v("inject",{el:e,...e.id&&{id:e.id}}),e.src&&""!==e.textContent.trim()&&t.addEventListener("load",()=>{let o=n.createElement("script");o.textContent=e.textContent,e.id&&(o.id=e.id+"-after"),t.insertAdjacentElement("afterend",o),v("inject",{el:o,parent:e,...o.id&&{id:o.id}})})})}export default{create:function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e)return e;t={...r,...s};let p=a.bmInvalidate=()=>{v("invalidate",{data:h()}),y({}),C(!1),k({}),localStorage.removeItem(t.key),m(!0)},L=a.bmUpdate=()=>{v("update",{data:h()}),g()};return k(T()||{}),function(){let e=Intl.DateTimeFormat().resolvedOptions().timeZone,o=/^(GMT|UTC)$/.test(e)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(e);t.acceptNonEU&&!o&&(C(!0),m(!1))}(),function(){d.classList.add("biscuitman"),d.innerHTML=`
${t.title}

${t.message}

${t.settingsTitle}

${t.message}

${t.info.split("\n").map((e,o,n)=>`${e}${n.length>1&&t.enableMore&&0==o?`${t.more}`:""}`).join("")}

${t.sections.map(e=>{let o=h()[e],n="essential"===e,a=n?"disabled":"",s=n?"checked":"";void 0!==o&&(s=o?"checked":"");let l=t[`${e}Cookies`];return`
${t[`${e}Title`]}

${t[`${e}Message`]}

${l?i.entries(l).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${t.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${t.linkText}`),d.querySelectorAll("button").forEach(e=>e.addEventListener("click",f)),(o=d.querySelector("dialog")).addEventListener("close",b),o.addEventListener("cancel",$);let e=d.querySelector(".more");e&&e.addEventListener("click",e.remove),d.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),n.body.appendChild(d),a.addEventListener("resize",u),v("render",{dialog:o,ui:d})}(),S(),a[t.global].consentTime?(m(!1),j()):(m(!0),t.force&&g()),e={consent:E,invalidate:p,update:L,on:(t,o)=>{let n=`${c}:${t}`;return l[n]||(l[n]=[]),l[n].push(o),e},off:(e,t)=>{let o=`${c}:${e}`;l[o]&&(l[o]=l[o].filter(e=>e!==t))}}}}; \ No newline at end of file +/*! biscuitman.js 0.4.1 */let e,t,o;let{document:n,window:a,Object:i}=globalThis,s=n.documentElement,c={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1},l=document.createElement("div"),r={},d=()=>{s.style.setProperty("--bm-height",`${l.offsetHeight}px`)},m=e=>{s.classList.toggle("bm-show",e),d()},u=()=>{let{consentTime:t,...o}=v();for(let[n,a]of(t||(o=i.fromEntries(e.sections.slice(1).map(e=>[e,!1]))),i.entries(o)))s.classList.toggle(`bm-${n}`,a),s.classList.toggle(`bm-no-${n}`,!a)};function p(e){let o=e.target.dataset.id;switch(g("button",{id:o}),o){case"accept":S(!0);break;case"close":t.close();break;case"settings":$();break;case"save":S();break;case"reject":S(!1)}}function b(){g("close")}function f(t){e.force&&t.preventDefault()}function $(){g("open"),t.showModal()}function g(e,t){let o=`bm:${e}`,a={...void 0!==t&&t,time:+new Date};n.dispatchEvent(new CustomEvent(o,{detail:a})),console.debug(o,a),r[o]&&r[o].forEach(e=>e(a))}let v=()=>a[e.global]||{};function h(t){a[e.global]=t,u()}let k=e=>!!v()[e];function E(e,t){for(let o in e)e[o]&&!1===t[o]&&g("revoke",{section:o})}function y(){try{return JSON.parse(localStorage.getItem(e.key))}catch(t){return console.error(t),localStorage.removeItem(e.key),{}}}function T(){let t=i.fromEntries(i.entries(localStorage)),o=i.fromEntries(n.cookie.split("; ").map(e=>e.split("="))),{consentTime:a,...s}=y()||e.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[a,c]of i.entries(s)){if(c)continue;let s=i.keys(e[`${a}Cookies`]||{});for(let e of(s.filter(e=>e.endsWith("*")).map(e=>{i.keys({...o,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&s.push(t)})}),s)){if(o[e]){let t=`${e}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;n.cookie=t,n.cookie=`${t}domain=${location.hostname};`,n.cookie=`${t}domain=.${location.hostname};`,g("delete",{cookie:e})}t[e]&&(localStorage.removeItem(e),g("delete",{localStorage:e}))}}}function S(o){let n=void 0===o,a={consentTime:+new Date};e.sections.forEach(e=>{if("essential"===e)return!1;let t=l.querySelector(`[data-s=${e}]`),i=n?t.checked:o;a[e]=i,n||(t.checked=o)}),E(v(),a),h(a),localStorage.setItem(e.key,JSON.stringify(a)),g("save",{data:a}),T(),C(),t.open&&t.close(),m(!1)}function C(){n.querySelectorAll("script[data-consent]").forEach(e=>{if(!v()[e.dataset.consent])return!1;let t=n.createElement("script");for(let{name:o,value:n}of e.attributes)o.startsWith("data-")||"type"===o||t.setAttribute(o,n);t.setAttribute("type",e.dataset.type||"text/javascript"),e.src||(t.textContent=e.textContent),e.parentNode.replaceChild(t,e),g("inject",{el:e,...e.id&&{id:e.id}}),e.src&&""!==e.textContent.trim()&&t.addEventListener("load",()=>{let o=n.createElement("script");o.textContent=e.textContent,e.id&&(o.id=e.id+"-after"),t.insertAdjacentElement("afterend",o),g("inject",{el:o,parent:e,...o.id&&{id:o.id}})})})}export default{create:function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(o)return o;e={...c,...s};let u=a.bmInvalidate=()=>{g("invalidate",{data:v()}),E({}),S(!1),h({}),localStorage.removeItem(e.key),m(!0)},j=a.bmUpdate=()=>{g("update",{data:v()}),$()};return h(y()||{}),function(){let t=Intl.DateTimeFormat().resolvedOptions().timeZone,o=/^(GMT|UTC)$/.test(t)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(t);e.acceptNonEU&&!o&&(S(!0),m(!1))}(),function(){l.classList.add("biscuitman"),l.innerHTML=`
${e.title}

${e.message}

${e.settingsTitle}

${e.message}

${e.info.split("\n").map((t,o,n)=>`${t}${n.length>1&&e.enableMore&&0==o?`${e.more}`:""}`).join("")}

${e.sections.map(t=>{let o=v()[t],n="essential"===t,a=n?"disabled":"",s=n?"checked":"";void 0!==o&&(s=o?"checked":"");let c=e[`${t}Cookies`];return`
${e[`${t}Title`]}

${e[`${t}Message`]}

${c?i.entries(c).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${e.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${e.linkText}`),l.querySelectorAll("button").forEach(e=>e.addEventListener("click",p)),(t=l.querySelector("dialog")).addEventListener("close",b),t.addEventListener("cancel",f);let o=l.querySelector(".more");o&&o.addEventListener("click",o.remove),l.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),n.body.appendChild(l),a.addEventListener("resize",d),g("render",{dialog:t,ui:l})}(),T(),a[e.global].consentTime?(m(!1),C()):(m(!0),e.force&&$()),o={consent:k,invalidate:u,update:j,on:(e,t)=>{let n=`bm:${e}`;return r[n]||(r[n]=[]),r[n].push(t),o},off:(e,t)=>{let o=`bm:${e}`;r[o]&&(r[o]=r[o].filter(e=>e!==t))}}}}; \ No newline at end of file diff --git a/dist/esm/biscuitman.mjs b/dist/esm/biscuitman.mjs index 90af620..6d3c2f9 100644 --- a/dist/esm/biscuitman.mjs +++ b/dist/esm/biscuitman.mjs @@ -1,10 +1,6 @@ -/*! biscuitman.js 0.4.0 */ +/*! biscuitman.js 0.4.1 */ const { document: d, window: w, Object: O } = globalThis; const h = d.documentElement; -const bm = 'biscuitman'; -let instance; -let options; -let listeners = {}; const defaults = { key: 'myconsent', global: 'Consent', @@ -25,9 +21,11 @@ const defaults = { noCookies: 'No cookies to display', acceptNonEU: false }; +let options; // UI & Events: const ui = document.createElement('div'); let dialog; +let listeners = {}; function render() { ui.classList.add('biscuitman'); ui.innerHTML = ` @@ -61,8 +59,8 @@ function render() {
${options[`${section}Title`]} - @@ -106,7 +104,6 @@ const displayUI = (show)=>{ }; const applyCssClasses = ()=>{ let { consentTime, ...consents } = getConsents(); - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(options.sections.slice(1).map((sectionName)=>[ sectionName, false @@ -289,6 +286,7 @@ function handleNonEUConsent() { displayUI(false); } } +let instance; function create() { let config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; if (instance) return instance; @@ -338,13 +336,13 @@ function create() { invalidate, update, on: (event, callback)=>{ - const eventName = `${bm}:${event}`; + const eventName = `bm:${event}`; if (!listeners[eventName]) listeners[eventName] = []; listeners[eventName].push(callback); return instance; }, off: (event, callback)=>{ - const eventName = `${bm}:${event}`; + const eventName = `bm:${event}`; if (!listeners[eventName]) return; listeners[eventName] = listeners[eventName].filter((cb)=>cb !== callback); } diff --git a/dist/esm/biscuitman.withcss.min.mjs b/dist/esm/biscuitman.withcss.min.mjs index 00c1b4d..46f4085 100644 --- a/dist/esm/biscuitman.withcss.min.mjs +++ b/dist/esm/biscuitman.withcss.min.mjs @@ -1 +1 @@ -/*! biscuitman.js 0.4.0 */let e,t,o;let{document:n,window:a,Object:i}=globalThis,s=n.documentElement,c="biscuitman",l={},r={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1},d=document.createElement("div"),u=()=>{s.style.setProperty("--bm-height",`${d.offsetHeight}px`)},m=e=>{s.classList.toggle("bm-show",e),u()},p=()=>{let{consentTime:e,...o}=h();for(let[n,a]of(e||(o=i.fromEntries(t.sections.slice(1).map(e=>[e,!1]))),i.entries(o)))s.classList.toggle(`bm-${n}`,a),s.classList.toggle(`bm-no-${n}`,!a)};function f(e){let t=e.target.dataset.id;switch(v("button",{id:t}),t){case"accept":C(!0);break;case"close":o.close();break;case"settings":g();break;case"save":C();break;case"reject":C(!1)}}function b(){v("close")}function $(e){t.force&&e.preventDefault()}function g(){v("open"),o.showModal()}function v(e,t){let o=`bm:${e}`,a={...void 0!==t&&t,time:+new Date};n.dispatchEvent(new CustomEvent(o,{detail:a})),console.debug(o,a),l[o]&&l[o].forEach(e=>e(a))}let h=()=>a[t.global]||{};function k(e){a[t.global]=e,p()}let E=e=>!!h()[e];function y(e,t){for(let o in e)e[o]&&!1===t[o]&&v("revoke",{section:o})}function T(){try{return JSON.parse(localStorage.getItem(t.key))}catch(e){return console.error(e),localStorage.removeItem(t.key),{}}}function S(){let e=i.fromEntries(i.entries(localStorage)),o=i.fromEntries(n.cookie.split("; ").map(e=>e.split("="))),{consentTime:a,...s}=T()||t.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[a,c]of i.entries(s)){if(c)continue;let s=i.keys(t[`${a}Cookies`]||{});for(let t of(s.filter(e=>e.endsWith("*")).map(t=>{i.keys({...o,...e}).map(e=>{e.startsWith(t.slice(0,-1))&&s.push(e)})}),s)){if(o[t]){let e=`${t}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;n.cookie=e,n.cookie=`${e}domain=${location.hostname};`,n.cookie=`${e}domain=.${location.hostname};`,v("delete",{cookie:t})}e[t]&&(localStorage.removeItem(t),v("delete",{localStorage:t}))}}}function C(e){let n=void 0===e,a={consentTime:+new Date};t.sections.forEach(t=>{if("essential"===t)return!1;let o=d.querySelector(`[data-s=${t}]`),i=n?o.checked:e;a[t]=i,n||(o.checked=e)}),y(h(),a),k(a),localStorage.setItem(t.key,JSON.stringify(a)),v("save",{data:a}),S(),j(),o.open&&o.close(),m(!1)}function j(){n.querySelectorAll("script[data-consent]").forEach(e=>{if(!h()[e.dataset.consent])return!1;let t=n.createElement("script");for(let{name:o,value:n}of e.attributes)o.startsWith("data-")||"type"===o||t.setAttribute(o,n);t.setAttribute("type",e.dataset.type||"text/javascript"),e.src||(t.textContent=e.textContent),e.parentNode.replaceChild(t,e),v("inject",{el:e,...e.id&&{id:e.id}}),e.src&&""!==e.textContent.trim()&&t.addEventListener("load",()=>{let o=n.createElement("script");o.textContent=e.textContent,e.id&&(o.id=e.id+"-after"),t.insertAdjacentElement("afterend",o),v("inject",{el:o,parent:e,...o.id&&{id:o.id}})})})}export default{create:function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(e)return e;t={...r,...s};let p=a.bmInvalidate=()=>{v("invalidate",{data:h()}),y({}),C(!1),k({}),localStorage.removeItem(t.key),m(!0)},L=a.bmUpdate=()=>{v("update",{data:h()}),g()};return k(T()||{}),function(){let e=Intl.DateTimeFormat().resolvedOptions().timeZone,o=/^(GMT|UTC)$/.test(e)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(e);t.acceptNonEU&&!o&&(C(!0),m(!1))}(),function(){d.classList.add("biscuitman"),d.innerHTML=`
${t.title}

${t.message}

${t.settingsTitle}

${t.message}

${t.info.split("\n").map((e,o,n)=>`${e}${n.length>1&&t.enableMore&&0==o?`${t.more}`:""}`).join("")}

${t.sections.map(e=>{let o=h()[e],n="essential"===e,a=n?"disabled":"",s=n?"checked":"";void 0!==o&&(s=o?"checked":"");let l=t[`${e}Cookies`];return`
${t[`${e}Title`]}

${t[`${e}Message`]}

${l?i.entries(l).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${t.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${t.linkText}`),d.querySelectorAll("button").forEach(e=>e.addEventListener("click",f)),(o=d.querySelector("dialog")).addEventListener("close",b),o.addEventListener("cancel",$);let e=d.querySelector(".more");e&&e.addEventListener("click",e.remove),d.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),n.body.appendChild(d),a.addEventListener("resize",u),v("render",{dialog:o,ui:d})}(),S(),a[t.global].consentTime?(m(!1),j()):(m(!0),t.force&&g()),e={consent:E,invalidate:p,update:L,on:(t,o)=>{let n=`${c}:${t}`;return l[n]||(l[n]=[]),l[n].push(o),e},off:(e,t)=>{let o=`${c}:${e}`;l[o]&&(l[o]=l[o].filter(e=>e!==t))}}}};;if(typeof BMCSS==='undefined'){let c=document.createElement('style');c.id='BMCSS';c.textContent=`/*! biscuitman.js 0.4.0 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)}`;document.head.appendChild(c)} \ No newline at end of file +/*! biscuitman.js 0.4.1 */let e,t,o;let{document:n,window:a,Object:i}=globalThis,s=n.documentElement,c={key:"myconsent",global:"Consent",force:!1,enableMore:!0,sections:["essential"],title:"Your privacy matters",message:"We use cookies",settings:"Settings",reject:"Reject All",accept:"Accept All",save:"Save My Settings",settingsTitle:"My Consent Settings",info:"",more:"Show more",noCookies:"No cookies to display",acceptNonEU:!1},l=document.createElement("div"),r={},d=()=>{s.style.setProperty("--bm-height",`${l.offsetHeight}px`)},m=e=>{s.classList.toggle("bm-show",e),d()},u=()=>{let{consentTime:t,...o}=v();for(let[n,a]of(t||(o=i.fromEntries(e.sections.slice(1).map(e=>[e,!1]))),i.entries(o)))s.classList.toggle(`bm-${n}`,a),s.classList.toggle(`bm-no-${n}`,!a)};function p(e){let o=e.target.dataset.id;switch(g("button",{id:o}),o){case"accept":S(!0);break;case"close":t.close();break;case"settings":$();break;case"save":S();break;case"reject":S(!1)}}function b(){g("close")}function f(t){e.force&&t.preventDefault()}function $(){g("open"),t.showModal()}function g(e,t){let o=`bm:${e}`,a={...void 0!==t&&t,time:+new Date};n.dispatchEvent(new CustomEvent(o,{detail:a})),console.debug(o,a),r[o]&&r[o].forEach(e=>e(a))}let v=()=>a[e.global]||{};function h(t){a[e.global]=t,u()}let k=e=>!!v()[e];function E(e,t){for(let o in e)e[o]&&!1===t[o]&&g("revoke",{section:o})}function y(){try{return JSON.parse(localStorage.getItem(e.key))}catch(t){return console.error(t),localStorage.removeItem(e.key),{}}}function T(){let t=i.fromEntries(i.entries(localStorage)),o=i.fromEntries(n.cookie.split("; ").map(e=>e.split("="))),{consentTime:a,...s}=y()||e.sections.slice(1).reduce((e,t)=>(e[t]=!1,{consentTime:void 0,...e}),{});for(let[a,c]of i.entries(s)){if(c)continue;let s=i.keys(e[`${a}Cookies`]||{});for(let e of(s.filter(e=>e.endsWith("*")).map(e=>{i.keys({...o,...t}).map(t=>{t.startsWith(e.slice(0,-1))&&s.push(t)})}),s)){if(o[e]){let t=`${e}=;expires=Thu, 01 Jan 1970 00:00:01 UTC;path=/;`;n.cookie=t,n.cookie=`${t}domain=${location.hostname};`,n.cookie=`${t}domain=.${location.hostname};`,g("delete",{cookie:e})}t[e]&&(localStorage.removeItem(e),g("delete",{localStorage:e}))}}}function S(o){let n=void 0===o,a={consentTime:+new Date};e.sections.forEach(e=>{if("essential"===e)return!1;let t=l.querySelector(`[data-s=${e}]`),i=n?t.checked:o;a[e]=i,n||(t.checked=o)}),E(v(),a),h(a),localStorage.setItem(e.key,JSON.stringify(a)),g("save",{data:a}),T(),C(),t.open&&t.close(),m(!1)}function C(){n.querySelectorAll("script[data-consent]").forEach(e=>{if(!v()[e.dataset.consent])return!1;let t=n.createElement("script");for(let{name:o,value:n}of e.attributes)o.startsWith("data-")||"type"===o||t.setAttribute(o,n);t.setAttribute("type",e.dataset.type||"text/javascript"),e.src||(t.textContent=e.textContent),e.parentNode.replaceChild(t,e),g("inject",{el:e,...e.id&&{id:e.id}}),e.src&&""!==e.textContent.trim()&&t.addEventListener("load",()=>{let o=n.createElement("script");o.textContent=e.textContent,e.id&&(o.id=e.id+"-after"),t.insertAdjacentElement("afterend",o),g("inject",{el:o,parent:e,...o.id&&{id:o.id}})})})}export default{create:function(){let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(o)return o;e={...c,...s};let u=a.bmInvalidate=()=>{g("invalidate",{data:v()}),E({}),S(!1),h({}),localStorage.removeItem(e.key),m(!0)},j=a.bmUpdate=()=>{g("update",{data:v()}),$()};return h(y()||{}),function(){let t=Intl.DateTimeFormat().resolvedOptions().timeZone,o=/^(GMT|UTC)$/.test(t)||/(Europe|BST|CEST|CET|EET|IST|WEST|WET|GMT-1|GMT-2|UTC+1|UTC+2|UTC+3)/.test(t);e.acceptNonEU&&!o&&(S(!0),m(!1))}(),function(){l.classList.add("biscuitman"),l.innerHTML=`
${e.title}

${e.message}

${e.settingsTitle}

${e.message}

${e.info.split("\n").map((t,o,n)=>`${t}${n.length>1&&e.enableMore&&0==o?`${e.more}`:""}`).join("")}

${e.sections.map(t=>{let o=v()[t],n="essential"===t,a=n?"disabled":"",s=n?"checked":"";void 0!==o&&(s=o?"checked":"");let c=e[`${t}Cookies`];return`
${e[`${t}Title`]}

${e[`${t}Message`]}

${c?i.entries(c).map(e=>{let[t,o]=e;return`
${t}
${o}
`}).join(""):`
${e.noCookies}
`}
`}).join("")}
`.replaceAll("{link}",`${e.linkText}`),l.querySelectorAll("button").forEach(e=>e.addEventListener("click",p)),(t=l.querySelector("dialog")).addEventListener("close",b),t.addEventListener("cancel",f);let o=l.querySelector(".more");o&&o.addEventListener("click",o.remove),l.querySelectorAll("[data-s]").forEach(e=>e.addEventListener("change",t=>{e.parentElement.classList.toggle("checked",t.target.checked)})),n.body.appendChild(l),a.addEventListener("resize",d),g("render",{dialog:t,ui:l})}(),T(),a[e.global].consentTime?(m(!1),C()):(m(!0),e.force&&$()),o={consent:k,invalidate:u,update:j,on:(e,t)=>{let n=`bm:${e}`;return r[n]||(r[n]=[]),r[n].push(t),o},off:(e,t)=>{let o=`bm:${e}`;r[o]&&(r[o]=r[o].filter(e=>e!==t))}}}};;if(typeof BMCSS==='undefined'){let c=document.createElement('style');c.id='BMCSS';c.textContent=`/*! biscuitman.js 0.4.1 */.biscuitman{--ui:0,0,0;--tx:#444;--bg:#fff;--c:#105d89;background:var(--bg);box-sizing:border-box;z-index:3;width:100%;padding:20px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;display:none;position:fixed;bottom:0;box-shadow:0 -2px 10px #00000029}.bm-show .biscuitman{display:block}.biscuitman *{box-sizing:border-box;color:var(--tx);margin:0;padding:0;font-family:inherit;font-size:16px;line-height:1.4em}.biscuitman:has([open]){transform:translateY(100%)}.biscuitman article{padding:0;position:relative}@media (min-width:770px){.biscuitman article{padding-right:calc(max(300px,30vw) + 20px)}.biscuitman article nav{width:30vw;min-width:300px;position:absolute;bottom:50%;right:0;transform:translateY(50%)}}.biscuitman article p{color:var(--tx);margin:10px 0;font-size:13px}@media (min-width:575px){.biscuitman article p{font-size:14px}}.biscuitman button{background:var(--bg);border:2px solid var(--c);color:var(--c);cursor:pointer;border-radius:3px;margin-top:10px;padding:.8em;font-size:13px;line-height:1em}.biscuitman button[data-id=accept]{background:var(--c);color:var(--bg)!important}.biscuitman button[data-id=close]{color:rgba(var(--ui),.5);opacity:.6;-webkit-user-select:none;user-select:none;z-index:2;background:0 0;border:none;outline:none;padding:10px;font-size:24px;line-height:1em;position:absolute;top:0;right:10px}.biscuitman button[disabled]{display:none}.biscuitman button:hover{opacity:.8}@media (min-width:576px){.biscuitman nav{flex-direction:row-reverse;gap:10px;width:100%;display:flex}.biscuitman nav button{flex-grow:1;margin-bottom:0}}@media (max-width:575px){.biscuitman nav{flex-direction:column;flex-grow:1;display:flex}}.biscuitman dialog{background:var(--bg);border:0;width:100%;max-width:100%;height:100%;max-height:100%}@media (min-width:576px){.biscuitman dialog{border-radius:10px;width:90vw;max-width:860px;max-height:80vh;margin:auto;box-shadow:0 0 8px #0000004d}}@media (min-width:576px) and (min-height:1134px){.biscuitman dialog{max-height:950px}}.biscuitman dialog nav{justify-self:flex-end;position:relative}.biscuitman .bm-dialog{flex-direction:column;height:100%;padding:20px;display:flex}.biscuitman .bm-dialog b{padding-bottom:8px;position:relative}.biscuitman .bm-dialog>b:after{content:"";background:linear-gradient(180deg,var(--bg)20%,#fff0);pointer-events:none;z-index:1;width:100%;height:25px;margin-bottom:-24px;position:absolute;bottom:0;left:0}.biscuitman .bm-dialog nav:after{content:"";background:linear-gradient(0deg,var(--bg)20%,#fff0);pointer-events:none;width:100%;height:25px;position:absolute;top:-24px;left:0}.biscuitman .bm-sections{scrollbar-color:rgba(var(--ui),.2)var(--bg);flex-shrink:1;height:100%;padding:15px 0;position:relative;overflow-y:scroll}@media (min-width:576px){.biscuitman .bm-sections{margin-right:-18px;padding-right:4px}}.biscuitman .bm-sections>p{padding-right:30px;font-size:13px;line-height:18px}@media (min-width:576px){.biscuitman .bm-sections>p{font-size:14px}}.biscuitman .bm-sections>p span{font-size:inherit;padding-bottom:5px;display:inline-block}.biscuitman .bm-sections>p .more~span{display:none}.biscuitman a{font-size:inherit;color:var(--c);cursor:pointer;text-decoration:none;display:inline-block}.biscuitman a:hover{text-decoration:underline}.biscuitman section{margin-bottom:10px;position:relative}.biscuitman section:first-of-type{margin-top:10px}.biscuitman details{border:1px solid rgba(var(--ui),.2);border-radius:5px;padding:10px;list-style:none;box-shadow:0 2px 4px #0000001a}.biscuitman details[open] summary b:after{margin:-3px 0 0 -2px;transform:rotate(45deg)scale(.3)}.biscuitman summary{cursor:pointer;flex-direction:column;width:100%;padding:5px 80px 10px 10px;list-style:none;display:flex;position:relative}.biscuitman summary b{margin-bottom:3px}.biscuitman summary b:after{content:"";border:5px solid rgba(var(--ui),.4);border-top-color:#0000;border-left-color:#0000;border-radius:2px;width:1em;height:1em;margin:-2px 0 0 -4px;display:block;transform:rotate(-45deg)scale(.3)}.biscuitman summary p{color:var(--tx);font-size:14px}.biscuitman summary>*{display:inline-flex}.biscuitman summary::marker{display:none}.biscuitman summary::-webkit-details-marker{display:none}.biscuitman dl{background:rgba(var(--ui),.08);margin:10px;padding:10px;display:flex}.biscuitman dl dt,.biscuitman dl dd{color:var(--tx);font-size:12px}.biscuitman dl dt{min-width:120px;padding-right:30px;font-weight:700}.biscuitman label{--height:1.2em;--width:2.3em;--gap:2px;height:var(--height);width:var(--width);background-color:rgba(var(--ui),.3);border-radius:var(--height);margin-top:-2px;display:block;position:absolute;top:50%;right:20px;transform:translateY(-50%);font-size:20px!important}.biscuitman label:before{content:"";background:var(--bg);height:calc(var(--height) - calc(var(--gap)*2));width:calc(var(--height) - calc(var(--gap)*2));height:var(--height);width:var(--height);left:var(--gap);transform-origin:50%;border-radius:100%;display:block;position:absolute;top:50%;left:0;transform:translateY(-50%)scale(.8)}.biscuitman label.checked{background-color:var(--c)}.biscuitman label.checked:before{left:auto;right:0}.biscuitman label:has(:focus-visible){outline:auto highlight}.biscuitman label.disabled.checked{opacity:.5}.biscuitman label input{opacity:0}.bm-dialog-polyfill .biscuitman dialog{position:fixed;top:50%;transform:translateY(-50%)}`;document.head.appendChild(c)} \ No newline at end of file diff --git a/dist/esm/biscuitman.withcss.mjs b/dist/esm/biscuitman.withcss.mjs index 01d0a80..375784d 100644 --- a/dist/esm/biscuitman.withcss.mjs +++ b/dist/esm/biscuitman.withcss.mjs @@ -1,10 +1,6 @@ -/*! biscuitman.js 0.4.0 */ +/*! biscuitman.js 0.4.1 */ const { document: d, window: w, Object: O } = globalThis; const h = d.documentElement; -const bm = 'biscuitman'; -let instance; -let options; -let listeners = {}; const defaults = { key: 'myconsent', global: 'Consent', @@ -25,9 +21,11 @@ const defaults = { noCookies: 'No cookies to display', acceptNonEU: false }; +let options; // UI & Events: const ui = document.createElement('div'); let dialog; +let listeners = {}; function render() { ui.classList.add('biscuitman'); ui.innerHTML = ` @@ -61,8 +59,8 @@ function render() {
${options[`${section}Title`]} - @@ -106,7 +104,6 @@ const displayUI = (show)=>{ }; const applyCssClasses = ()=>{ let { consentTime, ...consents } = getConsents(); - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(options.sections.slice(1).map((sectionName)=>[ sectionName, false @@ -289,6 +286,7 @@ function handleNonEUConsent() { displayUI(false); } } +let instance; function create() { let config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; if (instance) return instance; @@ -338,13 +336,13 @@ function create() { invalidate, update, on: (event, callback)=>{ - const eventName = `${bm}:${event}`; + const eventName = `bm:${event}`; if (!listeners[eventName]) listeners[eventName] = []; listeners[eventName].push(callback); return instance; }, off: (event, callback)=>{ - const eventName = `${bm}:${event}`; + const eventName = `bm:${event}`; if (!listeners[eventName]) return; listeners[eventName] = listeners[eventName].filter((cb)=>cb !== callback); } @@ -358,7 +356,7 @@ export default { if (typeof BMCSS === 'undefined') { let css=document.createElement('style'); css.id = 'BMCSS'; - css.textContent=`/*! biscuitman.js 0.4.0 */ + css.textContent=`/*! biscuitman.js 0.4.1 */ .biscuitman { --ui: 0, 0, 0; --tx: #444; diff --git a/package.json b/package.json index 6f546f1..4fa0631 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "biscuitman", - "version": "0.4.0", + "version": "0.4.1", "description": "Super lightweight open-source privacy consent manager for your website ", "browser": "biscuitman.js", "keywords": [ diff --git a/src/biscuitman.js b/src/biscuitman.js index b5aaad0..213495b 100644 --- a/src/biscuitman.js +++ b/src/biscuitman.js @@ -1,4 +1,4 @@ -((d, w, O, h, bm)=>{ +((d, w, O, h)=>{ const defaults = { key: 'myconsent', global: 'Consent', @@ -49,7 +49,7 @@ let dialog function render() { - ui.classList.add(bm) + ui.classList.add('biscuitman') ui.innerHTML = `
${o.title} @@ -84,8 +84,8 @@
${o[`${section}Title`]} - @@ -123,7 +123,6 @@ const applyCssClasses = () => { let { consentTime, ...consents } = getConsents() - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(o.sections.slice(1).map(sectionName => [sectionName, false])) for (let [name, granted] of O.entries(consents)) { @@ -324,4 +323,4 @@ openModal() } -})(document, window, Object, document.documentElement, 'biscuitman') +})(document, window, Object, document.documentElement) diff --git a/src/biscuitman.mjs b/src/biscuitman.mjs index 6ef2b36..34e6ec1 100644 --- a/src/biscuitman.mjs +++ b/src/biscuitman.mjs @@ -1,10 +1,5 @@ const { document: d, window: w, Object: O } = globalThis const h = d.documentElement -const bm = 'biscuitman' - -let instance -let options -let listeners = {} const defaults = { key: 'myconsent', @@ -47,11 +42,13 @@ const defaults = { // uncategorizedTitle: 'Uncategorized', // uncategorizedMessage: 'Uncategorized cookies are those currently under analysis and have not yet been assigned to a specific category', } +let options // UI & Events: const ui = document.createElement('div') let dialog +let listeners = {} function render() { ui.classList.add('biscuitman') @@ -89,8 +86,8 @@ function render() {
${options[`${section}Title`]} - @@ -129,7 +126,6 @@ const displayUI = (show) => { const applyCssClasses = () => { let { consentTime, ...consents } = getConsents() - // if (!consentTime) h.className = h.className.replace(/\bbm-[^\s]+(\s+|$)/g, '').trim(); if (!consentTime) consents = O.fromEntries(options.sections.slice(1).map(sectionName => [sectionName, false])) for (let [name, granted] of O.entries(consents)) { @@ -298,6 +294,7 @@ function handleNonEUConsent() { } } +let instance function create(config = {}) { if (instance) return instance @@ -351,13 +348,13 @@ function create(config = {}) { invalidate, update, on: (event, callback) => { - const eventName = `${bm}:${event}` + const eventName = `bm:${event}` if (!listeners[eventName]) listeners[eventName] = [] listeners[eventName].push(callback) return instance }, off: (event, callback) => { - const eventName = `${bm}:${event}` + const eventName = `bm:${event}` if (!listeners[eventName]) return listeners[eventName] = listeners[eventName].filter(cb => cb !== callback) }