From c3e122ac0b791bf6069bfda2e8f27154f6dae8bf Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Wed, 17 Jul 2024 10:25:22 +0200 Subject: [PATCH] fix: #20 - Bump CN to 6.0.3 --- content/themes/ldc/js/ldcweb-cn.min.js | 2 +- content/themes/ldc/package-lock.json | 8 ++++---- content/themes/ldc/package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/content/themes/ldc/js/ldcweb-cn.min.js b/content/themes/ldc/js/ldcweb-cn.min.js index 92a480e5..94abd7f9 100644 --- a/content/themes/ldc/js/ldcweb-cn.min.js +++ b/content/themes/ldc/js/ldcweb-cn.min.js @@ -1 +1 @@ -!function(){var e,t;!function(e){e.true="true",e.false="false",e.wait="wait"}(e||(e={})),function(e){e.lax="lax",e.strict="strict",e.none="none"}(t||(t={}));const o={cookieName:"cn-init",cookieTimeLife:6,cookieExpirationName:"_expiration",cookiePolicies:{sameSite:t.lax,secure:!1},restrictCloseModal:!0};var i=new Map([["youtube",["NID","ENID","_Secure-ENID","VISITOR_INFO1_LIVE","YEC","__Secure-YEC","YSC","GEUP","PREF","pm_sess","CGIC","SOCS","GPS","yt-player-bandwidth","yt-player-headers-readable"]],["recaptcha",["NID","_grecaptcha","__Secure-3PAPISID","__Secure-3PSID","__Secure-3PSIDCC","_GRECAPTCHA","rc::c","rc::b","rc::a","itsec-recaptcha-opt-in-*"]],["vimeo",["vuid","__utmt_player"]],["matomo",["_pk*","_pk_ref","_pk_cvar","_pk_id","_pk_ses","_pk_hsr","piwik_ignore","_pk_uid","_pk_ref","_pk_cvar","_pk_id","_pk_ses","_pk_hsr","mtm_consent","matomo_ignore","matomo_sessid"]]]);class s{static has(e){return this.getCookies().has(e)}static get(e){return this.getCookies().get(e)}static set(e,t,o=null,i=null){let s=`${e}=${t};path=/${location.hostname?`;domain=${location.hostname}`:""}`;o&&(s+=`;expires=${o.toUTCString()}`),i&&(s+=`;sameSite=${i.sameSite}${i.secure?";secure":""}`),document.cookie=s}static getAllStartingWith(e){const t=this.getCookies();for(const o of t.keys())o.startsWith(e)||t.delete(o);return t}static markForDeletion(e){s.has(e)||console.debug(`No document cookie named ${e}`),document.cookie=`${e}=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT`,document.cookie=`${e}=;path=/${location.hostname?`;domain=.${location.hostname}`:""};expires=Thu, 01 Jan 1970 00:00:01 GMT`,document.cookie=`${e}=;path=/${location.hostname?`;domain=${location.hostname}`:""};expires=Thu, 01 Jan 1970 00:00:01 GMT`}static getCookies(){const e=new Map;return document.cookie.split(";").filter((e=>e)).forEach((t=>{const o=t.split(/=(.*)/s).filter((e=>e));e.set(o[0].trim(),o[1].trim())})),e}}window.DocumentCookie=s;window.CookieNotice=class{constructor(t){this.config=t,this.cookieName=o.cookieName,this.cookieTimeLife=o.cookieTimeLife,this.cookieExpirationName=o.cookieExpirationName,this.cookiePolicies=o.cookiePolicies,this.restrictCloseModal=o.restrictCloseModal,this.cookieExpirationDate=new Date,this.domElList={},[...Object.keys(this.config)].forEach((e=>{this.config[e].cookies=[...new Set([...this.config[e].cookies,...i.get(e)??[]])]})),this.cookieExpirationDate=this.getCnCookieInfo().date,this.initDomElements(),this.setupEvents(),(this.configHasChanged()||this.configHasExpired())&&(this.resetCnCookie(),this.openCookieModalToBannerPage()),this.updateRestrictCloseModal(),this.getCnCookieInfo().values.forEach(((t,o)=>{switch(t){case e.wait:this.openCookieModalToBannerPage();break;case e.true:this.acceptCookie(o);break;case e.false:default:this.denyCookie(o)}}))}acceptAllCookies(){[...this.getCnCookieInfo().values.keys()].forEach((e=>this.acceptCookie(e)))}acceptCookie(t){this.setCnCookieStatus(t,e.true),this.setCookieSwitchButton(t,e.true)}denyAllCookies(){[...this.getCnCookieInfo().values.keys()].forEach((e=>this.denyCookie(e)))}denyCookie(t){this.setCnCookieStatus(t,e.false),this.setCookieSwitchButton(t,e.false)}denyAllWaitingCookies(){this.getCnCookieInfo().values.forEach(((t,o)=>{t!==e.wait||this.persistCnCookie(o,e.false)})),this.updateRestrictCloseModal()}getCookieConfig(e){const t=Object.entries(this.config).find((t=>t[0]===e))?.[1];if(void 0===t)throw new Error(`Cookie options ${e} not found in list`);return t}configHasExpired(){return this.cookieExpirationDate.getTime()<(new Date).getTime()}configHasChanged(){const e=this.getCnCookieInfo().values;return e.size!==Object.keys(this.config).length||[...e.keys()].join(".")!==Object.keys(this.config).join(".")}invertCookieStatus(t){switch(t){case e.true:case e.wait:return e.false;case e.false:return e.true;default:throw new Error(`Un handled cookie status ${t}`)}}getNewExpirationDate(){const e=new Date;return e.setMonth(this.cookieExpirationDate.getMonth()+this.cookieTimeLife),e}getCnCookieInfo(){const e=this.getCnCookieValues(),t=e.get(this.cookieExpirationName)??this.getNewExpirationDate();return e.delete(this.cookieExpirationName),{name:this.cookieName,values:e,date:t,cookiePolicies:this.cookiePolicies}}getCnCookieStatus(e){const t=this.getCnCookieInfo().values.get(e);if(void 0===t)throw new Error(`Cookie options ${e} not found in list`);return t}setCnCookieStatus(t,o){const i=this.getCookieConfig(t);this.persistCnCookie(t,o),o!==e.true?o!==e.false?this.persistCnCookie(t,e.wait):i.fallback&&i.fallback():i.script()}persistCnCookieList(t){const o=Array.from(t.entries()).map((([t,o])=>(o===e.false&&this.getCookieConfig(t).cookies.forEach((e=>{[...s.getAllStartingWith(e.replace(/\*+$/,"")).keys()].forEach((e=>s.markForDeletion(e)))})),`${t}=${o}`)));this.cookieExpirationDate=this.getNewExpirationDate(),o.push(`${this.cookieExpirationName}=${this.cookieExpirationDate.getTime()}`),s.set(this.cookieName,o.join(","),this.cookieExpirationDate,this.cookiePolicies)}getCnCookieValues(){const e=(s.get(this.cookieName)??"").split(",").filter((e=>e)).map((e=>e.split(/=|(?:->)/s))),t=new Map;return e.forEach((e=>{const o=e[0],i=e[1];if(o!==this.cookieExpirationName)t.set(e[0],e[1]);else{let o=new Date;o.setMonth(this.cookieExpirationDate.getMonth()+this.cookieTimeLife);try{const e=Number.parseInt(i);isNaN(e)||(o=new Date(e))}finally{t.set(e[0],o)}}})),t}resetCnCookie(){const t=new Map;Object.entries(this.config).forEach((([o])=>t.set(o,e.wait))),this.persistCnCookieList(t)}persistCnCookie(e,t){const o=this.getCnCookieInfo().values;s.markForDeletion(this.cookieName),o.set(e,t),this.persistCnCookieList(o),this.updateRestrictCloseModal()}addEvent(e,t,o){e.addEventListener(t,o.bind(this),!1)}addEventPrevent(e,t,o){e.addEventListener(t,(e=>{e.preventDefault(),o.call(this,e)}),!1)}addEventKbdValidate(e,t){this.addEvent(e,"keydown",(e=>{const o=e;" "!=o.key&&"Space"!=o.code&&32!=o.keyCode&&"Enter"!=o.key&&"Enter"!=o.code&&13!=o.keyCode||(t.call(this,o),e.preventDefault())}))}setCookieSwitchButton(t,o){const i=document.getElementById(`${t}-switch`),s=i?.querySelector("input");i&&s&&(s.indeterminate=o===e.wait,s.checked=o===e.true,i.ariaChecked=o===e.wait?e.false:o)}updateRestrictCloseModal(){const t=this.getDomEl("cookieCloseModalBtn"),o=this.getDomEl("modalBg");this.restrictCloseModal=!!Array.from(this.getCnCookieInfo().values.values()).includes(e.wait),this.restrictCloseModal?t.classList.add("d-none"):t.classList.remove("d-none"),this.restrictCloseModal?o.classList.add("cn-modal-bg-active"):o.classList.remove("cn-modal-bg-active")}toggleCookieModal(){document.body.classList.contains("cn-open")?this.closeCookieModal():this.openCookieModalToBannerPage()}openCookieModalToBannerPage(){this.openCookieModalToCookiePage(),this.toggleCookieModalPages()}openCookieModalToCookiePage(){document.body.classList.add("cn-open"),this.resetCookieModal(),this.getDomEl("bannerContent").classList.add("d-none"),this.getDomEl("modalContainer").classList.remove("d-none"),this.getDomEl("bannerContainer").classList.add("cn-modal-page"),this.getDomEl("modalContainer").scrollTop=0,this.setupCookieModalList(),this.setTabIndex()}closeCookieModal(){if(this.updateRestrictCloseModal(),this.restrictCloseModal)throw new Error("You need to accept or refuse all cookies");document.body.classList.remove("cn-open"),this.isOnBannerPage()||(this.getDomEl("bannerContent").classList.toggle("d-none"),this.getDomEl("modalContainer").classList.toggle("d-none"),this.getDomEl("bannerContainer").classList.remove("cn-modal-page")),this.unsetTabIndex(),this.setupCookieModalList()}setTabIndex(){document.documentElement.setAttribute("tabindex","-1"),setTimeout((()=>{const e='a[href], button, [role="button"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex="-1"])',t=this.getDomEl("cookieContainer");[...document.body.querySelectorAll(e)].filter((e=>!e.hasAttribute("disabled")&&!e.getAttribute("aria-hidden")&&!t.contains(e))).forEach((e=>{e.setAttribute("tabindex","-1"),e.classList.add("cn-disabled")})),[...t.querySelectorAll(e)].filter((e=>!(e.hasAttribute("disabled")||e.getAttribute("aria-hidden")||!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)||t.contains(e)))).forEach((e=>{e.setAttribute("tabindex","0"),e.classList.remove("cn-disabled")})),this.getDomEl("cookieShowModalBtn").setAttribute("tabindex","-1")}),500)}unsetTabIndex(){document.documentElement.setAttribute("tabindex","0"),setTimeout((()=>{document.body.querySelectorAll(".cn-disabled").forEach((e=>{e.setAttribute("tabindex","0"),e.classList.remove("cn-disabled")})),this.getDomEl("cookieShowModalBtn").setAttribute("tabindex","0")}),500)}resetCookieModal(){const e=this.getDomEl("customizeBtn");if(this.getDomEl("bannerContent").classList.remove("d-none"),this.getDomEl("modalContainer").classList.add("d-none"),this.getDomEl("bannerContainer").classList.remove("cn-modal-page"),!e.dataset.openModal)throw new Error("Cannot find attribut data-open-modal");e.innerHTML=e.dataset.openModal}setupCookieModalList(){this.getDomEl("cookiesUnorderedList").innerHTML="",Object.entries(this.config).forEach((([t,o])=>{if(this.initDomCookieSwitch(t,o),!s.has(this.cookieName))return;let i=e.wait;try{i=this.getCnCookieStatus(t)}finally{this.setCookieSwitchButton(t,i)}}))}switchToModalPageOrClose(){this.isOnBannerPage()?this.toggleCookieModalPages():this.closeCookieModal()}toggleCookieModalPages(){this.getDomEl("bannerContent").classList.toggle("d-none"),this.getDomEl("modalContainer").classList.toggle("d-none"),this.getDomEl("bannerContainer").classList.toggle("cn-modal-page"),this.isOnBannerPage()||(this.getDomEl("bannerContainer").classList.add("cn-modal-page"),this.denyAllWaitingCookies()),this.setTabIndex(),this.setupCookieModalList(),this.toggleCustomizeBtn()}toggleCustomizeBtn(){const e=this.getDomEl("customizeBtn"),t=this.getDomEl("customizeBtn").dataset;this.getDomEl("modalContainer").scrollTop=0,this.getDomEl("bannerContent").classList.contains("d-none")?(e.innerHTML=t.openModal,e.title=t.openModal):(e.innerHTML=t.closeModal,e.title=t.closeModal)}isOnBannerPage(){return this.getDomEl("modalContainer").classList.contains("d-none")}setupEvents(){this.addEventPrevent(this.getDomEl("modalBg"),"click",this.closeCookieModal),this.addEventPrevent(this.getDomEl("cookieCloseModalBtn"),"click",this.closeCookieModal),this.addEventPrevent(this.getDomEl("acceptAllBtn"),"click",(()=>{this.acceptAllCookies(),this.closeCookieModal()})),this.addEventPrevent(this.getDomEl("denyAllBtn"),"click",(()=>{this.denyAllCookies(),this.closeCookieModal()})),this.addEventPrevent(this.getDomEl("customizeBtn"),"click",this.switchToModalPageOrClose),this.addEventPrevent(this.getDomEl("cookieShowModalBtn"),"click",this.toggleCookieModal),this.getDomEl("cookieLinkShowCustomizeModalList").forEach((e=>{this.addEventPrevent(e,"click",this.openCookieModalToCookiePage),this.addEventKbdValidate(e,this.openCookieModalToCookiePage)}))}getDomEl(e){return this.domElList[e]}initDomCookieSwitch(t,o){const i=document.createElement("li"),s=this.getDomEl("template").children.item(0);if(null===s)throw new Error("Cannot find child item");i.append(s.cloneNode(!0));const n=i.querySelector("span.cn-cookie-name"),a=i.querySelector("span.cn-cookie-description"),c=i.querySelector(".cn-cookie-link"),l=i.querySelector(".cn-switch"),r=i.querySelector(".cn-switch > input");r.indeterminate=!0,r.checked=!1,n.textContent=o.name,a.id=`${t}-desc`,a.textContent=o.description,c.textContent=o.labelLink,c.setAttribute("href",o.link),l.id=`${t}-switch`,l.name=t,l.dataset.name=t,l.setAttribute("aria-labelledby",`${t}-desc`),l.setAttribute("aria-describedby",`${t}-desc`);const d=t=>{let o=e.wait;try{o=this.getCnCookieStatus(t)}finally{this.setCnCookieStatus(t,this.invertCookieStatus(o))}};this.addEvent(r,"click",(()=>d(t))),this.addEventKbdValidate(l,(()=>r.click())),this.getDomEl("cookiesUnorderedList").append(i)}initDomElements(){const e=document.createElement("div");e.classList.add("cn-modal-bg"),document.body.append(e),this.domElList.modalBg=e,this.domElList.cookieLinkShowCustomizeModalList=document.querySelectorAll(".cn-cookie-link");Object.entries({"div#cn-wrapper":"cookieContainer","button#cn-cookie-btn":"cookieShowModalBtn","button#cn-close-modal":"cookieCloseModalBtn","div#cn-banner":"bannerContainer","div.cn-banner-content":"bannerContent","div.cn-modal-container":"modalContainer","button#cn-accept-banner":"acceptAllBtn","button#cn-deny-banner":"denyAllBtn","button#cn-settings-banner":"customizeBtn","ul#cn-modal-list":"cookiesUnorderedList","div#cn-li-template":"template"}).forEach((e=>{const t=e[0],o=e[1];let i=this.domElList[o];if(i=document.querySelector(t),!i)throw new Error(`Cannot find dom element ${t}`);this.domElList={...this.domElList,[o]:i}}));const t=this.domElList.template.cloneNode(!0);this.domElList.template.remove(),this.domElList.template=t}}}(); +!function(){var e,t;!function(e){e.true="true",e.false="false",e.wait="wait"}(e||(e={})),function(e){e.lax="lax",e.strict="strict",e.none="none"}(t||(t={}));const o={cookieName:"cn-init",cookieTimeLife:6,cookieExpirationName:"_expiration",cookiePolicies:{sameSite:t.lax,secure:!1},restrictCloseModal:!0};var i=new Map([["youtube",["NID","ENID","_Secure-ENID","VISITOR_INFO1_LIVE","YEC","__Secure-YEC","YSC","GEUP","PREF","pm_sess","CGIC","SOCS","GPS","yt-player-bandwidth","yt-player-headers-readable"]],["recaptcha",["NID","_grecaptcha","__Secure-3PAPISID","__Secure-3PSID","__Secure-3PSIDCC","_GRECAPTCHA","rc::c","rc::b","rc::a","itsec-recaptcha-opt-in-*"]],["vimeo",["vuid","__utmt_player"]],["matomo",["_pk*","_pk_ref","_pk_cvar","_pk_id","_pk_ses","_pk_hsr","piwik_ignore","_pk_uid","_pk_ref","_pk_cvar","_pk_id","_pk_ses","_pk_hsr","mtm_consent","matomo_ignore","matomo_sessid"]]]);class s{static has(e){return this.getCookies().has(e)}static get(e){return this.getCookies().get(e)}static set(e,t,o=null,i=null){let s=`${e}=${t};path=/${location.hostname?`;domain=${location.hostname}`:""}`;o&&(s+=`;expires=${o.toUTCString()}`),i&&(s+=`;sameSite=${i.sameSite}${i.secure?";secure":""}`),document.cookie=s}static getAllStartingWith(e){const t=this.getCookies();for(const o of t.keys())o.startsWith(e)||t.delete(o);return t}static markForDeletion(e){s.has(e)||console.debug(`No document cookie named ${e}`),document.cookie=`${e}=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;sameSite=Lax`,document.cookie=`${e}=;path=/${location.hostname?`;domain=.${location.hostname}`:""};expires=Thu, 01 Jan 1970 00:00:01 GMT;sameSite=Lax`,document.cookie=`${e}=;path=/${location.hostname?`;domain=${location.hostname}`:""};expires=Thu, 01 Jan 1970 00:00:01 GMT;sameSite=Lax`}static getCookies(){const e=new Map;return document.cookie.split(";").filter((e=>e)).forEach((t=>{const o=t.split(/=(.*)/s).filter((e=>e));e.set(o[0].trim(),o[1].trim())})),e}}window.DocumentCookie=s;window.CookieNotice=class{constructor(t){this.config=t,this.cookieName=o.cookieName,this.cookieTimeLife=o.cookieTimeLife,this.cookieExpirationName=o.cookieExpirationName,this.cookiePolicies=o.cookiePolicies,this.restrictCloseModal=o.restrictCloseModal,this.cookieExpirationDate=new Date,this.domElList={},[...Object.keys(this.config)].forEach((e=>{this.config[e].cookies=[...new Set([...this.config[e].cookies,...i.get(e)??[]])]})),this.cookieExpirationDate=this.getCnCookieInfo().date,this.initDomElements(),this.setupEvents(),(this.configHasChanged()||this.configHasExpired())&&(this.resetCnCookie(),this.openCookieModalToBannerPage()),this.updateRestrictCloseModal(),this.getCnCookieInfo().values.forEach(((t,o)=>{t!==e.wait?(this.setCnCookieStatus(o,t),this.setCookieSwitchButton(o,t)):this.openCookieModalToBannerPage()}))}acceptAllCookies(){[...this.getCnCookieInfo().values.keys()].forEach((e=>this.acceptCookie(e)))}acceptCookie(t){this.setCnCookieStatus(t,e.true),this.setCookieSwitchButton(t,e.true),this.refreshCnCookieExpirationDate()}denyAllCookies(){[...this.getCnCookieInfo().values.keys()].forEach((e=>this.denyCookie(e)))}denyCookie(t){this.setCnCookieStatus(t,e.false),this.setCookieSwitchButton(t,e.false),this.refreshCnCookieExpirationDate()}denyAllWaitingCookies(){this.getCnCookieInfo().values.forEach(((t,o)=>{t!==e.wait||this.persistCnCookie(o,e.false)})),this.updateRestrictCloseModal()}getCookieConfig(e){const t=Object.entries(this.config).find((t=>t[0]===e))?.[1];if(void 0===t)throw new Error(`Cookie options ${e} not found in list`);return t}configHasExpired(){return this.cookieExpirationDate.getTime()<(new Date).getTime()}configHasChanged(){const e=this.getCnCookieInfo().values;return e.size!==Object.keys(this.config).length||[...e.keys()].join(".")!==Object.keys(this.config).join(".")}invertCookieStatus(t){switch(t){case e.true:case e.wait:return e.false;case e.false:return e.true;default:throw new Error(`Un handled cookie status ${t}`)}}getNewExpirationDate(){const e=new Date;return new Date(e.setMonth(e.getMonth()+this.cookieTimeLife))}getCnCookieInfo(){const e=this.getCnCookieValues(),t=e.get(this.cookieExpirationName)??this.getNewExpirationDate();return e.delete(this.cookieExpirationName),{name:this.cookieName,values:e,date:t,cookiePolicies:this.cookiePolicies}}getCnCookieStatus(e){const t=this.getCnCookieInfo().values.get(e);if(void 0===t)throw new Error(`Cookie options ${e} not found in list`);return t}setCnCookieStatus(t,o){const i=this.getCookieConfig(t);this.persistCnCookie(t,o),o!==e.true?o!==e.false?this.persistCnCookie(t,e.wait):i.fallback&&i.fallback():i.script()}persistCnCookieList(t){const o=Array.from(t.entries()).map((([t,o])=>(o===e.false&&this.getCookieConfig(t).cookies.forEach((e=>{[...s.getAllStartingWith(e.replace(/\*+$/,"")).keys()].forEach((e=>s.markForDeletion(e)))})),`${t}=${o}`)));o.push(`${this.cookieExpirationName}=${this.cookieExpirationDate.getTime()}`),s.set(this.cookieName,o.join(","),this.cookieExpirationDate,this.cookiePolicies)}refreshCnCookieExpirationDate(){const e=Array.from(this.getCnCookieInfo().values.entries()).map((([e,t])=>`${e}=${t}`));this.cookieExpirationDate=this.getNewExpirationDate(),e.push(`${this.cookieExpirationName}=${this.cookieExpirationDate.getTime()}`),s.set(this.cookieName,e.join(","),this.cookieExpirationDate,this.cookiePolicies)}getCnCookieValues(){const e=(s.get(this.cookieName)??"").split(",").filter((e=>e)).map((e=>e.split(/=|(?:->)/s))),t=new Map;return e.forEach((e=>{const o=e[0],i=e[1];if(o!==this.cookieExpirationName)t.set(e[0],e[1]);else{let o=this.getNewExpirationDate();try{const e=Number.parseInt(i);isNaN(e)||(o=new Date(e))}finally{t.set(e[0],o)}}})),t}resetCnCookie(){const t=new Map;Object.entries(this.config).forEach((([o])=>t.set(o,e.wait))),this.persistCnCookieList(t)}persistCnCookie(e,t){const o=this.getCnCookieInfo().values;s.markForDeletion(this.cookieName),o.set(e,t),this.persistCnCookieList(o),this.updateRestrictCloseModal()}addEvent(e,t,o){e.addEventListener(t,o.bind(this),!1)}addEventPrevent(e,t,o){e.addEventListener(t,(e=>{e.preventDefault(),o.call(this,e)}),!1)}addEventKbdValidate(e,t){this.addEvent(e,"keydown",(e=>{const o=e;" "!=o.key&&"Space"!=o.code&&32!=o.keyCode&&"Enter"!=o.key&&"Enter"!=o.code&&13!=o.keyCode||(t.call(this,o),e.preventDefault())}))}setCookieSwitchButton(t,o){const i=document.getElementById(`${t}-switch`),s=i?.querySelector("input");i&&s&&(s.indeterminate=o===e.wait,s.checked=o===e.true,i.ariaChecked=o===e.wait?e.false:o)}updateRestrictCloseModal(){const t=this.getDomEl("cookieCloseModalBtn"),o=this.getDomEl("modalBg");this.restrictCloseModal=!!Array.from(this.getCnCookieInfo().values.values()).includes(e.wait),this.restrictCloseModal?t.classList.add("d-none"):t.classList.remove("d-none"),this.restrictCloseModal?o.classList.add("cn-modal-bg-active"):o.classList.remove("cn-modal-bg-active")}toggleCookieModal(){document.body.classList.contains("cn-open")?this.closeCookieModal():this.openCookieModalToBannerPage()}openCookieModalToBannerPage(){this.openCookieModalToCookiePage(),this.toggleCookieModalPages()}openCookieModalToCookiePage(){document.body.classList.add("cn-open"),this.resetCookieModal(),this.getDomEl("bannerContent").classList.add("d-none"),this.getDomEl("modalContainer").classList.remove("d-none"),this.getDomEl("bannerContainer").classList.add("cn-modal-page"),this.getDomEl("modalContainer").scrollTop=0,this.setupCookieModalList(),this.setTabIndex()}closeCookieModal(){if(this.updateRestrictCloseModal(),this.restrictCloseModal)throw new Error("You need to accept or refuse all cookies");document.body.classList.remove("cn-open"),this.isOnBannerPage()||(this.getDomEl("bannerContent").classList.toggle("d-none"),this.getDomEl("modalContainer").classList.toggle("d-none"),this.getDomEl("bannerContainer").classList.remove("cn-modal-page")),this.unsetTabIndex(),this.setupCookieModalList()}setTabIndex(){document.documentElement.setAttribute("tabindex","-1"),setTimeout((()=>{const e='a[href], button, [role="button"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex="-1"])',t=this.getDomEl("cookieContainer");[...document.body.querySelectorAll(e)].filter((e=>!e.hasAttribute("disabled")&&!e.getAttribute("aria-hidden")&&!t.contains(e))).forEach((e=>{e.setAttribute("tabindex","-1"),e.classList.add("cn-disabled")})),[...t.querySelectorAll(e)].filter((e=>!(e.hasAttribute("disabled")||e.getAttribute("aria-hidden")||!(e.offsetWidth||e.offsetHeight||e.getClientRects().length)||t.contains(e)))).forEach((e=>{e.setAttribute("tabindex","0"),e.classList.remove("cn-disabled")})),this.getDomEl("cookieShowModalBtn").setAttribute("tabindex","-1")}),500)}unsetTabIndex(){document.documentElement.setAttribute("tabindex","0"),setTimeout((()=>{document.body.querySelectorAll(".cn-disabled").forEach((e=>{e.setAttribute("tabindex","0"),e.classList.remove("cn-disabled")})),this.getDomEl("cookieShowModalBtn").setAttribute("tabindex","0")}),500)}resetCookieModal(){const e=this.getDomEl("customizeBtn");if(this.getDomEl("bannerContent").classList.remove("d-none"),this.getDomEl("modalContainer").classList.add("d-none"),this.getDomEl("bannerContainer").classList.remove("cn-modal-page"),!e.dataset.openModal)throw new Error("Cannot find attribut data-open-modal");e.innerHTML=e.dataset.openModal}setupCookieModalList(){this.getDomEl("cookiesUnorderedList").innerHTML="",Object.entries(this.config).forEach((([t,o])=>{if(this.initDomCookieSwitch(t,o),!s.has(this.cookieName))return;let i=e.wait;try{i=this.getCnCookieStatus(t)}finally{this.setCookieSwitchButton(t,i)}}))}switchToModalPageOrClose(){this.isOnBannerPage()?this.toggleCookieModalPages():this.closeCookieModal()}toggleCookieModalPages(){this.getDomEl("bannerContent").classList.toggle("d-none"),this.getDomEl("modalContainer").classList.toggle("d-none"),this.getDomEl("bannerContainer").classList.toggle("cn-modal-page"),this.isOnBannerPage()||(this.getDomEl("bannerContainer").classList.add("cn-modal-page"),this.denyAllWaitingCookies()),this.setTabIndex(),this.setupCookieModalList(),this.toggleCustomizeBtn()}toggleCustomizeBtn(){const e=this.getDomEl("customizeBtn"),t=this.getDomEl("customizeBtn").dataset;this.getDomEl("modalContainer").scrollTop=0,this.getDomEl("bannerContent").classList.contains("d-none")?(e.innerHTML=t.openModal,e.title=t.openModal):(e.innerHTML=t.closeModal,e.title=t.closeModal)}isOnBannerPage(){return this.getDomEl("modalContainer").classList.contains("d-none")}setupEvents(){this.addEventPrevent(this.getDomEl("modalBg"),"click",this.closeCookieModal),this.addEventPrevent(this.getDomEl("cookieCloseModalBtn"),"click",this.closeCookieModal),this.addEventPrevent(this.getDomEl("acceptAllBtn"),"click",(()=>{this.acceptAllCookies(),this.closeCookieModal()})),this.addEventPrevent(this.getDomEl("denyAllBtn"),"click",(()=>{this.denyAllCookies(),this.closeCookieModal()})),this.addEventPrevent(this.getDomEl("customizeBtn"),"click",this.switchToModalPageOrClose),this.addEventPrevent(this.getDomEl("cookieShowModalBtn"),"click",this.toggleCookieModal),this.getDomEl("cookieLinkShowCustomizeModalList").forEach((e=>{this.addEventPrevent(e,"click",this.openCookieModalToCookiePage),this.addEventKbdValidate(e,this.openCookieModalToCookiePage)}))}getDomEl(e){return this.domElList[e]}initDomCookieSwitch(t,o){const i=document.createElement("li"),s=this.getDomEl("template").children.item(0);if(null===s)throw new Error("Cannot find child item");i.append(s.cloneNode(!0));const n=i.querySelector("span.cn-cookie-name"),a=i.querySelector("span.cn-cookie-description"),c=i.querySelector(".cn-cookie-link"),l=i.querySelector(".cn-switch"),r=i.querySelector(".cn-switch > input");r.indeterminate=!0,r.checked=!1,n.textContent=o.name,a.id=`${t}-desc`,a.textContent=o.description,c.textContent=o.labelLink,c.setAttribute("href",o.link),l.id=`${t}-switch`,l.name=t,l.dataset.name=t,l.setAttribute("aria-labelledby",`${t}-desc`),l.setAttribute("aria-describedby",`${t}-desc`);const d=t=>{let o=e.wait;try{o=this.getCnCookieStatus(t)}finally{this.setCnCookieStatus(t,this.invertCookieStatus(o)),this.refreshCnCookieExpirationDate()}};this.addEvent(r,"click",(()=>d(t))),this.addEventKbdValidate(l,(()=>r.click())),this.getDomEl("cookiesUnorderedList").append(i)}initDomElements(){const e=document.createElement("div");e.classList.add("cn-modal-bg"),document.body.append(e),this.domElList.modalBg=e,this.domElList.cookieLinkShowCustomizeModalList=document.querySelectorAll(".cn-cookie-link");Object.entries({"div#cn-wrapper":"cookieContainer","button#cn-cookie-btn":"cookieShowModalBtn","button#cn-close-modal":"cookieCloseModalBtn","div#cn-banner":"bannerContainer","div.cn-banner-content":"bannerContent","div.cn-modal-container":"modalContainer","button#cn-accept-banner":"acceptAllBtn","button#cn-deny-banner":"denyAllBtn","button#cn-settings-banner":"customizeBtn","ul#cn-modal-list":"cookiesUnorderedList","div#cn-li-template":"template"}).forEach((e=>{const t=e[0],o=e[1];let i=this.domElList[o];if(i=document.querySelector(t),!i)throw new Error(`Cannot find dom element ${t}`);this.domElList={...this.domElList,[o]:i}}));const t=this.domElList.template.cloneNode(!0);this.domElList.template.remove(),this.domElList.template=t}}}(); diff --git a/content/themes/ldc/package-lock.json b/content/themes/ldc/package-lock.json index 528f00f4..07ac5d1e 100644 --- a/content/themes/ldc/package-lock.json +++ b/content/themes/ldc/package-lock.json @@ -9,14 +9,14 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { - "@ldc-web/cookie-notice": "^6.0.1", + "@ldc-web/cookie-notice": "^6.0.3", "sass": "^1.77.4" } }, "node_modules/@ldc-web/cookie-notice": { - "version": "6.0.1", - "resolved": "https://lab.s-web.fr/api/v4/projects/50/packages/npm/@ldc-web/cookie-notice/-/@ldc-web/cookie-notice-6.0.1.tgz", - "integrity": "sha1-cpqBtzjutcgrzXCcyoAVsv9oBpo=", + "version": "6.0.3", + "resolved": "https://lab.s-web.fr/api/v4/projects/50/packages/npm/@ldc-web/cookie-notice/-/@ldc-web/cookie-notice-6.0.3.tgz", + "integrity": "sha1-mW2DD+8ipWkmvKhZ3m9h5wemAHI=", "dev": true }, "node_modules/anymatch": { diff --git a/content/themes/ldc/package.json b/content/themes/ldc/package.json index 677a4390..ccc570a5 100644 --- a/content/themes/ldc/package.json +++ b/content/themes/ldc/package.json @@ -11,7 +11,7 @@ "author": "", "license": "MIT", "devDependencies": { - "@ldc-web/cookie-notice": "^6.0.1", + "@ldc-web/cookie-notice": "^6.0.3", "sass": "^1.77.4" } }