@masth0/cookie-consent
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1164,5 +1164,4 @@ var __accessCheck = (obj, member, msg) => { | ||
copy.src = copy.dataset.src; | ||
} else { | ||
copy.type = copy.dataset.type || "text/javascript"; | ||
} | ||
copy.type = copy.dataset.type || "text/javascript"; | ||
newScriptTags.push(copy); | ||
@@ -1169,0 +1168,0 @@ script.insertAdjacentElement("beforebegin", copy); |
@@ -10,2 +10,2 @@ var le=(h,b,y)=>{if(!b.has(h))throw TypeError("Cannot "+y)};var W=(h,b,y)=>(le(h,b,"read from private field"),y?y.call(h):b.get(h)),ue=(h,b,y)=>{if(b.has(h))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(h):b.set(h,y)},de=(h,b,y,x)=>(le(h,b,"write to private field"),x?x.call(h,y):b.set(h,y),y);(function(h,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(h=typeof globalThis!="undefined"?globalThis:h||self,b(h.CookieConsent={}))})(this,function(h){var F;"use strict";/*! | ||
<p class="cc_description">${this.translations.description[this.locale]}</p> | ||
`;const s=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Save]:"",hidden:"","aria-hidden":"true"});s.innerText=this.translations.btn.save[this.locale];const l=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Params]:""});l.innerText=this.translations.btn.params[this.locale];const d=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Reject]:""});d.innerText=this.translations.btn.reject[this.locale];const f=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.SaveAll]:""});f.innerText=this.translations.btn.saveAll[this.locale],e.appendChild(t),this.container.appendChild(e),this.container.appendChild(n),this.container.appendChild(a),this.container.appendChild(i),i.appendChild(l),i.appendChild(d),i.appendChild(s),i.appendChild(f),this.categories.forEach(k=>{a.appendChild(this.categoryHtml(k))}),document.body.appendChild(this.container)}addParamsEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Params+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{var l;n.preventDefault();const a=this.container.querySelector("button["+C.Save+"]"),i=this.container.querySelector("button["+C.SaveAll+"]"),s=this.container.querySelector(".cc_body");if(s&&s.hasAttribute("hidden")){t.innerText=this.translations.btn.closeParams[this.locale],S.showElement(s),(l=s.querySelector("button"))==null||l.focus(),a!==null&&S.showElement(a),i!==null&&S.hideElement(i);const d=t.querySelector("button");d==null||d.focus()}else t.innerText=this.translations.btn.params[this.locale],s!==null&&S.hideElement(s),a!==null&&S.hideElement(a),i!==null&&S.showElement(i)})})}addSaveAllEvent(){const e=[].slice.call(document.querySelectorAll("["+C.SaveAll+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{n.preventDefault();const a=this.createEvent(E.AcceptAll,{});this.container.dispatchEvent(a)})})}addSaveEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Save+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{n.preventDefault();const a=this.createEvent(E.Save,{});this.container.dispatchEvent(a)})})}addRejectEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Reject+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",()=>{const n=this.createEvent(E.Reject,{});this.container.dispatchEvent(n)})})}categoryHtml(e){const t=this.createHTMLElement("div",{class:"cc_category"}),n=this.createHTMLElement("div",{class:"cc_category_inner",hidden:"","aria-hidden":"true"}),a=this.createHTMLElement("button",{type:"button",class:"cc_category_title","data-cc-category-trigger":"button"});if(a.innerText=e.name,t.appendChild(a),e.description){const s=this.createHTMLElement("div",{class:"cc_description"});s.innerHTML=e.description,n.appendChild(s)}const i=this.createHTMLElement("ul",{});return e.cookies.forEach(s=>{const l=this.createHTMLElement("li",{});l.appendChild(this.cookieDefinitionHtml(s)),i.appendChild(l)}),n.appendChild(i),t.appendChild(n),a.addEventListener("click",function(s){var d;s.preventDefault();const l=a.nextElementSibling;if(l&&l.hasAttribute("hidden"))this.classList.add("is-open"),S.showElement(l),(d=l.querySelector("input"))==null||d.focus(),l.addEventListener("animationend",function f(k){if(k.animationName==="fadeIn"){const m=Array.from(l.querySelectorAll("input.cc_switch"));for(const w of m)w.classList.remove("cc-disable-anim");l.removeEventListener("animationend",f)}},!1);else{this.classList.remove("is-open");const f=Array.from(l.querySelectorAll("input.cc_switch"));for(const k of f)k.classList.add("cc-disable-anim");l&&S.hideElement(l)}}),t}cookieDefinitionHtml(e){const t=document.createElement("div");t.classList.add("cc_cookie");const n=document.createElement("div");n.classList.add("cc_switch_container");const a=document.createElement("p");a.classList.add("cc_description"),a.innerHTML=e.description;const i=document.createElement("label");i.innerHTML=e.name,i.setAttribute("for",e.id);const s=document.createElement("input");return s.type="checkbox",s.dataset.category=e.categoryName,s.name=e.name,s.value=e.name,s.id=e.id,s.classList.add("cc_switch"),s.ariaLabel=e.name,s.disabled=!e.isRevocable,s.readOnly=!e.isRevocable,s.classList.add("cc-disable-anim"),(e.isAccepted||!e.isRevocable)&&s.setAttribute("checked","checked"),n.appendChild(s),n.appendChild(i),s.addEventListener("change",l=>{l.preventDefault();const d=new CustomEvent(E.Change,{detail:{checkbox:s,cookie:e}});this.container.dispatchEvent(d)}),t.appendChild(n),t.appendChild(a),t}createHTMLElement(e,t){const n=document.createElement(e);for(const a in t)n.setAttribute(a,t[a]);return n}static hideElement(e){e.setAttribute("hidden",""),e.classList.remove("is-open"),e.setAttribute("aria-hidden","true")}static showElement(e){e.removeAttribute("hidden"),e.classList.add("is-open"),e.setAttribute("aria-hidden","false")}createEvent(e,t){return new CustomEvent(e,{detail:{...t}})}}var E=(r=>(r.Save="on:save",r.AcceptAll="on:acceptAll",r.Reject="on:reject",r.Change="on:change",r))(E||{}),C=(r=>(r.Save="data-cc-save",r.SaveAll="data-cc-save-all",r.Reject="data-cc-reject",r.Params="data-cc-params",r))(C||{});class _{constructor(e){this.config=e,this._enabled=!1,this._accepted=!1,this.config=e}get id(){return`${this.categoryName}_${this.name}`}get isEnabled(){return this._enabled}set enabled(e){this._enabled=e}get isAccepted(){return this.isRevocable?this._accepted:!0}set accepted(e){this._accepted=e}get name(){return this.config.name}get description(){return this.config.description}get isRevocable(){return this.config.revocable}get categoryName(){return this.config.categoryName||"undefined"}set categoryName(e){this.config.categoryName=e}enable(){return new Promise((e,t)=>{this.isAccepted||t("Cookie is not accepted");let n=[];this.config.scripts.forEach(a=>{var s;if(a.type!=="cookie-consent")return;const i=_.copyScriptTag(a);i.dataset.src?i.src=i.dataset.src:i.type=i.dataset.type||"text/javascript",n.push(i),a.insertAdjacentElement("beforebegin",i),(s=a.parentElement)==null||s.removeChild(a)}),this.config.scripts=n,this._enabled=!0,e()})}disable(){return new Promise(e=>{if(this.isRevocable&&this.isEnabled){const t=Oe();for(const n of this.config.tokens){const a=t.find(i=>{if(n.endsWith("*")){const l=new RegExp(n+"[^;]+").exec(i.name.slice(0,-1));return l&&l[0]?i:void 0}return i.name===n});if(a){const i=new Date("1970");let s=location.hostname.replace("www","");document.cookie=`${a.name}=; expires=${i.toUTCString()}; Domain=${s}; Max-Age=0; path=/;`}}this._enabled=!1,this._accepted=!1}e()})}addScripts(e){this.config.scripts=[...this.config.scripts,...e]}addTokens(e){this.config.tokens=[...this.config.tokens,...e]}static copyScriptTag(e){const t=document.createElement("script");for(let n=0;n<e.attributes.length;n++){const a=e.attributes[n];t.setAttribute(a.name,a.value),t.innerHTML=e.innerHTML}return t}}class B{constructor(e){this.config=e}get description(){return this.config.description}get name(){return this.config.name}get cookies(){return this.config.cookies}addCookie(e){var n;const t=new _(e);return t.categoryName=(n=e.categoryName)!=null?n:this.config.name,this.config.cookies.push(t),this}getCookie(e){return this.cookies.find(t=>t.name===e)}}function xe(r){var n;let t=("; "+document.cookie).split("; "+r+"=");return t.length<2||(n=t.pop())==null?void 0:n.split(";").shift()}function Oe(){return document.cookie.split(";").map(r=>{const[e,t]=r.split("=").map(n=>n.trim());return{name:e,value:t}})}function Pe(r){let e=[];const t=[].slice.call(document.querySelectorAll(r));for(let n=0;n<t.length;n++){const a=t[n],i=a.dataset.name,s=a.dataset.description||"",l=a.hasAttribute("data-accepted"),d=!(a.hasAttribute("data-revocable")&&a.dataset.revocable==="false"),f=a.dataset.category||"undefined",k=a.dataset.tokens;let m=[];if(k&&(m=k.split(","),m=m.map(A=>A.trim())),i===void 0){console.error(`Name is missing on: ${a.outerHTML}`);continue}let w=e.find(A=>A.name===f);w===void 0&&(w=new B({name:f,description:"",cookies:[]}),e.push(w));let N=w.cookies.find(A=>A.name===i);N===void 0?w.addCookie({categoryName:f,name:i.trim(),description:s.trim(),scripts:[a],tokens:m,accepted:l,revocable:d}):(N.addScripts([a]),N.addTokens(m))}return e}function Ie(r,e){const t=r.slice();for(let n=0;n<e.length;n++){const a=e[n],i=r.find(s=>s.name===a.name);if(i===void 0){t.push(a);continue}for(let s=0;s<a.cookies.length;s++){const l=a.cookies[s];i.cookies.find(f=>f.name===l.name)===void 0&&(i==null||i.cookies.push(l))}}return t}const Me={title:{fr:"Nous utilisons des cookies",en:"We use cookies",de:"Wir verwenden Cookies"},description:{fr:"Nous utilisons des cookies pour nous assurer du bon fonctionnement de notre site, pour personnaliser notre contenu et nos publicit\xE9s et afin d\u2019analyser notre trafic. En utilisant ce site Internet ou en fermant ce bandeau, vous consentez \xE0 l'utilisation de ces cookies.",en:"We use cookies to ensure that our site functions properly, to personalize our content and advertising, and to analyze our traffic. By using this website or closing this banner, you consent to the use of these cookies.",de:"Wir verwenden Cookies, um sicherzustellen, dass unsere Website ordnungsgem\xE4\xDF funktioniert, um unseren Inhalt und unsere Werbung zu personalisieren und um unseren Datenverkehr zu analysieren. Durch die Nutzung dieser Website oder das Schlie\xDFen dieses Banners stimmen Sie der Verwendung dieser Cookies zu."},btn:{params:{fr:"G\xE9rer les pr\xE9f\xE9rences",en:"Manage my preferences",de:"Pr\xE4ferenzen verwalten"},closeParams:{fr:"Fermer les pr\xE9f\xE9rences",en:"Close preferences",de:"Pr\xE4ferenzen schliessen"},reject:{fr:"Refuser",en:"Deny",de:"Ablehnen"},saveAll:{fr:"Accepter",en:"Accept",de:"Alle akzeptieren"},save:{fr:"Enregistrer la s\xE9lection",en:"Save selection",de:"Auswahl speichern"},continue:{fr:"Continuer sans accepter",en:"Continue without accepting",de:"Ohne Zustimmung fortfahren"}},categories:{mandatory:{title:{fr:"Obligatoire",en:"Mandatory",de:"Erforderlich"},description:{fr:"Cookies requis pour le bon fonctionnement du site.",en:"We use required cookies to perform essential website functions.",de:""}}}};class je{constructor(e){ue(this,F,void 0);this.config=e,de(this,F,"_cookie_consent"),this.needToReload=!1,this.UI=new S(this.config.categories,this.config.translations),this.UI.init()}async init(){const e=this.getUserConsent();return!e||e&&e.version!==this.config.version?this.UI.show():this.updateConsentFromStorage(e),await this.enableAccepted(),this.UI.container.addEventListener(E.Change,t=>{const n=t.detail.cookie,a=this.getCategoryByName(n.categoryName);if(a){const i=a.getCookie(n.name);i&&(this.needToReload||(this.needToReload=!t.detail.checkbox.checked&&i.isEnabled),i.accepted=t.detail.checkbox.checked)}}),this.UI.container.addEventListener(E.Save,async()=>{await this.save(E.Save),this.UI.hide()}),this.UI.container.addEventListener(E.AcceptAll,async()=>{await this.save(E.AcceptAll),this.UI.hide()}),this.UI.container.addEventListener(E.Reject,async()=>{await this.save(E.Reject),this.UI.hide()}),Promise.resolve(this)}show(){this.UI.show()}hide(){this.UI.hide()}async save(e){switch(e){case E.Save:await this.enableAccepted();break;case E.AcceptAll:await this.acceptAll(!0).then(()=>{this.UI.update(this.config.categories)});break;case E.Reject:await this.acceptAll(!1).then(()=>{this.UI.update(this.config.categories)});break}this.saveUserConsent(),this.config.forceReload&&this.needToReload&&(window.location.reload(),this.needToReload=!1)}updateConsentFromStorage(e){e.cookies.forEach(t=>{const n=this.getCategoryByName(t.category);if(n){const a=n.getCookie(t.name);a&&(a.accepted=t.accepted)}}),this.UI.update(this.config.categories)}saveUserConsent(){const e=new Date;e.setMonth(e.getMonth()+12),document.cookie=`${W(this,F)}=${this.serializeUserConsent()}; expires=${e.toUTCString()}; path=/; SameSite=Lax;`}serializeUserConsent(){let e={version:this.config.version,cookies:[]};return this.config.categories.forEach(t=>{t.cookies.forEach(n=>{e.cookies.push({category:t.name,name:n.name,accepted:n.isAccepted})})}),JSON.stringify(e)}getUserConsent(){const e=xe(W(this,F));return e?JSON.parse(e):void 0}getCategoryByName(e){return this.config.categories.find(t=>t.name===e)}acceptAll(e){let t=[];for(let n=0;n<this.config.categories.length;n++)for(let a=0;a<this.config.categories[n].cookies.length;a++){const i=this.config.categories[n].cookies[a];i.isRevocable&&(i.isAccepted&&!e&&(this.needToReload=!0),i.accepted=e,e?t.push(i.enable()):t.push(i.disable()))}return Promise.all(t)}enableAccepted(){let e=[];for(let t=0;t<this.config.categories.length;t++)for(let n=0;n<this.config.categories[t].cookies.length;n++){const a=this.config.categories[t].cookies[n];a.isAccepted?e.push(a.enable()):e.push(a.disable())}return Promise.all(e)}}F=new WeakMap;function ne(r,e='script[type="cookie-consent"]'){const t=Pe(e);r.categories=Ie(t,r.categories);const n=new je(r);return new Promise(a=>{n.init().then(()=>a(n))})}function ae(r,e,t=[]){return new B({name:r,description:e,cookies:t})}const He={setup:ne,createCategory:ae,Category:B,CookieDefinition:_,UITranslationsDefault:Me,UIEvent};h.createCategory=ae,h.default=He,h.setup=ne,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
`;const s=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Save]:"",hidden:"","aria-hidden":"true"});s.innerText=this.translations.btn.save[this.locale];const l=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Params]:""});l.innerText=this.translations.btn.params[this.locale];const d=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.Reject]:""});d.innerText=this.translations.btn.reject[this.locale];const f=this.createHTMLElement("button",{type:"button",class:"cc_btn",[C.SaveAll]:""});f.innerText=this.translations.btn.saveAll[this.locale],e.appendChild(t),this.container.appendChild(e),this.container.appendChild(n),this.container.appendChild(a),this.container.appendChild(i),i.appendChild(l),i.appendChild(d),i.appendChild(s),i.appendChild(f),this.categories.forEach(k=>{a.appendChild(this.categoryHtml(k))}),document.body.appendChild(this.container)}addParamsEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Params+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{var l;n.preventDefault();const a=this.container.querySelector("button["+C.Save+"]"),i=this.container.querySelector("button["+C.SaveAll+"]"),s=this.container.querySelector(".cc_body");if(s&&s.hasAttribute("hidden")){t.innerText=this.translations.btn.closeParams[this.locale],S.showElement(s),(l=s.querySelector("button"))==null||l.focus(),a!==null&&S.showElement(a),i!==null&&S.hideElement(i);const d=t.querySelector("button");d==null||d.focus()}else t.innerText=this.translations.btn.params[this.locale],s!==null&&S.hideElement(s),a!==null&&S.hideElement(a),i!==null&&S.showElement(i)})})}addSaveAllEvent(){const e=[].slice.call(document.querySelectorAll("["+C.SaveAll+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{n.preventDefault();const a=this.createEvent(E.AcceptAll,{});this.container.dispatchEvent(a)})})}addSaveEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Save+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",n=>{n.preventDefault();const a=this.createEvent(E.Save,{});this.container.dispatchEvent(a)})})}addRejectEvent(){const e=[].slice.call(document.querySelectorAll("["+C.Reject+"]"));e.length>0&&e.forEach(t=>{t.addEventListener("click",()=>{const n=this.createEvent(E.Reject,{});this.container.dispatchEvent(n)})})}categoryHtml(e){const t=this.createHTMLElement("div",{class:"cc_category"}),n=this.createHTMLElement("div",{class:"cc_category_inner",hidden:"","aria-hidden":"true"}),a=this.createHTMLElement("button",{type:"button",class:"cc_category_title","data-cc-category-trigger":"button"});if(a.innerText=e.name,t.appendChild(a),e.description){const s=this.createHTMLElement("div",{class:"cc_description"});s.innerHTML=e.description,n.appendChild(s)}const i=this.createHTMLElement("ul",{});return e.cookies.forEach(s=>{const l=this.createHTMLElement("li",{});l.appendChild(this.cookieDefinitionHtml(s)),i.appendChild(l)}),n.appendChild(i),t.appendChild(n),a.addEventListener("click",function(s){var d;s.preventDefault();const l=a.nextElementSibling;if(l&&l.hasAttribute("hidden"))this.classList.add("is-open"),S.showElement(l),(d=l.querySelector("input"))==null||d.focus(),l.addEventListener("animationend",function f(k){if(k.animationName==="fadeIn"){const m=Array.from(l.querySelectorAll("input.cc_switch"));for(const w of m)w.classList.remove("cc-disable-anim");l.removeEventListener("animationend",f)}},!1);else{this.classList.remove("is-open");const f=Array.from(l.querySelectorAll("input.cc_switch"));for(const k of f)k.classList.add("cc-disable-anim");l&&S.hideElement(l)}}),t}cookieDefinitionHtml(e){const t=document.createElement("div");t.classList.add("cc_cookie");const n=document.createElement("div");n.classList.add("cc_switch_container");const a=document.createElement("p");a.classList.add("cc_description"),a.innerHTML=e.description;const i=document.createElement("label");i.innerHTML=e.name,i.setAttribute("for",e.id);const s=document.createElement("input");return s.type="checkbox",s.dataset.category=e.categoryName,s.name=e.name,s.value=e.name,s.id=e.id,s.classList.add("cc_switch"),s.ariaLabel=e.name,s.disabled=!e.isRevocable,s.readOnly=!e.isRevocable,s.classList.add("cc-disable-anim"),(e.isAccepted||!e.isRevocable)&&s.setAttribute("checked","checked"),n.appendChild(s),n.appendChild(i),s.addEventListener("change",l=>{l.preventDefault();const d=new CustomEvent(E.Change,{detail:{checkbox:s,cookie:e}});this.container.dispatchEvent(d)}),t.appendChild(n),t.appendChild(a),t}createHTMLElement(e,t){const n=document.createElement(e);for(const a in t)n.setAttribute(a,t[a]);return n}static hideElement(e){e.setAttribute("hidden",""),e.classList.remove("is-open"),e.setAttribute("aria-hidden","true")}static showElement(e){e.removeAttribute("hidden"),e.classList.add("is-open"),e.setAttribute("aria-hidden","false")}createEvent(e,t){return new CustomEvent(e,{detail:{...t}})}}var E=(r=>(r.Save="on:save",r.AcceptAll="on:acceptAll",r.Reject="on:reject",r.Change="on:change",r))(E||{}),C=(r=>(r.Save="data-cc-save",r.SaveAll="data-cc-save-all",r.Reject="data-cc-reject",r.Params="data-cc-params",r))(C||{});class _{constructor(e){this.config=e,this._enabled=!1,this._accepted=!1,this.config=e}get id(){return`${this.categoryName}_${this.name}`}get isEnabled(){return this._enabled}set enabled(e){this._enabled=e}get isAccepted(){return this.isRevocable?this._accepted:!0}set accepted(e){this._accepted=e}get name(){return this.config.name}get description(){return this.config.description}get isRevocable(){return this.config.revocable}get categoryName(){return this.config.categoryName||"undefined"}set categoryName(e){this.config.categoryName=e}enable(){return new Promise((e,t)=>{this.isAccepted||t("Cookie is not accepted");let n=[];this.config.scripts.forEach(a=>{var s;if(a.type!=="cookie-consent")return;const i=_.copyScriptTag(a);i.dataset.src&&(i.src=i.dataset.src),i.type=i.dataset.type||"text/javascript",n.push(i),a.insertAdjacentElement("beforebegin",i),(s=a.parentElement)==null||s.removeChild(a)}),this.config.scripts=n,this._enabled=!0,e()})}disable(){return new Promise(e=>{if(this.isRevocable&&this.isEnabled){const t=Oe();for(const n of this.config.tokens){const a=t.find(i=>{if(n.endsWith("*")){const l=new RegExp(n+"[^;]+").exec(i.name.slice(0,-1));return l&&l[0]?i:void 0}return i.name===n});if(a){const i=new Date("1970");let s=location.hostname.replace("www","");document.cookie=`${a.name}=; expires=${i.toUTCString()}; Domain=${s}; Max-Age=0; path=/;`}}this._enabled=!1,this._accepted=!1}e()})}addScripts(e){this.config.scripts=[...this.config.scripts,...e]}addTokens(e){this.config.tokens=[...this.config.tokens,...e]}static copyScriptTag(e){const t=document.createElement("script");for(let n=0;n<e.attributes.length;n++){const a=e.attributes[n];t.setAttribute(a.name,a.value),t.innerHTML=e.innerHTML}return t}}class B{constructor(e){this.config=e}get description(){return this.config.description}get name(){return this.config.name}get cookies(){return this.config.cookies}addCookie(e){var n;const t=new _(e);return t.categoryName=(n=e.categoryName)!=null?n:this.config.name,this.config.cookies.push(t),this}getCookie(e){return this.cookies.find(t=>t.name===e)}}function xe(r){var n;let t=("; "+document.cookie).split("; "+r+"=");return t.length<2||(n=t.pop())==null?void 0:n.split(";").shift()}function Oe(){return document.cookie.split(";").map(r=>{const[e,t]=r.split("=").map(n=>n.trim());return{name:e,value:t}})}function Pe(r){let e=[];const t=[].slice.call(document.querySelectorAll(r));for(let n=0;n<t.length;n++){const a=t[n],i=a.dataset.name,s=a.dataset.description||"",l=a.hasAttribute("data-accepted"),d=!(a.hasAttribute("data-revocable")&&a.dataset.revocable==="false"),f=a.dataset.category||"undefined",k=a.dataset.tokens;let m=[];if(k&&(m=k.split(","),m=m.map(A=>A.trim())),i===void 0){console.error(`Name is missing on: ${a.outerHTML}`);continue}let w=e.find(A=>A.name===f);w===void 0&&(w=new B({name:f,description:"",cookies:[]}),e.push(w));let N=w.cookies.find(A=>A.name===i);N===void 0?w.addCookie({categoryName:f,name:i.trim(),description:s.trim(),scripts:[a],tokens:m,accepted:l,revocable:d}):(N.addScripts([a]),N.addTokens(m))}return e}function Ie(r,e){const t=r.slice();for(let n=0;n<e.length;n++){const a=e[n],i=r.find(s=>s.name===a.name);if(i===void 0){t.push(a);continue}for(let s=0;s<a.cookies.length;s++){const l=a.cookies[s];i.cookies.find(f=>f.name===l.name)===void 0&&(i==null||i.cookies.push(l))}}return t}const Me={title:{fr:"Nous utilisons des cookies",en:"We use cookies",de:"Wir verwenden Cookies"},description:{fr:"Nous utilisons des cookies pour nous assurer du bon fonctionnement de notre site, pour personnaliser notre contenu et nos publicit\xE9s et afin d\u2019analyser notre trafic. En utilisant ce site Internet ou en fermant ce bandeau, vous consentez \xE0 l'utilisation de ces cookies.",en:"We use cookies to ensure that our site functions properly, to personalize our content and advertising, and to analyze our traffic. By using this website or closing this banner, you consent to the use of these cookies.",de:"Wir verwenden Cookies, um sicherzustellen, dass unsere Website ordnungsgem\xE4\xDF funktioniert, um unseren Inhalt und unsere Werbung zu personalisieren und um unseren Datenverkehr zu analysieren. Durch die Nutzung dieser Website oder das Schlie\xDFen dieses Banners stimmen Sie der Verwendung dieser Cookies zu."},btn:{params:{fr:"G\xE9rer les pr\xE9f\xE9rences",en:"Manage my preferences",de:"Pr\xE4ferenzen verwalten"},closeParams:{fr:"Fermer les pr\xE9f\xE9rences",en:"Close preferences",de:"Pr\xE4ferenzen schliessen"},reject:{fr:"Refuser",en:"Deny",de:"Ablehnen"},saveAll:{fr:"Accepter",en:"Accept",de:"Alle akzeptieren"},save:{fr:"Enregistrer la s\xE9lection",en:"Save selection",de:"Auswahl speichern"},continue:{fr:"Continuer sans accepter",en:"Continue without accepting",de:"Ohne Zustimmung fortfahren"}},categories:{mandatory:{title:{fr:"Obligatoire",en:"Mandatory",de:"Erforderlich"},description:{fr:"Cookies requis pour le bon fonctionnement du site.",en:"We use required cookies to perform essential website functions.",de:""}}}};class je{constructor(e){ue(this,F,void 0);this.config=e,de(this,F,"_cookie_consent"),this.needToReload=!1,this.UI=new S(this.config.categories,this.config.translations),this.UI.init()}async init(){const e=this.getUserConsent();return!e||e&&e.version!==this.config.version?this.UI.show():this.updateConsentFromStorage(e),await this.enableAccepted(),this.UI.container.addEventListener(E.Change,t=>{const n=t.detail.cookie,a=this.getCategoryByName(n.categoryName);if(a){const i=a.getCookie(n.name);i&&(this.needToReload||(this.needToReload=!t.detail.checkbox.checked&&i.isEnabled),i.accepted=t.detail.checkbox.checked)}}),this.UI.container.addEventListener(E.Save,async()=>{await this.save(E.Save),this.UI.hide()}),this.UI.container.addEventListener(E.AcceptAll,async()=>{await this.save(E.AcceptAll),this.UI.hide()}),this.UI.container.addEventListener(E.Reject,async()=>{await this.save(E.Reject),this.UI.hide()}),Promise.resolve(this)}show(){this.UI.show()}hide(){this.UI.hide()}async save(e){switch(e){case E.Save:await this.enableAccepted();break;case E.AcceptAll:await this.acceptAll(!0).then(()=>{this.UI.update(this.config.categories)});break;case E.Reject:await this.acceptAll(!1).then(()=>{this.UI.update(this.config.categories)});break}this.saveUserConsent(),this.config.forceReload&&this.needToReload&&(window.location.reload(),this.needToReload=!1)}updateConsentFromStorage(e){e.cookies.forEach(t=>{const n=this.getCategoryByName(t.category);if(n){const a=n.getCookie(t.name);a&&(a.accepted=t.accepted)}}),this.UI.update(this.config.categories)}saveUserConsent(){const e=new Date;e.setMonth(e.getMonth()+12),document.cookie=`${W(this,F)}=${this.serializeUserConsent()}; expires=${e.toUTCString()}; path=/; SameSite=Lax;`}serializeUserConsent(){let e={version:this.config.version,cookies:[]};return this.config.categories.forEach(t=>{t.cookies.forEach(n=>{e.cookies.push({category:t.name,name:n.name,accepted:n.isAccepted})})}),JSON.stringify(e)}getUserConsent(){const e=xe(W(this,F));return e?JSON.parse(e):void 0}getCategoryByName(e){return this.config.categories.find(t=>t.name===e)}acceptAll(e){let t=[];for(let n=0;n<this.config.categories.length;n++)for(let a=0;a<this.config.categories[n].cookies.length;a++){const i=this.config.categories[n].cookies[a];i.isRevocable&&(i.isAccepted&&!e&&(this.needToReload=!0),i.accepted=e,e?t.push(i.enable()):t.push(i.disable()))}return Promise.all(t)}enableAccepted(){let e=[];for(let t=0;t<this.config.categories.length;t++)for(let n=0;n<this.config.categories[t].cookies.length;n++){const a=this.config.categories[t].cookies[n];a.isAccepted?e.push(a.enable()):e.push(a.disable())}return Promise.all(e)}}F=new WeakMap;function ne(r,e='script[type="cookie-consent"]'){const t=Pe(e);r.categories=Ie(t,r.categories);const n=new je(r);return new Promise(a=>{n.init().then(()=>a(n))})}function ae(r,e,t=[]){return new B({name:r,description:e,cookies:t})}const He={setup:ne,createCategory:ae,Category:B,CookieDefinition:_,UITranslationsDefault:Me,UIEvent};h.createCategory=ae,h.default=He,h.setup=ne,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Cookie consent", | ||
@@ -9,0 +9,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90943
1963