Merge branch 'ldcweb-cookies' into 'main'
Ldcweb cookies Closes #1 See merge request ldc-web/projets/ldc-web-cookie-notice!2
This commit is contained in:
commit
3da375f47f
24 changed files with 5449 additions and 11089 deletions
13
.babelrc
Normal file
13
.babelrc
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"bugfixes": true,
|
||||
"useBuiltIns": "entry",
|
||||
"corejs": "3.22"
|
||||
}
|
||||
],
|
||||
"@babel/preset-typescript"
|
||||
]
|
||||
}
|
||||
|
|
@ -8,6 +8,9 @@ include:
|
|||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'security/npm.yml'
|
||||
- project: 'ldc-web/shared-ci'
|
||||
ref: 'main'
|
||||
file: 'build/npm.yml'
|
||||
|
||||
deploy:
|
||||
image: node:latest
|
||||
|
|
@ -23,4 +26,5 @@ deploy:
|
|||
stages:
|
||||
- lint
|
||||
- security
|
||||
- deploy
|
||||
- build
|
||||
- deploy
|
||||
|
|
|
|||
|
|
@ -18,15 +18,11 @@
|
|||
],
|
||||
"customSyntax": "postcss-scss",
|
||||
"rules": {
|
||||
"indentation": 4,
|
||||
"string-quotes": "double",
|
||||
"selector-max-id": null,
|
||||
"color-no-invalid-hex": true,
|
||||
"order/properties-alphabetical-order": null,
|
||||
"max-nesting-depth": 5,
|
||||
"selector-max-compound-selectors": 5,
|
||||
"declaration-colon-space-after": "always-single-line",
|
||||
"function-parentheses-space-inside": "never-single-line",
|
||||
"declaration-colon-newline-after": null,
|
||||
"scss/double-slash-comment-empty-line-before": [
|
||||
"always",
|
||||
|
|
|
|||
51
README.md
51
README.md
|
|
@ -1,4 +1,4 @@
|
|||
# LDC Web Cookie Notice
|
||||
# Web Cookie Notice
|
||||
|
||||
<div style="text-align: center;">
|
||||
|
||||
|
|
@ -9,24 +9,43 @@
|
|||
|
||||
</div>
|
||||
|
||||
## Contenu :
|
||||
- `ldcweb-cookie.blade.php` : structure du bandeau des cookies (le DOM) & script.
|
||||
- `ldcweb-cookies.scss` : stylisation des éléments du DOM.
|
||||
- `ldcweb-cookies.ts` : typescript du projet.
|
||||
- `ldcweb-cookies.php` : configuration des variables d'environnement.
|
||||
## Exemples :
|
||||
Voir dans la dossier `exemples`.
|
||||
Ici pour l'instant seulement un exemple pour **Laravel**.
|
||||
|
||||
## Étape 1 : implémentation
|
||||
|
||||
### Ajouter le package avec npm
|
||||
- https://docs.gitlab.com/ee/user/packages/npm_registry/
|
||||
- https://lab.s-web.fr/ldc-web/projets/laravel-base-project/-/snippets/8
|
||||
- `npm i @ldc-web/cookie-notice --save-dev`
|
||||
|
||||
### Laravel
|
||||
- Ajouter dans le projet, les fichiers au bon endroit :
|
||||
- `.blade.php` dans le dossier `./resources/view/front(/...)`
|
||||
- `.scss` dans le dossier `./resources/sass/utilities`
|
||||
- `.ts` dans le dossier `./resources/ts/utilities`
|
||||
- `.php` dans le dossier `./config`
|
||||
- Mettre à jour le fichier `webpack.mix.js` ou importer ces derniers dans les autres fichiers `.scss` ou `.ts` pour la compilation.
|
||||
- [`cn-cookies.blade.php`](./examples/cn-cookies.blade.php) dans le dossier `resources/view/vendor/`
|
||||
- [`standard.blade.php`](./examples/templates/standard.blade.php) dans le dossier `resources/view/vendor/cookie-notice-templates`
|
||||
- Inclure dans le layout general `@include('vendor.cn-cookies')`
|
||||
|
||||
- Ensuite inclure les éléments **style** et **script**
|
||||
- SCSS
|
||||
|
||||
@import "~@ldc-web/cookie-notice";
|
||||
// ou
|
||||
@import "~@ldc-web/cookie-notice/dist/css/cookie-notice-standard.css";
|
||||
// ou
|
||||
@import "~@ldc-web/cookie-notice/src/scss/themes/standard";
|
||||
- **TS/JS**
|
||||
|
||||
@import "@ldc-web/cookie-notice"
|
||||
import CookieNotice from "@ldc-web/cookie-notice";
|
||||
window.WebCookieNotice = CookieNotice;
|
||||
|
||||
### Wordpress
|
||||
**TODO: Add instructions for wordpress**
|
||||
|
||||
## Étape 2 : customisation
|
||||
- Ajouter et renseigner la variable d'environnement `ANALYTICS_GOOGLE_ID` dans le fichier `.env`.
|
||||
- Personnaliser le script des cookies dans le fichier `ldcweb-cookie.blade.php` (Analytics ? ReCaptcha ? Youtube ? Viméo ?), et ajouter les clés du site si nécessaire.
|
||||
- Personnaliser les fichiers `ldcweb-cookies.blade.php` et `ldcweb-cookies.scss` afin de respecter la charte graphique du projet.
|
||||
- Couleurs : Pour l'instant les variables **SASS** sont personalisables. Elle se trouvent ici [`node_modules/@ldc-web/cookie-notice/src/scss/variables.scss`](./src/scss/variables.scss)
|
||||
|
||||
## Étape 3 : finalisation
|
||||
- Ajouter un bouton `Gestion des cookies` dans le footer et lui attribuer la classe `ldcweb-cn-cookie-link`.
|
||||
- Si des vidéos sont présentes, attribuer aux `<div>` la classe `ldcweb-cn-youtube` pour Youtube, et/ou `ldcweb-cn-vimeo` pour Viméo.
|
||||
- Ajouter un bouton `Gestion des cookies` dans le footer et lui attribuer la classe `cn-cookie-link`.
|
||||
- Si des vidéos sont présentes, attribuer aux `<div>` la classe `cn-youtube` pour Youtube, et/ou `cn-vimeo` pour Viméo.
|
||||
|
|
|
|||
3
changelog.md
Normal file
3
changelog.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Changelog
|
||||
|
||||
## 3.0.2 Initial release as UMD + ESM
|
||||
1
dist/css/cookie-notice-standard.css
vendored
1
dist/css/cookie-notice-standard.css
vendored
|
|
@ -1 +0,0 @@
|
|||
:root{--cs-primary-color:var()}#cn-wrapper *{box-sizing:border-box}#cn-wrapper :before{display:none}#cn-wrapper button{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:#b9b9b9;border:0;color:#000;cursor:pointer;display:inline-block;font-family:Barlow,sans-serif;font-size:1rem;line-height:1;margin:0;padding:.2rem .5rem;text-align:center;text-decoration:none;transition:background .25s ease-in-out,transform .15s ease}#cn-wrapper button:focus,#cn-wrapper button:hover{background:#a0a0a0;color:#000}#cn-wrapper button:focus{outline:1px solid;outline-color:#000;outline-offset:-4px}#cn-wrapper button:active{transform:scale(.99)}#cn-wrapper .cn-nav #cn-accept-banner,#cn-wrapper .cn-nav #cn-deny-banner,#cn-wrapper .cn-nav #cn-settings-banner{align-items:center;display:flex;flex-direction:column;font-family:Barlow,sans-serif;font-size:1rem;height:3rem;justify-content:center;padding:0}#cn-wrapper{z-index:1050}#cn-wrapper #cn-cookie-btn{background-color:#fff;border-radius:100%;bottom:1rem;box-shadow:0 .1rem 1rem rgba(0,0,0,.35);cursor:pointer;height:50px;left:1rem;padding:8px;position:fixed;right:auto;width:50px}#cn-wrapper #cn-cookie-btn-icon circle,#cn-wrapper #cn-cookie-btn-icon path{fill:#dc9c52}#cn-wrapper #cn-banner{align-items:center;background-color:#fff;border-radius:0;bottom:0;box-shadow:0 .1rem 1rem rgba(0,0,0,.35);display:flex;flex-direction:column;height:100vh;justify-content:flex-end;left:0;line-height:normal;margin:0;max-height:100vh;opacity:0;padding:0;pointer-events:none;position:fixed;top:0;transition:.3s;-webkit-user-select:none;-moz-user-select:none;user-select:none;visibility:hidden;width:100vw;z-index:1050}#cn-wrapper #cn-banner>*{pointer-events:all}@media (min-width:535px){#cn-wrapper #cn-banner{border-radius:.5rem;bottom:calc(1rem + 60px);height:auto;left:0;margin-top:1rem;max-height:80vh;right:auto;width:30rem}}#cn-wrapper #cn-li-template{display:none}#cn-wrapper .cn-content{flex-grow:1;overflow-y:auto;padding:0 .8rem}#cn-wrapper .cn-content .cn-banner-content{color:#b9b9b9;display:flex;flex-direction:column;font-family:Barlow,sans-serif;font-size:14px}#cn-wrapper .cn-content .cn-banner-content .cn-banner-img{text-align:center}#cn-wrapper .cn-content .cn-banner-content .cn-banner-text{flex:2}#cn-wrapper .cn-content .cn-banner-content .cn-banner-text .cn-banner-title{color:#dc9c52;font-family:Satisfy,sans-serif;font-size:25px;font-weight:700;line-height:inherit;text-align:left}#cn-wrapper .cn-content .cn-banner-content .cn-banner-text .cn-banner-para-p{margin:6px 0;text-align:justify}#cn-wrapper .cn-content .cn-banner-content .cn-banner-details{align-items:flex-start;display:flex;flex-direction:row;height:0;justify-content:center;overflow:hidden;text-align:justify;transition:.3s}#cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details{margin:1rem 0;width:100%}#cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p{background-color:inherit;color:#dc9c52;cursor:pointer;display:inline-block;font-size:14px;margin:0 auto;text-align:center;width:100%}#cn-wrapper .cn-nav{align-items:center;border-bottom-left-radius:.5rem;border-bottom-right-radius:.5rem;border-top:1px solid grey;display:flex;flex-shrink:0;height:3rem;overflow:hidden;width:100%}#cn-wrapper .cn-nav #cn-deny-banner{width:50%}#cn-wrapper .cn-nav #cn-accept-banner{border-left:1px solid grey;border-right:1px solid grey;width:50%}#cn-wrapper .cn-nav #cn-settings-banner{border-top:1px solid grey;width:100%}@media (min-width:535px){#cn-wrapper .cn-nav{flex-wrap:inherit}#cn-wrapper .cn-nav #cn-accept-banner,#cn-wrapper .cn-nav #cn-deny-banner{width:33.33%}#cn-wrapper .cn-nav #cn-settings-banner{border-top:inherit;width:33.33%}#cn-wrapper{height:100%;width:100%}}.cn-open{overflow:hidden!important}.cn-open #cn-wrapper #cn-banner{opacity:1;visibility:visible}@media (min-width:535px){.cn-open #cn-wrapper #cn-banner{left:1rem;right:auto}}#ldcweb-cn.open-banner,#ldcweb-cn.open-banner .ldcweb-cn-banner,#ldcweb-cn.open-modal{display:flex}#ldcweb-cn a,#ldcweb-cn p{color:#b9b9b9;font-family:Barlow,sans-serif;font-size:14px}#ldcweb-cn a{text-decoration:underline;transition:0s}#ldcweb-cn a:hover{color:#dc9c52}
|
||||
594
dist/esm/index.js
vendored
Normal file
594
dist/esm/index.js
vendored
Normal file
|
|
@ -0,0 +1,594 @@
|
|||
export default class CookieNotice {
|
||||
constructor(config) {
|
||||
this.browserCookieName = "cn-init";
|
||||
this.cookiePolicies = {
|
||||
sameSite: CookiePolicySameSite.lax,
|
||||
secure: "",
|
||||
};
|
||||
// * Setup Config
|
||||
this.config = config;
|
||||
// * Inject DOM modal BG
|
||||
const modalBg = document.createElement("div");
|
||||
modalBg.classList.add("cn-modal-bg");
|
||||
document.body.append(modalBg);
|
||||
this.modalBg = modalBg;
|
||||
// * Setup Dom Elements
|
||||
const cookieContainer = document.querySelector("div#cn-wrapper"), cookieShowModalBtn = document.querySelector("button#cn-cookie-btn"), cookieCloseModalBtn = document.querySelector("button#cn-close-modal"), cookieLinkShowCustomizeModalPageList = document.querySelectorAll("a.cn-cookie-link"), bannerContainer = document.querySelector("div#cn-banner"), bannerContent = document.querySelector("div.cn-banner-content"), bannerDetails = document.querySelector("div.cn-banner-details"), bannerParaP = document.querySelector("div.cn-banner-para-p"), detailsTextOpen = document.querySelector("p.cn-banner-para-p-open"), detailsTextClose = document.querySelector("p.cn-banner-para-p-close"), bannerDetailsCollapseBtn = document.querySelector("button.cn-banner-btn-details-p"), bannerDetailsContainer = document.querySelector("div.cn-banner-btn-details"), modalContainer = document.querySelector("div.cn-modal-container"), acceptAllBtn = document.querySelector("button#cn-accept-banner"), denyAllBtn = document.querySelector("button#cn-deny-banner"), customizeBtn = document.querySelector("button#cn-settings-banner"), cookiesUnorderedList = document.querySelector("ul#cn-modal-list"), modalWrapper = document.querySelector("div.cn-modal-wrapper"), template = document.querySelector("div#cn-li-template");
|
||||
if (!cookieContainer) {
|
||||
throw new Error("Cannot find div#cn-wrapper");
|
||||
}
|
||||
if (!cookieShowModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-cookie-btn' element");
|
||||
}
|
||||
if (!cookieCloseModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-close-modal' element");
|
||||
}
|
||||
if (!bannerContainer) {
|
||||
throw new Error("Cannot find 'div#cn-banner' element");
|
||||
}
|
||||
if (!bannerContent) {
|
||||
throw new Error("Cannot find 'div.cn-banner-content' element");
|
||||
}
|
||||
if (!bannerDetails) {
|
||||
throw new Error("Cannot find 'div.cn-banner-details' element");
|
||||
}
|
||||
if (!bannerParaP) {
|
||||
throw new Error("Cannot find 'div.cn-banner-para-p' element");
|
||||
}
|
||||
if (!detailsTextOpen) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-open' element");
|
||||
}
|
||||
if (!detailsTextClose) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-close' element");
|
||||
}
|
||||
if (!bannerDetailsCollapseBtn) {
|
||||
throw new Error("Cannot find 'button.cn-banner-btn-details-p' element");
|
||||
}
|
||||
if (!bannerDetailsContainer) {
|
||||
throw new Error("Cannot find '.cn-banner-btn-details' element");
|
||||
}
|
||||
if (!modalContainer) {
|
||||
throw new Error("Cannot find 'div.cn-modal-container' element");
|
||||
}
|
||||
if (!acceptAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-accept-banner' element");
|
||||
}
|
||||
if (!denyAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-deny-banner' element");
|
||||
}
|
||||
if (!customizeBtn) {
|
||||
throw new Error("Cannot find 'button.cn-settings-banner' element");
|
||||
}
|
||||
if (!cookiesUnorderedList) {
|
||||
throw new Error("Cannot find 'ul#cn-modal-list' element");
|
||||
}
|
||||
if (!modalWrapper) {
|
||||
throw new Error("Cannot find 'div.cn-modal-wrapper' element");
|
||||
}
|
||||
if (!template) {
|
||||
throw new Error("Cannot find 'div#cn-li-template' element");
|
||||
}
|
||||
this.cookieShowModalBtn = cookieShowModalBtn;
|
||||
this.cookieCloseModalBtn = cookieCloseModalBtn;
|
||||
this.cookieLinkShowCustomizeModalList =
|
||||
cookieLinkShowCustomizeModalPageList;
|
||||
this.cookieContainer = cookieContainer;
|
||||
this.bannerDetailsContainer = bannerDetailsContainer;
|
||||
this.bannerContainer = bannerContainer;
|
||||
this.bannerContent = bannerContent;
|
||||
this.cookiesUnorderedList = cookiesUnorderedList;
|
||||
this.modalWrapper = modalWrapper;
|
||||
this.bannerParaP = bannerParaP;
|
||||
this.detailsTextOpen = detailsTextOpen;
|
||||
this.detailsTextClose = detailsTextClose;
|
||||
this.bannerDetails = bannerDetails;
|
||||
this.bannerDetailsCollapseBtn = bannerDetailsCollapseBtn;
|
||||
this.modalContainer = modalContainer;
|
||||
this.acceptAllBtn = acceptAllBtn;
|
||||
this.denyAllBtn = denyAllBtn;
|
||||
this.customizeBtn = customizeBtn;
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
this.template = template;
|
||||
const memoryTemplate = this.template.cloneNode(true);
|
||||
this.template.remove();
|
||||
this.template = memoryTemplate;
|
||||
// * Setup Events
|
||||
this.addEventPrevent(this.modalBg, "click", this.closeCookieModal);
|
||||
this.addEventPrevent(this.cookieCloseModalBtn, "click", this.closeCookieModal);
|
||||
this.addEventPrevent(this.acceptAllBtn, "click", this.acceptAllCookies);
|
||||
this.addEventPrevent(this.denyAllBtn, "click", this.denyAllCookies);
|
||||
this.addEventPrevent(this.customizeBtn, "click", this.toggleCookieModalPages);
|
||||
this.addEventPrevent(this.bannerDetailsCollapseBtn, "click", this.toggleBannerDetails);
|
||||
this.addEventPrevent(this.cookieShowModalBtn, "click", this.toggleCookieModal);
|
||||
this.cookieLinkShowCustomizeModalList.forEach((cookieLink) => {
|
||||
this.addEventPrevent(cookieLink, "click", this.openCookieModalToCookiePage);
|
||||
});
|
||||
// * Setup CN Cookie
|
||||
if (!this.cookiesMatchesConfig()) {
|
||||
// * Setup Browser Cookie if none.
|
||||
this.resetBrowserCookie();
|
||||
this.openCookieModalToBannerPage();
|
||||
}
|
||||
// * Cookie should have been created from here.
|
||||
const cookies = this.getCookieStatusList();
|
||||
Object.entries(cookies).forEach(([cookieName, cookieStatus]) => {
|
||||
if (cookieStatus === CookieStatus.wait) {
|
||||
// * Open modal if any cookie config is not set.
|
||||
this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
if (!this.config[cookieName]) {
|
||||
// * Ignore missing config
|
||||
return;
|
||||
}
|
||||
if (cookieStatus === CookieStatus.true) {
|
||||
// * Exec script part for accepted cookie.
|
||||
this.config[cookieName].script();
|
||||
return;
|
||||
}
|
||||
if (this.config[cookieName].fallback != null) {
|
||||
// * Exec fallback part for accepted cookie if provided.
|
||||
this.config[cookieName].fallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
// COOKIES
|
||||
/**
|
||||
* Check if the actual cookie matches the config
|
||||
*/
|
||||
cookiesMatchesConfig() {
|
||||
const cookies = this.getCookieStatusList();
|
||||
return Object.keys(cookies).length === Object.keys(this.config).length;
|
||||
}
|
||||
/**
|
||||
* Accept a specific cookie
|
||||
*/
|
||||
acceptAllCookies() {
|
||||
Object.entries(this.config).forEach(([cookieName, cookieOption]) => this.setCookieStatus(cookieName, CookieStatus.true, cookieOption));
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(".accept > label")) {
|
||||
acceptLabel.classList.add("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(".deny > label")) {
|
||||
denyLabel.classList.remove("active");
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Deny a specific cookie
|
||||
*/
|
||||
denyAllCookies() {
|
||||
Object.entries(this.config).forEach(([cookieName, cookieOption]) => this.setCookieStatus(cookieName, CookieStatus.false, cookieOption));
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(".accept > label")) {
|
||||
acceptLabel.classList.remove("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(".deny > label")) {
|
||||
denyLabel.classList.add("active");
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Fetch the cookie status list
|
||||
*
|
||||
* @returns the cookie status list
|
||||
*/
|
||||
getCookieStatusList() {
|
||||
const cookies = this.getBrowserCookieValue(), statusList = {};
|
||||
if (cookies === undefined) {
|
||||
return statusList;
|
||||
}
|
||||
/** specificCookieString contains youtube=true like */
|
||||
cookies.split(",").forEach((specificCookieString) => {
|
||||
const values = specificCookieString.split("=");
|
||||
statusList[values[0]] = values[1];
|
||||
});
|
||||
return statusList;
|
||||
}
|
||||
/**
|
||||
* Check has cookie status
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
containsCookieStatus(key) {
|
||||
const statusList = this.getCookieStatusList();
|
||||
return (Object.keys(statusList).find((cookieName) => cookieName === key) !==
|
||||
undefined);
|
||||
}
|
||||
/**
|
||||
* Set the cookie value
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
* @param cookieOption
|
||||
*/
|
||||
setCookieStatus(cookieName, status, cookieOption) {
|
||||
if (status === CookieStatus.true) {
|
||||
this.addCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
if (status === CookieStatus.false) {
|
||||
this.removeCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.wait);
|
||||
}
|
||||
/**
|
||||
* Add a specific cookie and
|
||||
* change his status to true
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
addCookieStatus(cookieName, cookieOption) {
|
||||
if (cookieOption.script) {
|
||||
cookieOption.script();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.true);
|
||||
}
|
||||
/**
|
||||
* Remove a specific cookie and
|
||||
* change his status to false
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
removeCookieStatus(cookieName, cookieOption) {
|
||||
const cookieNameElement = document.getElementById(cookieName);
|
||||
if (cookieNameElement) {
|
||||
cookieNameElement.remove();
|
||||
}
|
||||
if (cookieOption.fallback) {
|
||||
cookieOption.fallback();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.false);
|
||||
}
|
||||
/**
|
||||
* Change the status of a cookie
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
*/
|
||||
setBrowserCookieStatus(cookieName, status) {
|
||||
const statusList = this.getCookieStatusList();
|
||||
// * Force refresh
|
||||
this.deleteBrowserCookie();
|
||||
statusList[cookieName] = status;
|
||||
this.saveBrowserCookie(statusList);
|
||||
}
|
||||
/**
|
||||
* Has CN cokie setup ?
|
||||
* @returns true if the cookie is setup
|
||||
*/
|
||||
hasBrowserCookie() {
|
||||
return Boolean(this.getBrowserCookieValue());
|
||||
}
|
||||
/**
|
||||
* Get the Ldcweb cookie
|
||||
*
|
||||
* @returns A string like analytics=true,youtube=true or undefined
|
||||
*/
|
||||
getBrowserCookieValue() {
|
||||
const matches = document.cookie.match(new RegExp("(?:^|; )" +
|
||||
this.browserCookieName.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") +
|
||||
"=([^;]*)"));
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
/**
|
||||
* Save cookie content on web browser
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
saveBrowserCookie(statusList) {
|
||||
const date = new Date(), newDate = new Date(date.setMonth(date.getMonth() + 13)), content = Object.entries(statusList)
|
||||
.map(([cookieName, cookieStatus]) => {
|
||||
return `${cookieName}=${cookieStatus}`;
|
||||
})
|
||||
.join(",");
|
||||
document.cookie = `${this.browserCookieName}=${content};path=/${location.hostname ? `;domain=${location.hostname}` : ""};expires=${newDate.toUTCString()};${this.getCookiePoliciesAsString()}`;
|
||||
}
|
||||
/**
|
||||
* Set an older expire parameter to a specific cookie
|
||||
*/
|
||||
deleteBrowserCookie() {
|
||||
if (this.hasBrowserCookie()) {
|
||||
// * Suppression du cookie et de sa version precedé d'un point
|
||||
document.cookie = `${this.browserCookieName}=;path=/${location.hostname ? `;domain=.${location.hostname}` : ""};expires=Thu, 01 Jan 1970 00:00:01 GMT;${this.getCookiePoliciesAsString()}`;
|
||||
document.cookie = `${this.browserCookieName}=;path=/${location.hostname ? `;domain=${location.hostname}` : ""};expires=Thu, 01 Jan 1970 00:00:01 GMT;${this.getCookiePoliciesAsString()}`;
|
||||
}
|
||||
}
|
||||
getCookiePoliciesAsString() {
|
||||
return Object.entries(this.cookiePolicies)
|
||||
.map(([policyName, policyValue]) => `${policyName}=${policyValue}`)
|
||||
.join(";");
|
||||
}
|
||||
/**
|
||||
* Reset Ldc Web CN cookie
|
||||
*/
|
||||
resetBrowserCookie() {
|
||||
// * Create Cookie as It does not exists.
|
||||
const newCookieList = {};
|
||||
Object.entries(this.config).forEach(([cookieName]) => (newCookieList[cookieName] = CookieStatus.wait));
|
||||
this.saveBrowserCookie(newCookieList);
|
||||
}
|
||||
// LISTENERS
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEvent(element, evnt, funct) {
|
||||
return element.addEventListener(evnt, funct.bind(this), false);
|
||||
}
|
||||
/**
|
||||
* Add event on a specific element and prevent default
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventPrevent(element, evnt, funct) {
|
||||
return element.addEventListener(evnt, (e) => {
|
||||
e.preventDefault();
|
||||
funct.call(this, e);
|
||||
}, false);
|
||||
}
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventKbdValidate(element, funct) {
|
||||
return this.addEvent(element, "keyup", (e) => {
|
||||
const kbdEvt = e;
|
||||
if (kbdEvt.key == " " ||
|
||||
kbdEvt.code == "Space" ||
|
||||
kbdEvt.keyCode == 32 ||
|
||||
kbdEvt.key == "Enter" ||
|
||||
kbdEvt.code == "Enter" ||
|
||||
kbdEvt.keyCode == 13) {
|
||||
funct.call(this, kbdEvt);
|
||||
}
|
||||
});
|
||||
}
|
||||
// COOKIE MODAL
|
||||
/**
|
||||
* Show or hide Cookie modal
|
||||
* @returns
|
||||
*/
|
||||
toggleCookieModal() {
|
||||
if (!document.body.classList.contains("cn-open")) {
|
||||
this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Open the cookies modal to the banner page
|
||||
*/
|
||||
openCookieModalToBannerPage() {
|
||||
this.openCookieModalToCookiePage();
|
||||
this.toggleCookieModalPages();
|
||||
}
|
||||
/**
|
||||
* Open the cookies modal to the cookies page
|
||||
*/
|
||||
openCookieModalToCookiePage() {
|
||||
document.body.classList.add("cn-open");
|
||||
this.resetCookieModal();
|
||||
this.bannerContent.classList.add("d-none");
|
||||
this.bannerDetails.classList.add("d-none");
|
||||
this.bannerDetailsContainer.classList.add("d-none");
|
||||
this.modalContainer.classList.remove("d-none");
|
||||
// Scroll to the top of the cookies list
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
this.setupCookieModalList();
|
||||
this.setTabIndex();
|
||||
}
|
||||
/**
|
||||
* Hide the cookies modal
|
||||
*/
|
||||
closeCookieModal() {
|
||||
document.body.classList.remove("cn-open");
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.unsetTabIndex();
|
||||
this.setupCookieModalList();
|
||||
}
|
||||
/**
|
||||
* Setup tab indexes on visible elements
|
||||
*/
|
||||
setTabIndex() {
|
||||
// * Prevent focus html tag
|
||||
document.documentElement.setAttribute("tabindex", "-1");
|
||||
setTimeout(() => {
|
||||
const focusableSelector = "a[href], button, [role=\"button\"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])";
|
||||
// * Only focusable elements
|
||||
[...document.body.querySelectorAll(focusableSelector)]
|
||||
.filter((el) => !el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden"))
|
||||
.forEach((el) => {
|
||||
el.setAttribute("tabindex", "-1");
|
||||
el.classList.add("cn-disabled");
|
||||
});
|
||||
[...this.cookieContainer.querySelectorAll(focusableSelector)]
|
||||
.filter((el) => !el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden") &&
|
||||
// * Only visible elements
|
||||
!!(el.offsetWidth ||
|
||||
el.offsetHeight ||
|
||||
el.getClientRects().length))
|
||||
.forEach((el) => {
|
||||
el.setAttribute("tabindex", "0");
|
||||
el.classList.remove("cn-disabled");
|
||||
});
|
||||
this.cookieShowModalBtn.setAttribute("tabindex", "-1");
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
* Undo setup tab indexes on visible elements
|
||||
*/
|
||||
unsetTabIndex() {
|
||||
document.documentElement.setAttribute("tabindex", "0");
|
||||
setTimeout(() => {
|
||||
document.body.querySelectorAll(".cn-disabled").forEach((el) => {
|
||||
el.setAttribute("tabindex", "0");
|
||||
el.classList.remove("cn-disabled");
|
||||
});
|
||||
this.cookieShowModalBtn.setAttribute("tabindex", "0");
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
* Reset the modal view state
|
||||
*/
|
||||
resetCookieModal() {
|
||||
this.bannerContent.classList.remove("d-none");
|
||||
this.bannerDetails.classList.remove("d-none");
|
||||
this.bannerDetailsContainer.classList.remove("d-none");
|
||||
this.modalContainer.classList.add("d-none");
|
||||
if (!this.customizeBtn.dataset.openModal) {
|
||||
throw new Error("Cannot find attribut data-open-modal");
|
||||
}
|
||||
this.customizeBtn.innerHTML = this.customizeBtn.dataset.openModal;
|
||||
}
|
||||
/**
|
||||
* Set the cookies list in the modal
|
||||
*/
|
||||
setupCookieModalList() {
|
||||
this.cookiesUnorderedList.innerHTML = "";
|
||||
Object.entries(this.config).forEach(([cookieName, cookieConfig]) => {
|
||||
const cookie = document.createElement("li");
|
||||
const childItem = this.template.children.item(0);
|
||||
if (childItem === null) {
|
||||
throw new Error("Cannot find child item");
|
||||
}
|
||||
cookie.append(childItem.cloneNode(true));
|
||||
const name = cookie.querySelector("span.cn-cookie-name");
|
||||
const description = cookie.querySelector("span.cn-cookie-description");
|
||||
const link = cookie.querySelector(".cn-cookie-link");
|
||||
const acceptInput = cookie.querySelector(".accept > input");
|
||||
const denyInput = cookie.querySelector(".deny > input");
|
||||
const acceptLabel = cookie.querySelector(".accept > label");
|
||||
const denyLabel = cookie.querySelector(".deny > label");
|
||||
name.textContent = cookieConfig.name;
|
||||
description.textContent = cookieConfig.description;
|
||||
link.textContent = cookieConfig.labelLink;
|
||||
link.setAttribute("href", cookieConfig.link);
|
||||
acceptInput.id = cookieName + "1";
|
||||
acceptInput.name = cookieName;
|
||||
acceptInput.dataset.name = cookieName;
|
||||
acceptLabel.htmlFor = cookieName + "1";
|
||||
denyInput.id = cookieName + "2";
|
||||
denyInput.name = cookieName;
|
||||
denyInput.dataset.name = cookieName;
|
||||
denyLabel.htmlFor = cookieName + "2";
|
||||
const acceptFn = () => {
|
||||
acceptLabel.classList.add("active");
|
||||
denyLabel.classList.remove("active");
|
||||
this.setCookieStatus(cookieName, CookieStatus.true, cookieConfig);
|
||||
}, denyFn = () => {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.add("active");
|
||||
this.setCookieStatus(cookieName, CookieStatus.false, cookieConfig);
|
||||
};
|
||||
this.addEvent(acceptInput, "click", acceptFn);
|
||||
this.addEventKbdValidate(acceptLabel, acceptFn);
|
||||
this.addEvent(denyInput, "click", denyFn);
|
||||
this.addEventKbdValidate(denyLabel, denyFn);
|
||||
this.cookiesUnorderedList.append(cookie);
|
||||
if (!this.hasBrowserCookie()) {
|
||||
// * Ldcweb cookie is not set.
|
||||
return;
|
||||
}
|
||||
// * Setup list status state
|
||||
Object.entries(this.getCookieStatusList()).forEach(([ckName, cookieStatus]) => {
|
||||
if (ckName === cookieName) {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.remove("active");
|
||||
switch (cookieStatus) {
|
||||
case CookieStatus.true:
|
||||
acceptLabel.classList.add("active");
|
||||
break;
|
||||
case CookieStatus.false:
|
||||
denyLabel.classList.add("active");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Toggle show hide banner details
|
||||
*/
|
||||
toggleBannerDetails() {
|
||||
this.bannerDetails.classList.toggle("cn-details-open");
|
||||
if (!this.bannerDetailsCollapseBtn.dataset.open ||
|
||||
!this.bannerDetailsCollapseBtn.dataset.close) {
|
||||
throw new Error("Cannot find attribute data-open or data-close");
|
||||
}
|
||||
if (this.bannerDetailsAreExpanded) {
|
||||
this.bannerDetailsCollapseBtn.innerHTML =
|
||||
this.bannerDetailsCollapseBtn.dataset.close;
|
||||
this.detailsTextOpen.classList.add("d-none");
|
||||
this.detailsTextClose.classList.remove("d-none");
|
||||
this.bannerDetails.style.height = "0px";
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
}
|
||||
else {
|
||||
this.bannerDetailsCollapseBtn.innerHTML =
|
||||
this.bannerDetailsCollapseBtn.dataset.open;
|
||||
this.detailsTextOpen.classList.remove("d-none");
|
||||
this.detailsTextClose.classList.add("d-none");
|
||||
this.bannerDetails.style.height =
|
||||
this.bannerDetails.children[0].clientHeight + "px";
|
||||
this.bannerDetailsAreExpanded = true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Toggle Cookie modal pages
|
||||
*/
|
||||
toggleCookieModalPages() {
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.setTabIndex();
|
||||
this.setupCookieModalList();
|
||||
this.togglePersonalizeBtn();
|
||||
}
|
||||
/**
|
||||
* Toggle customize btn
|
||||
*/
|
||||
togglePersonalizeBtn() {
|
||||
const customizeBtnBannerDataset = this.customizeBtn.dataset;
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
if (this.bannerContent.classList.contains("d-none")) {
|
||||
this.customizeBtn.innerHTML =
|
||||
customizeBtnBannerDataset.openModal;
|
||||
}
|
||||
else {
|
||||
this.customizeBtn.innerHTML =
|
||||
customizeBtnBannerDataset.closeModal;
|
||||
}
|
||||
}
|
||||
}
|
||||
var CookieStatus;
|
||||
(function (CookieStatus) {
|
||||
CookieStatus["true"] = "true";
|
||||
CookieStatus["false"] = "false";
|
||||
CookieStatus["wait"] = "wait";
|
||||
})(CookieStatus || (CookieStatus = {}));
|
||||
var CookiePolicySameSite;
|
||||
(function (CookiePolicySameSite) {
|
||||
CookiePolicySameSite["lax"] = "lax";
|
||||
CookiePolicySameSite["strict"] = "strict";
|
||||
CookiePolicySameSite["none"] = "none";
|
||||
})(CookiePolicySameSite || (CookiePolicySameSite = {}));
|
||||
1
dist/js/cookie-notice.js
vendored
1
dist/js/cookie-notice.js
vendored
File diff suppressed because one or more lines are too long
219
dist/typings/index.d.ts
vendored
Normal file
219
dist/typings/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
export default class CookieNotice {
|
||||
browserCookieName: string;
|
||||
cookiePolicies: CookiePolicy;
|
||||
config: Record<string, CookieOptions>;
|
||||
modalBg: HTMLDivElement;
|
||||
cookieContainer: HTMLDivElement;
|
||||
bannerContainer: HTMLDivElement;
|
||||
modalContainer: HTMLDivElement;
|
||||
cookieShowModalBtn: HTMLButtonElement;
|
||||
cookieCloseModalBtn: HTMLButtonElement;
|
||||
bannerDetailsCollapseBtn: HTMLButtonElement;
|
||||
bannerParaP: HTMLDivElement;
|
||||
detailsTextOpen: HTMLParagraphElement;
|
||||
detailsTextClose: HTMLParagraphElement;
|
||||
bannerContent: HTMLDivElement;
|
||||
bannerDetails: HTMLDivElement;
|
||||
bannerDetailsContainer: HTMLDivElement;
|
||||
acceptAllBtn: HTMLButtonElement;
|
||||
denyAllBtn: HTMLButtonElement;
|
||||
customizeBtn: HTMLButtonElement;
|
||||
cookiesUnorderedList: HTMLUListElement;
|
||||
cookieLinkShowCustomizeModalList: NodeListOf<HTMLAnchorElement>;
|
||||
modalWrapper: HTMLDivElement;
|
||||
template: HTMLDivElement;
|
||||
bannerDetailsAreExpanded: boolean;
|
||||
constructor(config: Record<string, CookieOptions>);
|
||||
/**
|
||||
* Check if the actual cookie matches the config
|
||||
*/
|
||||
cookiesMatchesConfig(): boolean;
|
||||
/**
|
||||
* Accept a specific cookie
|
||||
*/
|
||||
acceptAllCookies(): void;
|
||||
/**
|
||||
* Deny a specific cookie
|
||||
*/
|
||||
denyAllCookies(): void;
|
||||
/**
|
||||
* Fetch the cookie status list
|
||||
*
|
||||
* @returns the cookie status list
|
||||
*/
|
||||
getCookieStatusList(): CookieStatusList;
|
||||
/**
|
||||
* Check has cookie status
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
containsCookieStatus(key: string): boolean;
|
||||
/**
|
||||
* Set the cookie value
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
* @param cookieOption
|
||||
*/
|
||||
setCookieStatus(cookieName: string, status: CookieStatus, cookieOption: CookieOptions): void;
|
||||
/**
|
||||
* Add a specific cookie and
|
||||
* change his status to true
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
addCookieStatus(cookieName: string, cookieOption: CookieOptions): void;
|
||||
/**
|
||||
* Remove a specific cookie and
|
||||
* change his status to false
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
removeCookieStatus(cookieName: string, cookieOption: CookieOptions): void;
|
||||
/**
|
||||
* Change the status of a cookie
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
*/
|
||||
setBrowserCookieStatus(cookieName: string, status: CookieStatus): void;
|
||||
/**
|
||||
* Has CN cokie setup ?
|
||||
* @returns true if the cookie is setup
|
||||
*/
|
||||
hasBrowserCookie(): boolean;
|
||||
/**
|
||||
* Get the Ldcweb cookie
|
||||
*
|
||||
* @returns A string like analytics=true,youtube=true or undefined
|
||||
*/
|
||||
getBrowserCookieValue(): string | undefined;
|
||||
/**
|
||||
* Save cookie content on web browser
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
saveBrowserCookie(statusList: CookieStatusList): void;
|
||||
/**
|
||||
* Set an older expire parameter to a specific cookie
|
||||
*/
|
||||
deleteBrowserCookie(): void;
|
||||
getCookiePoliciesAsString(): string;
|
||||
/**
|
||||
* Reset Ldc Web CN cookie
|
||||
*/
|
||||
resetBrowserCookie(): void;
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEvent(element: HTMLElement, evnt: string, funct: (e: Event) => void): void;
|
||||
/**
|
||||
* Add event on a specific element and prevent default
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventPrevent(element: HTMLElement, evnt: string, funct: (e: Event) => void): void;
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventKbdValidate(element: HTMLElement, funct: (e: Event) => void): void;
|
||||
/**
|
||||
* Show or hide Cookie modal
|
||||
* @returns
|
||||
*/
|
||||
toggleCookieModal(): void;
|
||||
/**
|
||||
* Open the cookies modal to the banner page
|
||||
*/
|
||||
openCookieModalToBannerPage(): void;
|
||||
/**
|
||||
* Open the cookies modal to the cookies page
|
||||
*/
|
||||
openCookieModalToCookiePage(): void;
|
||||
/**
|
||||
* Hide the cookies modal
|
||||
*/
|
||||
closeCookieModal(): void;
|
||||
/**
|
||||
* Setup tab indexes on visible elements
|
||||
*/
|
||||
setTabIndex(): void;
|
||||
/**
|
||||
* Undo setup tab indexes on visible elements
|
||||
*/
|
||||
unsetTabIndex(): void;
|
||||
/**
|
||||
* Reset the modal view state
|
||||
*/
|
||||
resetCookieModal(): void;
|
||||
/**
|
||||
* Set the cookies list in the modal
|
||||
*/
|
||||
setupCookieModalList(): void;
|
||||
/**
|
||||
* Toggle show hide banner details
|
||||
*/
|
||||
toggleBannerDetails(): void;
|
||||
/**
|
||||
* Toggle Cookie modal pages
|
||||
*/
|
||||
toggleCookieModalPages(): void;
|
||||
/**
|
||||
* Toggle customize btn
|
||||
*/
|
||||
togglePersonalizeBtn(): void;
|
||||
}
|
||||
declare enum CookieStatus {
|
||||
true = "true",
|
||||
false = "false",
|
||||
wait = "wait"
|
||||
}
|
||||
type CookieStatusList = Record<string, keyof typeof CookieStatus>;
|
||||
type CookiePolicy = {
|
||||
sameSite: CookiePolicySameSite;
|
||||
secure: string;
|
||||
};
|
||||
declare enum CookiePolicySameSite {
|
||||
lax = "lax",
|
||||
strict = "strict",
|
||||
none = "none"
|
||||
}
|
||||
export type CookieOptions = {
|
||||
name: string;
|
||||
description: string;
|
||||
link: string;
|
||||
labelLink: string;
|
||||
cookies: string[];
|
||||
/**
|
||||
* Fonction qui sert à initialiser la fonctionnalité
|
||||
* conduisant à la génération du cookie
|
||||
* @return void
|
||||
*/
|
||||
script: () => void;
|
||||
/**
|
||||
* Fonction qui sert à informer l'utilisateur
|
||||
* sur chaque élèment que le cookie
|
||||
* associé à la fonctionnalité
|
||||
* est désactivé et propose un lien sur
|
||||
* cookie notice pour l'activer
|
||||
* @return void
|
||||
*/
|
||||
fallback: () => void | null;
|
||||
};
|
||||
export {};
|
||||
442
dist/umd/css/standard.css
vendored
Normal file
442
dist/umd/css/standard.css
vendored
Normal file
|
|
@ -0,0 +1,442 @@
|
|||
@charset "UTF-8";
|
||||
:root {
|
||||
--cs-primary-color: var();
|
||||
}
|
||||
|
||||
/* Distance par rapport à la gauche de la fenêtre */
|
||||
/* Distance par rapport à la droite de la fenêtre */
|
||||
/* Distance par rapport au bas de la fenêtre */
|
||||
/* Position gauche de base des cookies */
|
||||
/* Position droite de base des cookies */
|
||||
#cn-wrapper {
|
||||
/* Buttons styles start */
|
||||
/* Button styles end */
|
||||
}
|
||||
#cn-wrapper * {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
#cn-wrapper *::before {
|
||||
display: none;
|
||||
}
|
||||
#cn-wrapper button {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.5rem;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
appearance: none;
|
||||
background: #b9b9b9;
|
||||
color: #000;
|
||||
cursor: pointer;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 1rem;
|
||||
line-height: 1;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
transition: background 250ms ease-in-out, transform 150ms ease;
|
||||
}
|
||||
#cn-wrapper button:hover,
|
||||
#cn-wrapper button:focus {
|
||||
background: #a0a0a0;
|
||||
color: #000;
|
||||
}
|
||||
#cn-wrapper button:focus {
|
||||
outline: 1px solid;
|
||||
outline-color: #000;
|
||||
outline-offset: -4px;
|
||||
}
|
||||
#cn-wrapper button:active {
|
||||
transform: scale(0.99);
|
||||
}
|
||||
|
||||
/** 3.0.0 */
|
||||
/* FENETRE D'ACCUEIL */
|
||||
/* Title settings */
|
||||
/* Text settings */
|
||||
/* Button settings */
|
||||
/* Title settings */
|
||||
/* Text settings */
|
||||
/* Accept/Deny btn settings */
|
||||
/* Cookies list settings */
|
||||
#cn-wrapper .cn-nav #cn-settings-banner, #cn-wrapper .cn-nav #cn-accept-banner, #cn-wrapper .cn-nav #cn-deny-banner, #cn-wrapper .cn-content .cn-modal-container .accept label,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label, #cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p {
|
||||
display: flex;
|
||||
height: 3rem;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
background-color: #000;
|
||||
color: #b9b9b9;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 1rem;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-settings-banner:hover, #cn-wrapper .cn-nav #cn-accept-banner:hover, #cn-wrapper .cn-nav #cn-deny-banner:hover, #cn-wrapper .cn-content .cn-modal-container .accept label:hover,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label:hover, #cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p:hover, #cn-wrapper .cn-nav #cn-settings-banner:focus, #cn-wrapper .cn-nav #cn-accept-banner:focus, #cn-wrapper .cn-nav #cn-deny-banner:focus, #cn-wrapper .cn-content .cn-modal-container .accept label:focus,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label:focus, #cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p:focus {
|
||||
background-color: #a0a0a0;
|
||||
color: #000;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-settings-banner:focus, #cn-wrapper .cn-nav #cn-accept-banner:focus, #cn-wrapper .cn-nav #cn-deny-banner:focus, #cn-wrapper .cn-content .cn-modal-container .accept label:focus,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label:focus, #cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p:focus {
|
||||
outline-color: #000;
|
||||
}
|
||||
|
||||
.cn-modal-bg {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cn-open .cn-modal-bg {
|
||||
position: fixed;
|
||||
z-index: 1030;
|
||||
top: 0;
|
||||
display: block;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.cn-disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#cn-wrapper {
|
||||
z-index: 1050;
|
||||
}
|
||||
#cn-wrapper #cn-cookie-btn {
|
||||
position: fixed;
|
||||
right: auto;
|
||||
bottom: 1rem;
|
||||
left: 1rem;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
padding: 0.5rem;
|
||||
border-radius: 100%;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0.1rem 1rem rgba(0, 0, 0, 0.35);
|
||||
cursor: pointer;
|
||||
}
|
||||
#cn-wrapper #cn-cookie-btn:focus {
|
||||
outline-color: #d1842a;
|
||||
}
|
||||
#cn-wrapper #cn-cookie-btn-icon path {
|
||||
fill: #dc9c52;
|
||||
}
|
||||
#cn-wrapper #cn-cookie-btn-icon circle {
|
||||
fill: #dc9c52;
|
||||
}
|
||||
#cn-wrapper #cn-banner {
|
||||
position: fixed;
|
||||
z-index: 1050;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
max-height: 100vh;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
margin: auto;
|
||||
margin-bottom: 0;
|
||||
background-color: #fff;
|
||||
box-shadow: 0 0.1rem 1rem rgba(0, 0, 0, 0.35);
|
||||
line-height: initial;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: 0.3s;
|
||||
user-select: none;
|
||||
visibility: hidden;
|
||||
}
|
||||
#cn-wrapper #cn-banner .cn-modal-top-line {
|
||||
align-self: end;
|
||||
}
|
||||
#cn-wrapper #cn-banner .cn-modal-top-line #cn-close-modal {
|
||||
width: 4rem;
|
||||
height: 3rem;
|
||||
border-bottom-left-radius: 0.5rem;
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
#cn-wrapper #cn-banner .cn-modal-top-line #cn-close-modal {
|
||||
width: 3rem;
|
||||
height: 2rem;
|
||||
border-top-right-radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
#cn-wrapper #cn-banner > * {
|
||||
pointer-events: all;
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
#cn-wrapper #cn-banner {
|
||||
right: auto;
|
||||
bottom: calc(1rem + 60px);
|
||||
left: 0;
|
||||
width: 30rem;
|
||||
height: auto;
|
||||
max-height: 26rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
#cn-wrapper #cn-li-template {
|
||||
display: none;
|
||||
}
|
||||
#cn-wrapper .d-none {
|
||||
display: none !important;
|
||||
}
|
||||
#cn-wrapper .cn-content {
|
||||
flex-grow: 1;
|
||||
padding: 0.8rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content {
|
||||
display: flex;
|
||||
min-height: 100%;
|
||||
flex-direction: column;
|
||||
color: #b9b9b9;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
#cn-wrapper .cn-content .cn-banner-content {
|
||||
flex-flow: row wrap;
|
||||
align-items: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-img {
|
||||
width: 33%;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-text {
|
||||
width: 66%;
|
||||
}
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-img {
|
||||
text-align: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-text {
|
||||
flex: 2;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-text .cn-banner-title {
|
||||
color: #dc9c52;
|
||||
font-family: "Satisfy", sans-serif;
|
||||
font-size: 25px;
|
||||
font-weight: bold;
|
||||
line-height: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-text .cn-banner-para-p {
|
||||
margin: 6px 0;
|
||||
text-align: justify;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-details {
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
height: 0;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
text-align: justify;
|
||||
transition: 0.3s;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details {
|
||||
width: 100%;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-banner-content .cn-banner-btn-details-p {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-title {
|
||||
color: #dc9c52;
|
||||
font-family: "Satisfy", sans-serif;
|
||||
font-size: 25px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-subtitle {
|
||||
margin-bottom: 6px;
|
||||
color: #b9b9b9;
|
||||
color: #dc9c52;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-description {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: #b9b9b9;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
line-height: initial;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper {
|
||||
position: relative;
|
||||
display: flex;
|
||||
overflow: auto;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper ul {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0 20px;
|
||||
list-style: none;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper .cn-cookie-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
border: 1px solid #e4e4e4;
|
||||
border-radius: 20px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper span {
|
||||
color: #dc9c52;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper a {
|
||||
color: #dc9c52;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-modal-wrapper label {
|
||||
color: #dc9c52;
|
||||
font-family: "Barlow", sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-name {
|
||||
color: #dc9c52;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-infos {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-infos span:first-of-type {
|
||||
font-size: 17.5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-infos .cn-cookie-description {
|
||||
color: #b9b9b9;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-infos a {
|
||||
width: fit-content;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-buttons {
|
||||
display: flex;
|
||||
width: 200px;
|
||||
justify-content: space-around;
|
||||
margin-top: 6px;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-buttons input {
|
||||
display: none;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-buttons label {
|
||||
display: block;
|
||||
width: 100px;
|
||||
padding: 6px 20px;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .cn-cookie-buttons div {
|
||||
display: table;
|
||||
margin: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .accept label,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label {
|
||||
height: inherit;
|
||||
background: #808080;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .accept label:hover,
|
||||
#cn-wrapper .cn-content .cn-modal-container .accept label:focus {
|
||||
background-color: #278327;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .accept .active {
|
||||
background-color: #3a3;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label:hover,
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny label:focus {
|
||||
background-color: #832727;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny .active {
|
||||
background-color: #a33;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .accept input:checked ~ label {
|
||||
background-color: #3a3;
|
||||
}
|
||||
#cn-wrapper .cn-content .cn-modal-container .deny input:checked ~ label {
|
||||
background-color: #a33;
|
||||
}
|
||||
#cn-wrapper .cn-nav {
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 6rem;
|
||||
flex-shrink: 0;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
border-top: 1px solid #808080;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-deny-banner {
|
||||
width: 50%;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-accept-banner {
|
||||
width: 50%;
|
||||
border-right: 1px solid #808080;
|
||||
border-left: 1px solid #808080;
|
||||
font-weight: bolder;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-settings-banner {
|
||||
width: 100%;
|
||||
border-top: 1px solid #808080;
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
#cn-wrapper .cn-nav {
|
||||
height: 3rem;
|
||||
flex-wrap: initial;
|
||||
border-bottom-left-radius: 0.5rem;
|
||||
border-bottom-right-radius: 0.5rem;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-deny-banner {
|
||||
width: 33.33%;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-accept-banner {
|
||||
width: 33.33%;
|
||||
}
|
||||
#cn-wrapper .cn-nav #cn-settings-banner {
|
||||
width: 33.33%;
|
||||
border-top: initial;
|
||||
}
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
#cn-wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.cn-open {
|
||||
overflow: hidden !important;
|
||||
}
|
||||
.cn-open #cn-wrapper #cn-banner {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
}
|
||||
@media (min-width: 535px) {
|
||||
.cn-open #cn-wrapper #cn-banner {
|
||||
right: auto;
|
||||
left: 1rem;
|
||||
}
|
||||
}
|
||||
884
dist/umd/main.js
vendored
Normal file
884
dist/umd/main.js
vendored
Normal file
|
|
@ -0,0 +1,884 @@
|
|||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory();
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define([], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["CookieNotice"] = factory();
|
||||
else
|
||||
root["CookieNotice"] = factory();
|
||||
})(this, function() {
|
||||
return /******/ (function() { // webpackBootstrap
|
||||
/******/ "use strict";
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
/***/ "./dist/esm/index.js":
|
||||
/*!***************************!*\
|
||||
!*** ./dist/esm/index.js ***!
|
||||
\***************************/
|
||||
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": function() { return /* binding */ CookieNotice; }
|
||||
/* harmony export */ });
|
||||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
||||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
||||
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
||||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
||||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
||||
var CookieNotice = /*#__PURE__*/function () {
|
||||
function CookieNotice(config) {
|
||||
var _this = this;
|
||||
_classCallCheck(this, CookieNotice);
|
||||
this.browserCookieName = "cn-init";
|
||||
this.cookiePolicies = {
|
||||
sameSite: CookiePolicySameSite.lax,
|
||||
secure: ""
|
||||
};
|
||||
// * Setup Config
|
||||
this.config = config;
|
||||
// * Inject DOM modal BG
|
||||
var modalBg = document.createElement("div");
|
||||
modalBg.classList.add("cn-modal-bg");
|
||||
document.body.append(modalBg);
|
||||
this.modalBg = modalBg;
|
||||
// * Setup Dom Elements
|
||||
var cookieContainer = document.querySelector("div#cn-wrapper"),
|
||||
cookieShowModalBtn = document.querySelector("button#cn-cookie-btn"),
|
||||
cookieCloseModalBtn = document.querySelector("button#cn-close-modal"),
|
||||
cookieLinkShowCustomizeModalPageList = document.querySelectorAll("a.cn-cookie-link"),
|
||||
bannerContainer = document.querySelector("div#cn-banner"),
|
||||
bannerContent = document.querySelector("div.cn-banner-content"),
|
||||
bannerDetails = document.querySelector("div.cn-banner-details"),
|
||||
bannerParaP = document.querySelector("div.cn-banner-para-p"),
|
||||
detailsTextOpen = document.querySelector("p.cn-banner-para-p-open"),
|
||||
detailsTextClose = document.querySelector("p.cn-banner-para-p-close"),
|
||||
bannerDetailsCollapseBtn = document.querySelector("button.cn-banner-btn-details-p"),
|
||||
bannerDetailsContainer = document.querySelector("div.cn-banner-btn-details"),
|
||||
modalContainer = document.querySelector("div.cn-modal-container"),
|
||||
acceptAllBtn = document.querySelector("button#cn-accept-banner"),
|
||||
denyAllBtn = document.querySelector("button#cn-deny-banner"),
|
||||
customizeBtn = document.querySelector("button#cn-settings-banner"),
|
||||
cookiesUnorderedList = document.querySelector("ul#cn-modal-list"),
|
||||
modalWrapper = document.querySelector("div.cn-modal-wrapper"),
|
||||
template = document.querySelector("div#cn-li-template");
|
||||
if (!cookieContainer) {
|
||||
throw new Error("Cannot find div#cn-wrapper");
|
||||
}
|
||||
if (!cookieShowModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-cookie-btn' element");
|
||||
}
|
||||
if (!cookieCloseModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-close-modal' element");
|
||||
}
|
||||
if (!bannerContainer) {
|
||||
throw new Error("Cannot find 'div#cn-banner' element");
|
||||
}
|
||||
if (!bannerContent) {
|
||||
throw new Error("Cannot find 'div.cn-banner-content' element");
|
||||
}
|
||||
if (!bannerDetails) {
|
||||
throw new Error("Cannot find 'div.cn-banner-details' element");
|
||||
}
|
||||
if (!bannerParaP) {
|
||||
throw new Error("Cannot find 'div.cn-banner-para-p' element");
|
||||
}
|
||||
if (!detailsTextOpen) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-open' element");
|
||||
}
|
||||
if (!detailsTextClose) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-close' element");
|
||||
}
|
||||
if (!bannerDetailsCollapseBtn) {
|
||||
throw new Error("Cannot find 'button.cn-banner-btn-details-p' element");
|
||||
}
|
||||
if (!bannerDetailsContainer) {
|
||||
throw new Error("Cannot find '.cn-banner-btn-details' element");
|
||||
}
|
||||
if (!modalContainer) {
|
||||
throw new Error("Cannot find 'div.cn-modal-container' element");
|
||||
}
|
||||
if (!acceptAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-accept-banner' element");
|
||||
}
|
||||
if (!denyAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-deny-banner' element");
|
||||
}
|
||||
if (!customizeBtn) {
|
||||
throw new Error("Cannot find 'button.cn-settings-banner' element");
|
||||
}
|
||||
if (!cookiesUnorderedList) {
|
||||
throw new Error("Cannot find 'ul#cn-modal-list' element");
|
||||
}
|
||||
if (!modalWrapper) {
|
||||
throw new Error("Cannot find 'div.cn-modal-wrapper' element");
|
||||
}
|
||||
if (!template) {
|
||||
throw new Error("Cannot find 'div#cn-li-template' element");
|
||||
}
|
||||
this.cookieShowModalBtn = cookieShowModalBtn;
|
||||
this.cookieCloseModalBtn = cookieCloseModalBtn;
|
||||
this.cookieLinkShowCustomizeModalList = cookieLinkShowCustomizeModalPageList;
|
||||
this.cookieContainer = cookieContainer;
|
||||
this.bannerDetailsContainer = bannerDetailsContainer;
|
||||
this.bannerContainer = bannerContainer;
|
||||
this.bannerContent = bannerContent;
|
||||
this.cookiesUnorderedList = cookiesUnorderedList;
|
||||
this.modalWrapper = modalWrapper;
|
||||
this.bannerParaP = bannerParaP;
|
||||
this.detailsTextOpen = detailsTextOpen;
|
||||
this.detailsTextClose = detailsTextClose;
|
||||
this.bannerDetails = bannerDetails;
|
||||
this.bannerDetailsCollapseBtn = bannerDetailsCollapseBtn;
|
||||
this.modalContainer = modalContainer;
|
||||
this.acceptAllBtn = acceptAllBtn;
|
||||
this.denyAllBtn = denyAllBtn;
|
||||
this.customizeBtn = customizeBtn;
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
this.template = template;
|
||||
var memoryTemplate = this.template.cloneNode(true);
|
||||
this.template.remove();
|
||||
this.template = memoryTemplate;
|
||||
// * Setup Events
|
||||
this.addEventPrevent(this.modalBg, "click", this.closeCookieModal);
|
||||
this.addEventPrevent(this.cookieCloseModalBtn, "click", this.closeCookieModal);
|
||||
this.addEventPrevent(this.acceptAllBtn, "click", this.acceptAllCookies);
|
||||
this.addEventPrevent(this.denyAllBtn, "click", this.denyAllCookies);
|
||||
this.addEventPrevent(this.customizeBtn, "click", this.toggleCookieModalPages);
|
||||
this.addEventPrevent(this.bannerDetailsCollapseBtn, "click", this.toggleBannerDetails);
|
||||
this.addEventPrevent(this.cookieShowModalBtn, "click", this.toggleCookieModal);
|
||||
this.cookieLinkShowCustomizeModalList.forEach(function (cookieLink) {
|
||||
_this.addEventPrevent(cookieLink, "click", _this.openCookieModalToCookiePage);
|
||||
});
|
||||
// * Setup CN Cookie
|
||||
if (!this.cookiesMatchesConfig()) {
|
||||
// * Setup Browser Cookie if none.
|
||||
this.resetBrowserCookie();
|
||||
this.openCookieModalToBannerPage();
|
||||
}
|
||||
// * Cookie should have been created from here.
|
||||
var cookies = this.getCookieStatusList();
|
||||
Object.entries(cookies).forEach(function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
cookieName = _ref2[0],
|
||||
cookieStatus = _ref2[1];
|
||||
if (cookieStatus === CookieStatus.wait) {
|
||||
// * Open modal if any cookie config is not set.
|
||||
_this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
if (!_this.config[cookieName]) {
|
||||
// * Ignore missing config
|
||||
return;
|
||||
}
|
||||
if (cookieStatus === CookieStatus.true) {
|
||||
// * Exec script part for accepted cookie.
|
||||
_this.config[cookieName].script();
|
||||
return;
|
||||
}
|
||||
if (_this.config[cookieName].fallback != null) {
|
||||
// * Exec fallback part for accepted cookie if provided.
|
||||
_this.config[cookieName].fallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
// COOKIES
|
||||
/**
|
||||
* Check if the actual cookie matches the config
|
||||
*/
|
||||
_createClass(CookieNotice, [{
|
||||
key: "cookiesMatchesConfig",
|
||||
value: function cookiesMatchesConfig() {
|
||||
var cookies = this.getCookieStatusList();
|
||||
return Object.keys(cookies).length === Object.keys(this.config).length;
|
||||
}
|
||||
/**
|
||||
* Accept a specific cookie
|
||||
*/
|
||||
}, {
|
||||
key: "acceptAllCookies",
|
||||
value: function acceptAllCookies() {
|
||||
var _this2 = this;
|
||||
Object.entries(this.config).forEach(function (_ref3) {
|
||||
var _ref4 = _slicedToArray(_ref3, 2),
|
||||
cookieName = _ref4[0],
|
||||
cookieOption = _ref4[1];
|
||||
return _this2.setCookieStatus(cookieName, CookieStatus.true, cookieOption);
|
||||
});
|
||||
var _iterator = _createForOfIteratorHelper(this.cookieContainer.querySelectorAll(".accept > label")),
|
||||
_step;
|
||||
try {
|
||||
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
||||
var acceptLabel = _step.value;
|
||||
acceptLabel.classList.add("active");
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator.e(err);
|
||||
} finally {
|
||||
_iterator.f();
|
||||
}
|
||||
var _iterator2 = _createForOfIteratorHelper(this.cookieContainer.querySelectorAll(".deny > label")),
|
||||
_step2;
|
||||
try {
|
||||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
||||
var denyLabel = _step2.value;
|
||||
denyLabel.classList.remove("active");
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator2.e(err);
|
||||
} finally {
|
||||
_iterator2.f();
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Deny a specific cookie
|
||||
*/
|
||||
}, {
|
||||
key: "denyAllCookies",
|
||||
value: function denyAllCookies() {
|
||||
var _this3 = this;
|
||||
Object.entries(this.config).forEach(function (_ref5) {
|
||||
var _ref6 = _slicedToArray(_ref5, 2),
|
||||
cookieName = _ref6[0],
|
||||
cookieOption = _ref6[1];
|
||||
return _this3.setCookieStatus(cookieName, CookieStatus.false, cookieOption);
|
||||
});
|
||||
var _iterator3 = _createForOfIteratorHelper(this.cookieContainer.querySelectorAll(".accept > label")),
|
||||
_step3;
|
||||
try {
|
||||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
||||
var acceptLabel = _step3.value;
|
||||
acceptLabel.classList.remove("active");
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator3.e(err);
|
||||
} finally {
|
||||
_iterator3.f();
|
||||
}
|
||||
var _iterator4 = _createForOfIteratorHelper(this.cookieContainer.querySelectorAll(".deny > label")),
|
||||
_step4;
|
||||
try {
|
||||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
||||
var denyLabel = _step4.value;
|
||||
denyLabel.classList.add("active");
|
||||
}
|
||||
} catch (err) {
|
||||
_iterator4.e(err);
|
||||
} finally {
|
||||
_iterator4.f();
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Fetch the cookie status list
|
||||
*
|
||||
* @returns the cookie status list
|
||||
*/
|
||||
}, {
|
||||
key: "getCookieStatusList",
|
||||
value: function getCookieStatusList() {
|
||||
var cookies = this.getBrowserCookieValue(),
|
||||
statusList = {};
|
||||
if (cookies === undefined) {
|
||||
return statusList;
|
||||
}
|
||||
/** specificCookieString contains youtube=true like */
|
||||
cookies.split(",").forEach(function (specificCookieString) {
|
||||
var values = specificCookieString.split("=");
|
||||
statusList[values[0]] = values[1];
|
||||
});
|
||||
return statusList;
|
||||
}
|
||||
/**
|
||||
* Check has cookie status
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
}, {
|
||||
key: "containsCookieStatus",
|
||||
value: function containsCookieStatus(key) {
|
||||
var statusList = this.getCookieStatusList();
|
||||
return Object.keys(statusList).find(function (cookieName) {
|
||||
return cookieName === key;
|
||||
}) !== undefined;
|
||||
}
|
||||
/**
|
||||
* Set the cookie value
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
* @param cookieOption
|
||||
*/
|
||||
}, {
|
||||
key: "setCookieStatus",
|
||||
value: function setCookieStatus(cookieName, status, cookieOption) {
|
||||
if (status === CookieStatus.true) {
|
||||
this.addCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
if (status === CookieStatus.false) {
|
||||
this.removeCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.wait);
|
||||
}
|
||||
/**
|
||||
* Add a specific cookie and
|
||||
* change his status to true
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
}, {
|
||||
key: "addCookieStatus",
|
||||
value: function addCookieStatus(cookieName, cookieOption) {
|
||||
if (cookieOption.script) {
|
||||
cookieOption.script();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.true);
|
||||
}
|
||||
/**
|
||||
* Remove a specific cookie and
|
||||
* change his status to false
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
}, {
|
||||
key: "removeCookieStatus",
|
||||
value: function removeCookieStatus(cookieName, cookieOption) {
|
||||
var cookieNameElement = document.getElementById(cookieName);
|
||||
if (cookieNameElement) {
|
||||
cookieNameElement.remove();
|
||||
}
|
||||
if (cookieOption.fallback) {
|
||||
cookieOption.fallback();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.false);
|
||||
}
|
||||
/**
|
||||
* Change the status of a cookie
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
*/
|
||||
}, {
|
||||
key: "setBrowserCookieStatus",
|
||||
value: function setBrowserCookieStatus(cookieName, status) {
|
||||
var statusList = this.getCookieStatusList();
|
||||
// * Force refresh
|
||||
this.deleteBrowserCookie();
|
||||
statusList[cookieName] = status;
|
||||
this.saveBrowserCookie(statusList);
|
||||
}
|
||||
/**
|
||||
* Has CN cokie setup ?
|
||||
* @returns true if the cookie is setup
|
||||
*/
|
||||
}, {
|
||||
key: "hasBrowserCookie",
|
||||
value: function hasBrowserCookie() {
|
||||
return Boolean(this.getBrowserCookieValue());
|
||||
}
|
||||
/**
|
||||
* Get the Ldcweb cookie
|
||||
*
|
||||
* @returns A string like analytics=true,youtube=true or undefined
|
||||
*/
|
||||
}, {
|
||||
key: "getBrowserCookieValue",
|
||||
value: function getBrowserCookieValue() {
|
||||
var matches = document.cookie.match(new RegExp("(?:^|; )" + this.browserCookieName.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") + "=([^;]*)"));
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
/**
|
||||
* Save cookie content on web browser
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
}, {
|
||||
key: "saveBrowserCookie",
|
||||
value: function saveBrowserCookie(statusList) {
|
||||
var date = new Date(),
|
||||
newDate = new Date(date.setMonth(date.getMonth() + 13)),
|
||||
content = Object.entries(statusList).map(function (_ref7) {
|
||||
var _ref8 = _slicedToArray(_ref7, 2),
|
||||
cookieName = _ref8[0],
|
||||
cookieStatus = _ref8[1];
|
||||
return "".concat(cookieName, "=").concat(cookieStatus);
|
||||
}).join(",");
|
||||
document.cookie = "".concat(this.browserCookieName, "=").concat(content, ";path=/").concat(location.hostname ? ";domain=".concat(location.hostname) : "", ";expires=").concat(newDate.toUTCString(), ";").concat(this.getCookiePoliciesAsString());
|
||||
}
|
||||
/**
|
||||
* Set an older expire parameter to a specific cookie
|
||||
*/
|
||||
}, {
|
||||
key: "deleteBrowserCookie",
|
||||
value: function deleteBrowserCookie() {
|
||||
if (this.hasBrowserCookie()) {
|
||||
// * Suppression du cookie et de sa version precedé d'un point
|
||||
document.cookie = "".concat(this.browserCookieName, "=;path=/").concat(location.hostname ? ";domain=.".concat(location.hostname) : "", ";expires=Thu, 01 Jan 1970 00:00:01 GMT;").concat(this.getCookiePoliciesAsString());
|
||||
document.cookie = "".concat(this.browserCookieName, "=;path=/").concat(location.hostname ? ";domain=".concat(location.hostname) : "", ";expires=Thu, 01 Jan 1970 00:00:01 GMT;").concat(this.getCookiePoliciesAsString());
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "getCookiePoliciesAsString",
|
||||
value: function getCookiePoliciesAsString() {
|
||||
return Object.entries(this.cookiePolicies).map(function (_ref9) {
|
||||
var _ref10 = _slicedToArray(_ref9, 2),
|
||||
policyName = _ref10[0],
|
||||
policyValue = _ref10[1];
|
||||
return "".concat(policyName, "=").concat(policyValue);
|
||||
}).join(";");
|
||||
}
|
||||
/**
|
||||
* Reset Ldc Web CN cookie
|
||||
*/
|
||||
}, {
|
||||
key: "resetBrowserCookie",
|
||||
value: function resetBrowserCookie() {
|
||||
// * Create Cookie as It does not exists.
|
||||
var newCookieList = {};
|
||||
Object.entries(this.config).forEach(function (_ref11) {
|
||||
var _ref12 = _slicedToArray(_ref11, 1),
|
||||
cookieName = _ref12[0];
|
||||
return newCookieList[cookieName] = CookieStatus.wait;
|
||||
});
|
||||
this.saveBrowserCookie(newCookieList);
|
||||
}
|
||||
// LISTENERS
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
}, {
|
||||
key: "addEvent",
|
||||
value: function addEvent(element, evnt, funct) {
|
||||
return element.addEventListener(evnt, funct.bind(this), false);
|
||||
}
|
||||
/**
|
||||
* Add event on a specific element and prevent default
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
}, {
|
||||
key: "addEventPrevent",
|
||||
value: function addEventPrevent(element, evnt, funct) {
|
||||
var _this4 = this;
|
||||
return element.addEventListener(evnt, function (e) {
|
||||
e.preventDefault();
|
||||
funct.call(_this4, e);
|
||||
}, false);
|
||||
}
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
}, {
|
||||
key: "addEventKbdValidate",
|
||||
value: function addEventKbdValidate(element, funct) {
|
||||
var _this5 = this;
|
||||
return this.addEvent(element, "keyup", function (e) {
|
||||
var kbdEvt = e;
|
||||
if (kbdEvt.key == " " || kbdEvt.code == "Space" || kbdEvt.keyCode == 32 || kbdEvt.key == "Enter" || kbdEvt.code == "Enter" || kbdEvt.keyCode == 13) {
|
||||
funct.call(_this5, kbdEvt);
|
||||
}
|
||||
});
|
||||
}
|
||||
// COOKIE MODAL
|
||||
/**
|
||||
* Show or hide Cookie modal
|
||||
* @returns
|
||||
*/
|
||||
}, {
|
||||
key: "toggleCookieModal",
|
||||
value: function toggleCookieModal() {
|
||||
if (!document.body.classList.contains("cn-open")) {
|
||||
this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
/**
|
||||
* Open the cookies modal to the banner page
|
||||
*/
|
||||
}, {
|
||||
key: "openCookieModalToBannerPage",
|
||||
value: function openCookieModalToBannerPage() {
|
||||
this.openCookieModalToCookiePage();
|
||||
this.toggleCookieModalPages();
|
||||
}
|
||||
/**
|
||||
* Open the cookies modal to the cookies page
|
||||
*/
|
||||
}, {
|
||||
key: "openCookieModalToCookiePage",
|
||||
value: function openCookieModalToCookiePage() {
|
||||
document.body.classList.add("cn-open");
|
||||
this.resetCookieModal();
|
||||
this.bannerContent.classList.add("d-none");
|
||||
this.bannerDetails.classList.add("d-none");
|
||||
this.bannerDetailsContainer.classList.add("d-none");
|
||||
this.modalContainer.classList.remove("d-none");
|
||||
// Scroll to the top of the cookies list
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
this.setupCookieModalList();
|
||||
this.setTabIndex();
|
||||
}
|
||||
/**
|
||||
* Hide the cookies modal
|
||||
*/
|
||||
}, {
|
||||
key: "closeCookieModal",
|
||||
value: function closeCookieModal() {
|
||||
document.body.classList.remove("cn-open");
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.unsetTabIndex();
|
||||
this.setupCookieModalList();
|
||||
}
|
||||
/**
|
||||
* Setup tab indexes on visible elements
|
||||
*/
|
||||
}, {
|
||||
key: "setTabIndex",
|
||||
value: function setTabIndex() {
|
||||
var _this6 = this;
|
||||
// * Prevent focus html tag
|
||||
document.documentElement.setAttribute("tabindex", "-1");
|
||||
setTimeout(function () {
|
||||
var focusableSelector = "a[href], button, [role=\"button\"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])";
|
||||
// * Only focusable elements
|
||||
_toConsumableArray(document.body.querySelectorAll(focusableSelector)).filter(function (el) {
|
||||
return !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden");
|
||||
}).forEach(function (el) {
|
||||
el.setAttribute("tabindex", "-1");
|
||||
el.classList.add("cn-disabled");
|
||||
});
|
||||
_toConsumableArray(_this6.cookieContainer.querySelectorAll(focusableSelector)).filter(function (el) {
|
||||
return !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden") &&
|
||||
// * Only visible elements
|
||||
!!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
|
||||
}).forEach(function (el) {
|
||||
el.setAttribute("tabindex", "0");
|
||||
el.classList.remove("cn-disabled");
|
||||
});
|
||||
_this6.cookieShowModalBtn.setAttribute("tabindex", "-1");
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
* Undo setup tab indexes on visible elements
|
||||
*/
|
||||
}, {
|
||||
key: "unsetTabIndex",
|
||||
value: function unsetTabIndex() {
|
||||
var _this7 = this;
|
||||
document.documentElement.setAttribute("tabindex", "0");
|
||||
setTimeout(function () {
|
||||
document.body.querySelectorAll(".cn-disabled").forEach(function (el) {
|
||||
el.setAttribute("tabindex", "0");
|
||||
el.classList.remove("cn-disabled");
|
||||
});
|
||||
_this7.cookieShowModalBtn.setAttribute("tabindex", "0");
|
||||
}, 500);
|
||||
}
|
||||
/**
|
||||
* Reset the modal view state
|
||||
*/
|
||||
}, {
|
||||
key: "resetCookieModal",
|
||||
value: function resetCookieModal() {
|
||||
this.bannerContent.classList.remove("d-none");
|
||||
this.bannerDetails.classList.remove("d-none");
|
||||
this.bannerDetailsContainer.classList.remove("d-none");
|
||||
this.modalContainer.classList.add("d-none");
|
||||
if (!this.customizeBtn.dataset.openModal) {
|
||||
throw new Error("Cannot find attribut data-open-modal");
|
||||
}
|
||||
this.customizeBtn.innerHTML = this.customizeBtn.dataset.openModal;
|
||||
}
|
||||
/**
|
||||
* Set the cookies list in the modal
|
||||
*/
|
||||
}, {
|
||||
key: "setupCookieModalList",
|
||||
value: function setupCookieModalList() {
|
||||
var _this8 = this;
|
||||
this.cookiesUnorderedList.innerHTML = "";
|
||||
Object.entries(this.config).forEach(function (_ref13) {
|
||||
var _ref14 = _slicedToArray(_ref13, 2),
|
||||
cookieName = _ref14[0],
|
||||
cookieConfig = _ref14[1];
|
||||
var cookie = document.createElement("li");
|
||||
var childItem = _this8.template.children.item(0);
|
||||
if (childItem === null) {
|
||||
throw new Error("Cannot find child item");
|
||||
}
|
||||
cookie.append(childItem.cloneNode(true));
|
||||
var name = cookie.querySelector("span.cn-cookie-name");
|
||||
var description = cookie.querySelector("span.cn-cookie-description");
|
||||
var link = cookie.querySelector(".cn-cookie-link");
|
||||
var acceptInput = cookie.querySelector(".accept > input");
|
||||
var denyInput = cookie.querySelector(".deny > input");
|
||||
var acceptLabel = cookie.querySelector(".accept > label");
|
||||
var denyLabel = cookie.querySelector(".deny > label");
|
||||
name.textContent = cookieConfig.name;
|
||||
description.textContent = cookieConfig.description;
|
||||
link.textContent = cookieConfig.labelLink;
|
||||
link.setAttribute("href", cookieConfig.link);
|
||||
acceptInput.id = cookieName + "1";
|
||||
acceptInput.name = cookieName;
|
||||
acceptInput.dataset.name = cookieName;
|
||||
acceptLabel.htmlFor = cookieName + "1";
|
||||
denyInput.id = cookieName + "2";
|
||||
denyInput.name = cookieName;
|
||||
denyInput.dataset.name = cookieName;
|
||||
denyLabel.htmlFor = cookieName + "2";
|
||||
var acceptFn = function acceptFn() {
|
||||
acceptLabel.classList.add("active");
|
||||
denyLabel.classList.remove("active");
|
||||
_this8.setCookieStatus(cookieName, CookieStatus.true, cookieConfig);
|
||||
},
|
||||
denyFn = function denyFn() {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.add("active");
|
||||
_this8.setCookieStatus(cookieName, CookieStatus.false, cookieConfig);
|
||||
};
|
||||
_this8.addEvent(acceptInput, "click", acceptFn);
|
||||
_this8.addEventKbdValidate(acceptLabel, acceptFn);
|
||||
_this8.addEvent(denyInput, "click", denyFn);
|
||||
_this8.addEventKbdValidate(denyLabel, denyFn);
|
||||
_this8.cookiesUnorderedList.append(cookie);
|
||||
if (!_this8.hasBrowserCookie()) {
|
||||
// * Ldcweb cookie is not set.
|
||||
return;
|
||||
}
|
||||
// * Setup list status state
|
||||
Object.entries(_this8.getCookieStatusList()).forEach(function (_ref15) {
|
||||
var _ref16 = _slicedToArray(_ref15, 2),
|
||||
ckName = _ref16[0],
|
||||
cookieStatus = _ref16[1];
|
||||
if (ckName === cookieName) {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.remove("active");
|
||||
switch (cookieStatus) {
|
||||
case CookieStatus.true:
|
||||
acceptLabel.classList.add("active");
|
||||
break;
|
||||
case CookieStatus.false:
|
||||
denyLabel.classList.add("active");
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Toggle show hide banner details
|
||||
*/
|
||||
}, {
|
||||
key: "toggleBannerDetails",
|
||||
value: function toggleBannerDetails() {
|
||||
this.bannerDetails.classList.toggle("cn-details-open");
|
||||
if (!this.bannerDetailsCollapseBtn.dataset.open || !this.bannerDetailsCollapseBtn.dataset.close) {
|
||||
throw new Error("Cannot find attribute data-open or data-close");
|
||||
}
|
||||
if (this.bannerDetailsAreExpanded) {
|
||||
this.bannerDetailsCollapseBtn.innerHTML = this.bannerDetailsCollapseBtn.dataset.close;
|
||||
this.detailsTextOpen.classList.add("d-none");
|
||||
this.detailsTextClose.classList.remove("d-none");
|
||||
this.bannerDetails.style.height = "0px";
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
} else {
|
||||
this.bannerDetailsCollapseBtn.innerHTML = this.bannerDetailsCollapseBtn.dataset.open;
|
||||
this.detailsTextOpen.classList.remove("d-none");
|
||||
this.detailsTextClose.classList.add("d-none");
|
||||
this.bannerDetails.style.height = this.bannerDetails.children[0].clientHeight + "px";
|
||||
this.bannerDetailsAreExpanded = true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Toggle Cookie modal pages
|
||||
*/
|
||||
}, {
|
||||
key: "toggleCookieModalPages",
|
||||
value: function toggleCookieModalPages() {
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.setTabIndex();
|
||||
this.setupCookieModalList();
|
||||
this.togglePersonalizeBtn();
|
||||
}
|
||||
/**
|
||||
* Toggle customize btn
|
||||
*/
|
||||
}, {
|
||||
key: "togglePersonalizeBtn",
|
||||
value: function togglePersonalizeBtn() {
|
||||
var customizeBtnBannerDataset = this.customizeBtn.dataset;
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
if (this.bannerContent.classList.contains("d-none")) {
|
||||
this.customizeBtn.innerHTML = customizeBtnBannerDataset.openModal;
|
||||
} else {
|
||||
this.customizeBtn.innerHTML = customizeBtnBannerDataset.closeModal;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
return CookieNotice;
|
||||
}();
|
||||
|
||||
var CookieStatus;
|
||||
(function (CookieStatus) {
|
||||
CookieStatus["true"] = "true";
|
||||
CookieStatus["false"] = "false";
|
||||
CookieStatus["wait"] = "wait";
|
||||
})(CookieStatus || (CookieStatus = {}));
|
||||
var CookiePolicySameSite;
|
||||
(function (CookiePolicySameSite) {
|
||||
CookiePolicySameSite["lax"] = "lax";
|
||||
CookiePolicySameSite["strict"] = "strict";
|
||||
CookiePolicySameSite["none"] = "none";
|
||||
})(CookiePolicySameSite || (CookiePolicySameSite = {}));
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./src/scss/themes/standard.scss":
|
||||
/*!***************************************!*\
|
||||
!*** ./src/scss/themes/standard.scss ***!
|
||||
\***************************************/
|
||||
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
||||
|
||||
module.exports = __webpack_require__.p + "css/standard.css";
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/define property getters */
|
||||
/******/ !function() {
|
||||
/******/ // define getter functions for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, definition) {
|
||||
/******/ for(var key in definition) {
|
||||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
||||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
||||
/******/ }
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/ }();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/global */
|
||||
/******/ !function() {
|
||||
/******/ __webpack_require__.g = (function() {
|
||||
/******/ if (typeof globalThis === 'object') return globalThis;
|
||||
/******/ try {
|
||||
/******/ return this || new Function('return this')();
|
||||
/******/ } catch (e) {
|
||||
/******/ if (typeof window === 'object') return window;
|
||||
/******/ }
|
||||
/******/ })();
|
||||
/******/ }();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
||||
/******/ !function() {
|
||||
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
||||
/******/ }();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/make namespace object */
|
||||
/******/ !function() {
|
||||
/******/ // define __esModule on exports
|
||||
/******/ __webpack_require__.r = function(exports) {
|
||||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
/******/ }
|
||||
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||
/******/ };
|
||||
/******/ }();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/publicPath */
|
||||
/******/ !function() {
|
||||
/******/ var scriptUrl;
|
||||
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
|
||||
/******/ var document = __webpack_require__.g.document;
|
||||
/******/ if (!scriptUrl && document) {
|
||||
/******/ if (document.currentScript)
|
||||
/******/ scriptUrl = document.currentScript.src;
|
||||
/******/ if (!scriptUrl) {
|
||||
/******/ var scripts = document.getElementsByTagName("script");
|
||||
/******/ if(scripts.length) scriptUrl = scripts[scripts.length - 1].src
|
||||
/******/ }
|
||||
/******/ }
|
||||
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
|
||||
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
|
||||
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
|
||||
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
||||
/******/ __webpack_require__.p = scriptUrl;
|
||||
/******/ }();
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/
|
||||
/******/ // startup
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ __webpack_require__("./dist/esm/index.js");
|
||||
/******/ // This entry module doesn't tell about it's top-level declarations so it can't be inlined
|
||||
/******/ var __webpack_exports__ = __webpack_require__("./src/scss/themes/standard.scss");
|
||||
/******/
|
||||
/******/ return __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
||||
});
|
||||
//# sourceMappingURL=main.js.map
|
||||
1
dist/umd/main.js.map
vendored
Normal file
1
dist/umd/main.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -14,10 +14,10 @@ $strings = (object)[
|
|||
'button_customize' => Str::upper(__('Personnaliser')),
|
||||
'button_back' => Str::upper(__('Retour')),
|
||||
'banner_title' => __('Le site internet :site_name utilise des cookies !', ['site_name' => $site_name]),
|
||||
'banner_text_open' => __('Ce site web stocke les cookies sur votre ordinateur. :site_name utilise ces informations
|
||||
'banner_text_open' => __("Ce site web stocke les cookies sur votre ordinateur. :site_name utilise ces informations
|
||||
afin d’améliorer et de personnaliser votre expérience de navigation, ainsi que pour l’analyse et les indicateurs concernant nos
|
||||
visiteurs à la fois sur ce site web et sur d’autres supports. Vous pouvez cliquer sur « Accepter » si vous consentez à l’utilisation
|
||||
de ces cookies.', ['site_name' => $site_name]),
|
||||
visiteurs à la fois sur ce site web et sur d’autres supports.\n Vous pouvez cliquer sur « Accepter » si vous consentez à l’utilisation
|
||||
de ces cookies.", ['site_name' => $site_name]),
|
||||
'banner_text' => __('Nous utilisons des cookies pour nous assurer du bon fonctionnement de notre site et à des fins analytiques.
|
||||
En poursuivant votre navigation sur ce site ou en fermant ce bandeau, vous consentez à l’utilisationde ces cookies.'),
|
||||
'banner_details' => __('Si vous refusez l’utilisation des cookies, vos informations ne seront pas suivies lors de votre visite sur ce site.
|
||||
|
|
@ -50,7 +50,7 @@ $cookies['youtube'] = [
|
|||
|
||||
$cookies['youtube']['script'] = <<<SCRIPT
|
||||
function () {
|
||||
let youtubeVids = document.getElementsByClassName('ldcweb-cn-youtube');
|
||||
let youtubeVids = document.getElementsByClassName('cn-youtube');
|
||||
for (let item of youtubeVids) {
|
||||
let id = item.dataset.id;
|
||||
let e = document.createElement('iframe');
|
||||
|
|
@ -67,14 +67,14 @@ function () {
|
|||
SCRIPT;
|
||||
$cookies['youtube']['fallback'] = <<<FALLBACK
|
||||
function () {
|
||||
let youtubeVids = document.getElementsByClassName('ldcweb-cn-youtube');
|
||||
let youtubeVids = document.getElementsByClassName('cn-youtube');
|
||||
for (let item of youtubeVids) {
|
||||
let a = document.createElement('a');
|
||||
a.innerText = 'Autoriser';
|
||||
a.classList.add('ldcweb-cn-cookie-link');
|
||||
a.classList.add('cn-cookie-link');
|
||||
a.classList.add('btn-autorize');
|
||||
a.onclick = function () {
|
||||
LdcwebCn.openModal();
|
||||
CookieNotice.openModal();
|
||||
};
|
||||
let e = document.createElement('p');
|
||||
e.innerHTML = 'Youtube est désactivé. ';
|
||||
|
|
@ -96,7 +96,7 @@ $cookies['vimeo'] = [
|
|||
|
||||
$cookies['vimeo']['script'] = <<<SCRIPT
|
||||
function () {
|
||||
let vimeoVids = document.getElementsByClassName('ldcweb-cn-vimeo');
|
||||
let vimeoVids = document.getElementsByClassName('cn-vimeo');
|
||||
for (let item of vimeoVids) {
|
||||
let id = item.dataset.id;
|
||||
let e = document.createElement('iframe');
|
||||
|
|
@ -113,14 +113,14 @@ function () {
|
|||
SCRIPT;
|
||||
$cookies['vimeo']['fallback'] = <<<FALLBACK
|
||||
function () {
|
||||
let vimeoVids = document.getElementsByClassName('ldcweb-cn-vimeo');
|
||||
let vimeoVids = document.getElementsByClassName('cn-vimeo');
|
||||
for (let item of vimeoVids) {
|
||||
let a = document.createElement('a');
|
||||
a.innerText = 'Autoriser';
|
||||
a.classList.add('ldcweb-cn-cookie-link');
|
||||
a.classList.add('cn-cookie-link');
|
||||
a.classList.add('btn-autorize');
|
||||
a.onclick = function () {
|
||||
LdcwebCn.openModal();
|
||||
CookieNotice.openModal();
|
||||
};
|
||||
let e = document.createElement('p');
|
||||
e.innerHTML = 'Vimeo est désactivé. ';
|
||||
|
|
@ -142,8 +142,8 @@ $cookies['recaptcha'] = [
|
|||
|
||||
$cookies['recaptcha']['script'] = <<<SCRIPT
|
||||
function () {
|
||||
if (window.__LDC_CN_Recaptcha) {
|
||||
window.__LDC_CN_Recaptcha();
|
||||
if (window.__CN_Recaptcha) {
|
||||
window.__CN_Recaptcha();
|
||||
}
|
||||
}
|
||||
SCRIPT;
|
||||
|
|
@ -184,42 +184,31 @@ SCRIPT;
|
|||
@endphp
|
||||
|
||||
|
||||
// INCLUDE TEMPLATE
|
||||
@include('templates.standard', compact(
|
||||
{{-- INCLUDE TEMPLATE --}}
|
||||
@include('vendor.cookie-notice-templates/standard', compact(
|
||||
'site_name', 'logo_picture_url', 'logo_alt_text',
|
||||
'confidentiality_page_url', 'strings'
|
||||
))
|
||||
|
||||
@push('scripts')
|
||||
<script nonce="{{ $nonce ?? '' }}">
|
||||
window.LDCWebCN = {};
|
||||
window.WebCookieNotice = {};
|
||||
@foreach($cookies as $index_name => $cookie)
|
||||
window.LDCWebCN['{{ $index_name }}'] = {};
|
||||
window.LDCWebCN['{{ $index_name }}'].tmp = {};
|
||||
window.WebCookieNotice['{{ $index_name }}'] = {};
|
||||
window.WebCookieNotice['{{ $index_name }}'].tmp = {};
|
||||
// SCRIPT
|
||||
window.LDCWebCN['{{ $index_name }}'].tmp.script = {!! strip_tags($cookie['script']) !!};
|
||||
window.WebCookieNotice['{{ $index_name }}'].tmp.script = {!! strip_tags($cookie['script']) !!};
|
||||
@php unset($cookie['script']); @endphp
|
||||
// FALLBACK
|
||||
@if(isset($cookie['fallback']))
|
||||
window.LDCWebCN['{{ $index_name }}'].tmp.fallback = {!! strip_tags($cookie['fallback']) !!};
|
||||
window.WebCookieNotice['{{ $index_name }}'].tmp.fallback = {!! strip_tags($cookie['fallback']) !!};
|
||||
@php unset($cookie['fallback']); @endphp
|
||||
@endif
|
||||
window.LDCWebCN['{{ $index_name }}'].conf = @json($cookie);
|
||||
window.LDCWebCN['{{ $index_name }}'].conf.script = window.LDCWebCN['{{ $index_name }}'].tmp.script;
|
||||
window.LDCWebCN['{{ $index_name }}'].conf.fallback = window.LDCWebCN['{{ $index_name }}'].tmp.fallback;
|
||||
window.LDCWebCN['{{ $index_name }}'] = window.LDCWebCN['{{ $index_name }}'].conf;
|
||||
window.WebCookieNotice['{{ $index_name }}'].conf = @json($cookie);
|
||||
window.WebCookieNotice['{{ $index_name }}'].conf.script = window.WebCookieNotice['{{ $index_name }}'].tmp.script;
|
||||
window.WebCookieNotice['{{ $index_name }}'].conf.fallback = window.WebCookieNotice['{{ $index_name }}'].tmp.fallback;
|
||||
window.WebCookieNotice['{{ $index_name }}'] = window.WebCookieNotice['{{ $index_name }}'].conf;
|
||||
@endforeach
|
||||
window.LDCWebCN = new LdcwebCn(window.LDCWebCN);
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
|
||||
@push('scripts')
|
||||
<script nonce="{{ $nonce ?? '' }}">
|
||||
window.LDCWebCN = new LdcwebCn({
|
||||
@foreach($cookies as $index_name => $cookie)
|
||||
'{{ $index_name }}': {{ $cookie }}
|
||||
@endforeach
|
||||
});
|
||||
window.WebCookieNotice = new WebCookieNotice(window.WebCookieNotice);
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<div id="cn-wrapper">
|
||||
<div id="cn-wrapper" tabindex="-1" role="dialog">
|
||||
<button id="cn-cookie-btn" title="{{ $strings->button_customize_cookies }}">
|
||||
{{-- COOKIE SVG --}}
|
||||
<svg viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg">
|
||||
|
|
@ -16,7 +16,10 @@
|
|||
</svg>
|
||||
</button>
|
||||
{{-- BANNER --}}
|
||||
<div id="cn-banner">
|
||||
<div id="cn-banner" tabindex="-1">
|
||||
<div class="cn-modal-top-line">
|
||||
<button id="cn-close-modal">X</button>
|
||||
</div>
|
||||
{{-- CONTENT VIEW --}}
|
||||
<div class="cn-content">
|
||||
{{-- 1ST PAGE BANNER --}}
|
||||
|
|
@ -52,7 +55,7 @@
|
|||
<p class="cn-modal-description">{!! nl2br(e($strings->Panel_details)) !!}</p>
|
||||
<div class="cn-modal-wrapper">
|
||||
{{-- COOKIES LIST --}}
|
||||
<ul id="ldcweb-cn-list"></ul>
|
||||
<ul id="cn-modal-list"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -68,19 +71,19 @@
|
|||
{{-- COOKIE LIST LI TEMPLATE --}}
|
||||
<div id="cn-li-template">
|
||||
<div class="cn-cookie-wrapper">
|
||||
<div class="ldcweb-cn-infos">
|
||||
<span class="ldcweb-cn-name">#name</span>
|
||||
<span class="ldcweb-cn-description">#description</span>
|
||||
<a class="ldcweb-cn-link">#link</a>
|
||||
<div class="cn-cookie-infos">
|
||||
<span class="cn-cookie-name">#name</span>
|
||||
<span class="cn-cookie-description">#description</span>
|
||||
<a class="cn-cookie-link">#link</a>
|
||||
</div>
|
||||
<div class="ldcweb-cn-buttons">
|
||||
<div class="cn-cookie-buttons">
|
||||
<div class="deny">
|
||||
<input type="radio" id="" name="" data-name="" data-status="false">
|
||||
<label for="" role="button">{{ $strings->button_forbid }}</label>
|
||||
<label for="" role="button" tabindex="0">{{ $strings->button_forbid }}</label>
|
||||
</div>
|
||||
<div class="accept">
|
||||
<input type="radio" id="" name="" data-name="" data-status="true">
|
||||
<label for="" role="button">{{ $strings->button_allow }}</label>
|
||||
<label for="" role="button" tabindex="0">{{ $strings->button_allow }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"include": ["./resources/js/**/*"]
|
||||
"include": ["./src/js/**/*"]
|
||||
}
|
||||
|
|
|
|||
12322
package-lock.json
generated
12322
package-lock.json
generated
File diff suppressed because it is too large
Load diff
98
package.json
98
package.json
|
|
@ -1,31 +1,16 @@
|
|||
{
|
||||
"name": "@ldc-web/cookie-notice",
|
||||
"version": "3.0.0",
|
||||
"description": "LDC Web cookie notice for websites usage",
|
||||
"main": "dist/ts/ldcweb-cookies.js",
|
||||
"typings": "dist/ts/index.d.ts",
|
||||
"version": "3.0.2",
|
||||
"description": "Web cookie notice for websites usage",
|
||||
"main": "./dist/umd/main.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"types": "./dist/typings/index.d.ts",
|
||||
"sass": "./src/scss/themes/standard.scss",
|
||||
"style": "./dist/css/cookie-notice-standard.css",
|
||||
"browserslist": "last 3 version, not dead, >0.3%",
|
||||
"directories": {
|
||||
"example": "examples"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npm run development",
|
||||
"development": "mix",
|
||||
"watch": "mix watch",
|
||||
"watch-poll": "mix watch -- --watch-options-poll=1000",
|
||||
"hot": "mix watch --hot",
|
||||
"build": "npm run production",
|
||||
"prod": "npm run production",
|
||||
"production": "mix --production",
|
||||
"eslint": "node ./node_modules/.bin/eslint -c .eslintrc.json ./src",
|
||||
"eslint-ci": "node ./node_modules/.bin/eslint -c .eslintrc.json ./src -f junit",
|
||||
"stylelint": "npx stylelint '**/*.scss'",
|
||||
"stylelint-ci": "npx stylelint '**/*.scss' -f json",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@lab.s-web.fr:ldc-web/projets/ldc-web-cookie-notice.git"
|
||||
},
|
||||
"keywords": [
|
||||
"cookie",
|
||||
"notice",
|
||||
|
|
@ -35,33 +20,50 @@
|
|||
],
|
||||
"author": "Equipe Web",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@lab.s-web.fr:ldc-web/projets/ldc-web-cookie-notice.git"
|
||||
},
|
||||
"browser": {
|
||||
"fs": false,
|
||||
"path": false
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prod": "npm run build",
|
||||
"build": "webpack --progress",
|
||||
"prebuild": "npm run stylelint && npm run eslint && tsc -p ./tsconfig.json",
|
||||
"eslint": "node ./node_modules/.bin/eslint -c .eslintrc.json ./src",
|
||||
"eslint-ci": "node ./node_modules/.bin/eslint -c .eslintrc.json ./src -f junit",
|
||||
"stylelint": "npx stylelint '**/*.scss'",
|
||||
"stylelint-ci": "npx stylelint '**/*.scss' -f json"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rushstack/eslint-patch": "^1.1.4",
|
||||
"@types/webpack-env": "^1.18.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"eslint": "^8.23.0",
|
||||
"@babel/preset-env": "^7.21.4",
|
||||
"@babel/preset-typescript": "^7.21.4",
|
||||
"@typescript-eslint/parser": "^5.58.0",
|
||||
"@vue/eslint-config-typescript": "^11.0.2",
|
||||
"babel-loader": "^9.1.2",
|
||||
"eslint": "^8.38.0",
|
||||
"eslint-config-typescript": "^3.0.0",
|
||||
"eslint-plugin-vue": "^9.10.0",
|
||||
"eslint-webpack-plugin": "^3.2.0",
|
||||
"laravel-mix": "^6.0.6",
|
||||
"laravel-mix-clean": "^0.1.0",
|
||||
"laravel-mix-eslint": "^0.2.0",
|
||||
"laravel-mix-polyfill": "^3.0.1",
|
||||
"laravel-mix-stylelint": "^1.0.0",
|
||||
"postcss": "^8.1.14",
|
||||
"prettier": "^2.7.1",
|
||||
"resolve-url-loader": "^5.0.0",
|
||||
"sass": "^1.54.8",
|
||||
"sass-loader": "^12.6.0",
|
||||
"stylelint": "^14.11.0",
|
||||
"stylelint-config-idiomatic-order": "^8.1.0",
|
||||
"stylelint-config-sass-guidelines": "^9.0.1",
|
||||
"stylelint-config-standard-scss": "^6.1.0",
|
||||
"stylelint-webpack-plugin": "^3.3.0",
|
||||
"ts-loader": "^9.3.1",
|
||||
"typescript": "^4.8.2",
|
||||
"typescript-eslint": "^0.0.1-alpha.0"
|
||||
"file-loader": "^6.2.0",
|
||||
"postcss": "^8.4.21",
|
||||
"postcss-scss": "^4.0.6",
|
||||
"prettier": "^2.8.7",
|
||||
"sass": "^1.61.0",
|
||||
"sass-loader": "^13.2.2",
|
||||
"stylelint": "^15.4.0",
|
||||
"stylelint-config-idiomatic-order": "^9.0.0",
|
||||
"stylelint-config-sass-guidelines": "^10.0.0",
|
||||
"stylelint-config-standard-scss": "^8.0.0",
|
||||
"stylelint-webpack-plugin": "^4.1.1",
|
||||
"typescript": "^5.0.4",
|
||||
"typescript-eslint": "^0.0.1-alpha.0",
|
||||
"webpack": "^5.78.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^3.30.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
858
src/index.ts
Normal file
858
src/index.ts
Normal file
|
|
@ -0,0 +1,858 @@
|
|||
export default class CookieNotice {
|
||||
browserCookieName = "cn-init";
|
||||
cookiePolicies: CookiePolicy = {
|
||||
sameSite: CookiePolicySameSite.lax,
|
||||
secure: "",
|
||||
};
|
||||
|
||||
config: Record<string, CookieOptions>;
|
||||
modalBg: HTMLDivElement;
|
||||
cookieContainer: HTMLDivElement;
|
||||
bannerContainer: HTMLDivElement;
|
||||
modalContainer: HTMLDivElement;
|
||||
|
||||
cookieShowModalBtn: HTMLButtonElement;
|
||||
cookieCloseModalBtn: HTMLButtonElement;
|
||||
bannerDetailsCollapseBtn: HTMLButtonElement;
|
||||
|
||||
bannerParaP: HTMLDivElement;
|
||||
detailsTextOpen: HTMLParagraphElement;
|
||||
detailsTextClose: HTMLParagraphElement;
|
||||
|
||||
bannerContent: HTMLDivElement;
|
||||
bannerDetails: HTMLDivElement;
|
||||
bannerDetailsContainer: HTMLDivElement;
|
||||
acceptAllBtn: HTMLButtonElement;
|
||||
denyAllBtn: HTMLButtonElement;
|
||||
customizeBtn: HTMLButtonElement;
|
||||
cookiesUnorderedList: HTMLUListElement;
|
||||
cookieLinkShowCustomizeModalList: NodeListOf<HTMLAnchorElement>;
|
||||
modalWrapper: HTMLDivElement;
|
||||
template: HTMLDivElement;
|
||||
bannerDetailsAreExpanded: boolean;
|
||||
|
||||
constructor(config: Record<string, CookieOptions>) {
|
||||
// * Setup Config
|
||||
this.config = config;
|
||||
|
||||
// * Inject DOM modal BG
|
||||
const modalBg = document.createElement("div");
|
||||
modalBg.classList.add("cn-modal-bg");
|
||||
document.body.append(modalBg);
|
||||
this.modalBg = modalBg;
|
||||
|
||||
// * Setup Dom Elements
|
||||
const cookieContainer = document.querySelector(
|
||||
"div#cn-wrapper"
|
||||
) as HTMLDivElement | null,
|
||||
cookieShowModalBtn = document.querySelector(
|
||||
"button#cn-cookie-btn"
|
||||
) as HTMLButtonElement | null,
|
||||
cookieCloseModalBtn = document.querySelector(
|
||||
"button#cn-close-modal"
|
||||
) as HTMLButtonElement | null,
|
||||
cookieLinkShowCustomizeModalPageList = document.querySelectorAll(
|
||||
"a.cn-cookie-link"
|
||||
) as NodeListOf<HTMLAnchorElement>,
|
||||
bannerContainer = document.querySelector(
|
||||
"div#cn-banner"
|
||||
) as HTMLDivElement | null,
|
||||
bannerContent = document.querySelector(
|
||||
"div.cn-banner-content"
|
||||
) as HTMLDivElement | null,
|
||||
bannerDetails = document.querySelector(
|
||||
"div.cn-banner-details"
|
||||
) as HTMLDivElement | null,
|
||||
bannerParaP = document.querySelector(
|
||||
"div.cn-banner-para-p"
|
||||
) as HTMLDivElement | null,
|
||||
detailsTextOpen = document.querySelector(
|
||||
"p.cn-banner-para-p-open"
|
||||
) as HTMLParagraphElement | null,
|
||||
detailsTextClose = document.querySelector(
|
||||
"p.cn-banner-para-p-close"
|
||||
) as HTMLParagraphElement | null,
|
||||
bannerDetailsCollapseBtn = document.querySelector(
|
||||
"button.cn-banner-btn-details-p"
|
||||
) as HTMLButtonElement | null,
|
||||
bannerDetailsContainer = document.querySelector(
|
||||
"div.cn-banner-btn-details"
|
||||
) as HTMLDivElement | null,
|
||||
modalContainer = document.querySelector(
|
||||
"div.cn-modal-container"
|
||||
) as HTMLDivElement | null,
|
||||
acceptAllBtn = document.querySelector(
|
||||
"button#cn-accept-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
denyAllBtn = document.querySelector(
|
||||
"button#cn-deny-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
customizeBtn = document.querySelector(
|
||||
"button#cn-settings-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
cookiesUnorderedList = document.querySelector(
|
||||
"ul#cn-modal-list"
|
||||
) as HTMLUListElement | null,
|
||||
modalWrapper = document.querySelector(
|
||||
"div.cn-modal-wrapper"
|
||||
) as HTMLDivElement,
|
||||
template = document.querySelector(
|
||||
"div#cn-li-template"
|
||||
) as HTMLDivElement | null;
|
||||
if (!cookieContainer) {
|
||||
throw new Error("Cannot find div#cn-wrapper");
|
||||
}
|
||||
if (!cookieShowModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-cookie-btn' element");
|
||||
}
|
||||
if (!cookieCloseModalBtn) {
|
||||
throw new Error("Cannot find 'button#cn-close-modal' element");
|
||||
}
|
||||
if (!bannerContainer) {
|
||||
throw new Error("Cannot find 'div#cn-banner' element");
|
||||
}
|
||||
if (!bannerContent) {
|
||||
throw new Error("Cannot find 'div.cn-banner-content' element");
|
||||
}
|
||||
if (!bannerDetails) {
|
||||
throw new Error("Cannot find 'div.cn-banner-details' element");
|
||||
}
|
||||
if (!bannerParaP) {
|
||||
throw new Error("Cannot find 'div.cn-banner-para-p' element");
|
||||
}
|
||||
if (!detailsTextOpen) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-open' element");
|
||||
}
|
||||
if (!detailsTextClose) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-close' element");
|
||||
}
|
||||
if (!bannerDetailsCollapseBtn) {
|
||||
throw new Error(
|
||||
"Cannot find 'button.cn-banner-btn-details-p' element"
|
||||
);
|
||||
}
|
||||
if (!bannerDetailsContainer) {
|
||||
throw new Error("Cannot find '.cn-banner-btn-details' element");
|
||||
}
|
||||
if (!modalContainer) {
|
||||
throw new Error("Cannot find 'div.cn-modal-container' element");
|
||||
}
|
||||
if (!acceptAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-accept-banner' element");
|
||||
}
|
||||
if (!denyAllBtn) {
|
||||
throw new Error("Cannot find 'button#cn-deny-banner' element");
|
||||
}
|
||||
if (!customizeBtn) {
|
||||
throw new Error("Cannot find 'button.cn-settings-banner' element");
|
||||
}
|
||||
if (!cookiesUnorderedList) {
|
||||
throw new Error("Cannot find 'ul#cn-modal-list' element");
|
||||
}
|
||||
if (!modalWrapper) {
|
||||
throw new Error("Cannot find 'div.cn-modal-wrapper' element");
|
||||
}
|
||||
if (!template) {
|
||||
throw new Error("Cannot find 'div#cn-li-template' element");
|
||||
}
|
||||
|
||||
this.cookieShowModalBtn = cookieShowModalBtn;
|
||||
this.cookieCloseModalBtn = cookieCloseModalBtn;
|
||||
this.cookieLinkShowCustomizeModalList =
|
||||
cookieLinkShowCustomizeModalPageList;
|
||||
this.cookieContainer = cookieContainer;
|
||||
this.bannerDetailsContainer = bannerDetailsContainer;
|
||||
this.bannerContainer = bannerContainer;
|
||||
this.bannerContent = bannerContent;
|
||||
this.cookiesUnorderedList = cookiesUnorderedList;
|
||||
this.modalWrapper = modalWrapper;
|
||||
this.bannerParaP = bannerParaP;
|
||||
this.detailsTextOpen = detailsTextOpen;
|
||||
this.detailsTextClose = detailsTextClose;
|
||||
this.bannerDetails = bannerDetails;
|
||||
this.bannerDetailsCollapseBtn = bannerDetailsCollapseBtn;
|
||||
this.modalContainer = modalContainer;
|
||||
this.acceptAllBtn = acceptAllBtn;
|
||||
this.denyAllBtn = denyAllBtn;
|
||||
this.customizeBtn = customizeBtn;
|
||||
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
this.template = template;
|
||||
const memoryTemplate = this.template.cloneNode(true) as HTMLDivElement;
|
||||
this.template.remove();
|
||||
this.template = memoryTemplate;
|
||||
|
||||
// * Setup Events
|
||||
this.addEventPrevent(this.modalBg, "click", this.closeCookieModal);
|
||||
this.addEventPrevent(
|
||||
this.cookieCloseModalBtn,
|
||||
"click",
|
||||
this.closeCookieModal
|
||||
);
|
||||
this.addEventPrevent(this.acceptAllBtn, "click", this.acceptAllCookies);
|
||||
this.addEventPrevent(this.denyAllBtn, "click", this.denyAllCookies);
|
||||
this.addEventPrevent(
|
||||
this.customizeBtn,
|
||||
"click",
|
||||
this.toggleCookieModalPages
|
||||
);
|
||||
this.addEventPrevent(
|
||||
this.bannerDetailsCollapseBtn,
|
||||
"click",
|
||||
this.toggleBannerDetails
|
||||
);
|
||||
this.addEventPrevent(
|
||||
this.cookieShowModalBtn,
|
||||
"click",
|
||||
this.toggleCookieModal
|
||||
);
|
||||
this.cookieLinkShowCustomizeModalList.forEach((cookieLink) => {
|
||||
this.addEventPrevent(
|
||||
cookieLink,
|
||||
"click",
|
||||
this.openCookieModalToCookiePage
|
||||
);
|
||||
});
|
||||
|
||||
// * Setup CN Cookie
|
||||
if (!this.cookiesMatchesConfig()) {
|
||||
// * Setup Browser Cookie if none.
|
||||
this.resetBrowserCookie();
|
||||
this.openCookieModalToBannerPage();
|
||||
}
|
||||
|
||||
// * Cookie should have been created from here.
|
||||
const cookies = this.getCookieStatusList();
|
||||
Object.entries(cookies).forEach(([cookieName, cookieStatus]) => {
|
||||
if (cookieStatus === CookieStatus.wait) {
|
||||
// * Open modal if any cookie config is not set.
|
||||
this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
if (!this.config[cookieName]) {
|
||||
// * Ignore missing config
|
||||
return;
|
||||
}
|
||||
if (cookieStatus === CookieStatus.true) {
|
||||
// * Exec script part for accepted cookie.
|
||||
this.config[cookieName].script();
|
||||
return;
|
||||
}
|
||||
if (this.config[cookieName].fallback != null) {
|
||||
// * Exec fallback part for accepted cookie if provided.
|
||||
this.config[cookieName].fallback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// COOKIES
|
||||
|
||||
/**
|
||||
* Check if the actual cookie matches the config
|
||||
*/
|
||||
cookiesMatchesConfig(): boolean {
|
||||
const cookies = this.getCookieStatusList();
|
||||
return Object.keys(cookies).length === Object.keys(this.config).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a specific cookie
|
||||
*/
|
||||
acceptAllCookies() {
|
||||
Object.entries(this.config).forEach(([cookieName, cookieOption]) =>
|
||||
this.setCookieStatus(cookieName, CookieStatus.true, cookieOption)
|
||||
);
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(
|
||||
".accept > label"
|
||||
)) {
|
||||
acceptLabel.classList.add("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(
|
||||
".deny > label"
|
||||
)) {
|
||||
denyLabel.classList.remove("active");
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deny a specific cookie
|
||||
*/
|
||||
denyAllCookies() {
|
||||
Object.entries(this.config).forEach(([cookieName, cookieOption]) =>
|
||||
this.setCookieStatus(cookieName, CookieStatus.false, cookieOption)
|
||||
);
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(
|
||||
".accept > label"
|
||||
)) {
|
||||
acceptLabel.classList.remove("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(
|
||||
".deny > label"
|
||||
)) {
|
||||
denyLabel.classList.add("active");
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cookie status list
|
||||
*
|
||||
* @returns the cookie status list
|
||||
*/
|
||||
getCookieStatusList(): CookieStatusList {
|
||||
const cookies = this.getBrowserCookieValue(),
|
||||
statusList: CookieStatusList = {};
|
||||
if (cookies === undefined) {
|
||||
return statusList;
|
||||
}
|
||||
/** specificCookieString contains youtube=true like */
|
||||
cookies.split(",").forEach((specificCookieString) => {
|
||||
const values = specificCookieString.split("=");
|
||||
statusList[values[0]] = values[1] as CookieStatus;
|
||||
});
|
||||
return statusList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check has cookie status
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
containsCookieStatus(key: string): boolean {
|
||||
const statusList: CookieStatusList = this.getCookieStatusList();
|
||||
return (
|
||||
Object.keys(statusList).find((cookieName) => cookieName === key) !==
|
||||
undefined
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cookie value
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
* @param cookieOption
|
||||
*/
|
||||
setCookieStatus(
|
||||
cookieName: string,
|
||||
status: CookieStatus,
|
||||
cookieOption: CookieOptions
|
||||
) {
|
||||
if (status === CookieStatus.true) {
|
||||
this.addCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
if (status === CookieStatus.false) {
|
||||
this.removeCookieStatus(cookieName, cookieOption);
|
||||
return;
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.wait);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a specific cookie and
|
||||
* change his status to true
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
addCookieStatus(cookieName: string, cookieOption: CookieOptions) {
|
||||
if (cookieOption.script) {
|
||||
cookieOption.script();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specific cookie and
|
||||
* change his status to false
|
||||
*
|
||||
* @param cookieName
|
||||
* @param cookieOption
|
||||
*/
|
||||
removeCookieStatus(cookieName: string, cookieOption: CookieOptions) {
|
||||
const cookieNameElement = document.getElementById(cookieName);
|
||||
if (cookieNameElement) {
|
||||
cookieNameElement.remove();
|
||||
}
|
||||
if (cookieOption.fallback) {
|
||||
cookieOption.fallback();
|
||||
}
|
||||
this.setBrowserCookieStatus(cookieName, CookieStatus.false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the status of a cookie
|
||||
*
|
||||
* @param cookieName
|
||||
* @param status
|
||||
*/
|
||||
setBrowserCookieStatus(cookieName: string, status: CookieStatus) {
|
||||
const statusList: CookieStatusList = this.getCookieStatusList();
|
||||
// * Force refresh
|
||||
this.deleteBrowserCookie();
|
||||
statusList[cookieName] = status;
|
||||
this.saveBrowserCookie(statusList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Has CN cokie setup ?
|
||||
* @returns true if the cookie is setup
|
||||
*/
|
||||
hasBrowserCookie(): boolean {
|
||||
return Boolean(this.getBrowserCookieValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Ldcweb cookie
|
||||
*
|
||||
* @returns A string like analytics=true,youtube=true or undefined
|
||||
*/
|
||||
getBrowserCookieValue() {
|
||||
const matches = document.cookie.match(
|
||||
new RegExp(
|
||||
"(?:^|; )" +
|
||||
this.browserCookieName.replace(
|
||||
/([.$?*|{}()[\]\\/+^])/g,
|
||||
"\\$1"
|
||||
) +
|
||||
"=([^;]*)"
|
||||
)
|
||||
);
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save cookie content on web browser
|
||||
*
|
||||
* @param list
|
||||
*/
|
||||
saveBrowserCookie(statusList: CookieStatusList) {
|
||||
const date = new Date(),
|
||||
newDate = new Date(date.setMonth(date.getMonth() + 13)),
|
||||
content = Object.entries(statusList)
|
||||
.map(([cookieName, cookieStatus]) => {
|
||||
return `${cookieName}=${cookieStatus}`;
|
||||
})
|
||||
.join(",");
|
||||
document.cookie = `${this.browserCookieName}=${content};path=/${
|
||||
location.hostname ? `;domain=${location.hostname}` : ""
|
||||
};expires=${newDate.toUTCString()};${this.getCookiePoliciesAsString()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an older expire parameter to a specific cookie
|
||||
*/
|
||||
deleteBrowserCookie() {
|
||||
if (this.hasBrowserCookie()) {
|
||||
// * Suppression du cookie et de sa version precedé d'un point
|
||||
document.cookie = `${this.browserCookieName}=;path=/${
|
||||
location.hostname ? `;domain=.${location.hostname}` : ""
|
||||
};expires=Thu, 01 Jan 1970 00:00:01 GMT;${this.getCookiePoliciesAsString()}`;
|
||||
document.cookie = `${this.browserCookieName}=;path=/${
|
||||
location.hostname ? `;domain=${location.hostname}` : ""
|
||||
};expires=Thu, 01 Jan 1970 00:00:01 GMT;${this.getCookiePoliciesAsString()}`;
|
||||
}
|
||||
}
|
||||
|
||||
getCookiePoliciesAsString(): string {
|
||||
return Object.entries(this.cookiePolicies)
|
||||
.map(([policyName, policyValue]) => `${policyName}=${policyValue}`)
|
||||
.join(";");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset Ldc Web CN cookie
|
||||
*/
|
||||
resetBrowserCookie() {
|
||||
// * Create Cookie as It does not exists.
|
||||
const newCookieList: CookieStatusList = {};
|
||||
Object.entries(this.config).forEach(
|
||||
([cookieName]) => (newCookieList[cookieName] = CookieStatus.wait)
|
||||
);
|
||||
this.saveBrowserCookie(newCookieList);
|
||||
}
|
||||
|
||||
// LISTENERS
|
||||
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEvent(element: HTMLElement, evnt: string, funct: (e: Event) => void) {
|
||||
return element.addEventListener(evnt, funct.bind(this), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add event on a specific element and prevent default
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventPrevent(
|
||||
element: HTMLElement,
|
||||
evnt: string,
|
||||
funct: (e: Event) => void
|
||||
) {
|
||||
return element.addEventListener(
|
||||
evnt,
|
||||
(e) => {
|
||||
e.preventDefault();
|
||||
funct.call(this, e);
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventKbdValidate(element: HTMLElement, funct: (e: Event) => void) {
|
||||
return this.addEvent(element, "keyup", (e: Event) => {
|
||||
const kbdEvt = e as KeyboardEvent;
|
||||
if (
|
||||
kbdEvt.key == " " ||
|
||||
kbdEvt.code == "Space" ||
|
||||
kbdEvt.keyCode == 32 ||
|
||||
kbdEvt.key == "Enter" ||
|
||||
kbdEvt.code == "Enter" ||
|
||||
kbdEvt.keyCode == 13
|
||||
) {
|
||||
funct.call(this, kbdEvt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// COOKIE MODAL
|
||||
|
||||
/**
|
||||
* Show or hide Cookie modal
|
||||
* @returns
|
||||
*/
|
||||
toggleCookieModal() {
|
||||
if (!document.body.classList.contains("cn-open")) {
|
||||
this.openCookieModalToBannerPage();
|
||||
return;
|
||||
}
|
||||
this.closeCookieModal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the cookies modal to the banner page
|
||||
*/
|
||||
openCookieModalToBannerPage() {
|
||||
this.openCookieModalToCookiePage();
|
||||
this.toggleCookieModalPages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the cookies modal to the cookies page
|
||||
*/
|
||||
openCookieModalToCookiePage() {
|
||||
document.body.classList.add("cn-open");
|
||||
this.resetCookieModal();
|
||||
|
||||
this.bannerContent.classList.add("d-none");
|
||||
this.bannerDetails.classList.add("d-none");
|
||||
this.bannerDetailsContainer.classList.add("d-none");
|
||||
this.modalContainer.classList.remove("d-none");
|
||||
// Scroll to the top of the cookies list
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
this.setupCookieModalList();
|
||||
this.setTabIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the cookies modal
|
||||
*/
|
||||
closeCookieModal() {
|
||||
document.body.classList.remove("cn-open");
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.unsetTabIndex();
|
||||
this.setupCookieModalList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup tab indexes on visible elements
|
||||
*/
|
||||
setTabIndex() {
|
||||
// * Prevent focus html tag
|
||||
document.documentElement.setAttribute("tabindex", "-1");
|
||||
setTimeout(() => {
|
||||
const focusableSelector =
|
||||
"a[href], button, [role=\"button\"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])";
|
||||
|
||||
// * Only focusable elements
|
||||
[...document.body.querySelectorAll(focusableSelector)]
|
||||
.filter(
|
||||
(el) =>
|
||||
!el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden")
|
||||
)
|
||||
.forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "-1");
|
||||
(el as HTMLElement).classList.add("cn-disabled");
|
||||
});
|
||||
[...this.cookieContainer.querySelectorAll(focusableSelector)]
|
||||
.filter(
|
||||
(el) =>
|
||||
!el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden") &&
|
||||
// * Only visible elements
|
||||
!!(
|
||||
(el as HTMLElement).offsetWidth ||
|
||||
(el as HTMLElement).offsetHeight ||
|
||||
el.getClientRects().length
|
||||
)
|
||||
)
|
||||
.forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "0");
|
||||
(el as HTMLElement).classList.remove("cn-disabled");
|
||||
});
|
||||
this.cookieShowModalBtn.setAttribute("tabindex", "-1");
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo setup tab indexes on visible elements
|
||||
*/
|
||||
unsetTabIndex() {
|
||||
document.documentElement.setAttribute("tabindex", "0");
|
||||
setTimeout(() => {
|
||||
document.body.querySelectorAll(".cn-disabled").forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "0");
|
||||
(el as HTMLElement).classList.remove("cn-disabled");
|
||||
});
|
||||
this.cookieShowModalBtn.setAttribute("tabindex", "0");
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the modal view state
|
||||
*/
|
||||
resetCookieModal() {
|
||||
this.bannerContent.classList.remove("d-none");
|
||||
this.bannerDetails.classList.remove("d-none");
|
||||
this.bannerDetailsContainer.classList.remove("d-none");
|
||||
this.modalContainer.classList.add("d-none");
|
||||
if (!this.customizeBtn.dataset.openModal) {
|
||||
throw new Error("Cannot find attribut data-open-modal");
|
||||
}
|
||||
this.customizeBtn.innerHTML = this.customizeBtn.dataset.openModal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cookies list in the modal
|
||||
*/
|
||||
setupCookieModalList() {
|
||||
this.cookiesUnorderedList.innerHTML = "";
|
||||
Object.entries(this.config).forEach(([cookieName, cookieConfig]) => {
|
||||
const cookie = document.createElement("li");
|
||||
const childItem = this.template.children.item(
|
||||
0
|
||||
) as HTMLDivElement | null;
|
||||
if (childItem === null) {
|
||||
throw new Error("Cannot find child item");
|
||||
}
|
||||
cookie.append(childItem.cloneNode(true));
|
||||
const name = cookie.querySelector(
|
||||
"span.cn-cookie-name"
|
||||
) as HTMLSpanElement;
|
||||
const description = cookie.querySelector(
|
||||
"span.cn-cookie-description"
|
||||
) as HTMLSpanElement;
|
||||
const link = cookie.querySelector(
|
||||
".cn-cookie-link"
|
||||
) as HTMLButtonElement;
|
||||
const acceptInput = cookie.querySelector(
|
||||
".accept > input"
|
||||
) as HTMLInputElement;
|
||||
const denyInput = cookie.querySelector(
|
||||
".deny > input"
|
||||
) as HTMLInputElement;
|
||||
const acceptLabel = cookie.querySelector(
|
||||
".accept > label"
|
||||
) as HTMLLabelElement;
|
||||
const denyLabel = cookie.querySelector(
|
||||
".deny > label"
|
||||
) as HTMLLabelElement;
|
||||
|
||||
name.textContent = cookieConfig.name;
|
||||
description.textContent = cookieConfig.description;
|
||||
link.textContent = cookieConfig.labelLink;
|
||||
link.setAttribute("href", cookieConfig.link);
|
||||
acceptInput.id = cookieName + "1";
|
||||
acceptInput.name = cookieName;
|
||||
acceptInput.dataset.name = cookieName;
|
||||
acceptLabel.htmlFor = cookieName + "1";
|
||||
denyInput.id = cookieName + "2";
|
||||
denyInput.name = cookieName;
|
||||
denyInput.dataset.name = cookieName;
|
||||
denyLabel.htmlFor = cookieName + "2";
|
||||
|
||||
const acceptFn = () => {
|
||||
acceptLabel.classList.add("active");
|
||||
denyLabel.classList.remove("active");
|
||||
this.setCookieStatus(
|
||||
cookieName,
|
||||
CookieStatus.true,
|
||||
cookieConfig
|
||||
);
|
||||
},
|
||||
denyFn = () => {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.add("active");
|
||||
this.setCookieStatus(
|
||||
cookieName,
|
||||
CookieStatus.false,
|
||||
cookieConfig
|
||||
);
|
||||
};
|
||||
this.addEvent(acceptInput, "click", acceptFn);
|
||||
this.addEventKbdValidate(acceptLabel, acceptFn);
|
||||
this.addEvent(denyInput, "click", denyFn);
|
||||
this.addEventKbdValidate(denyLabel, denyFn);
|
||||
|
||||
this.cookiesUnorderedList.append(cookie);
|
||||
|
||||
if (!this.hasBrowserCookie()) {
|
||||
// * Ldcweb cookie is not set.
|
||||
return;
|
||||
}
|
||||
// * Setup list status state
|
||||
Object.entries(this.getCookieStatusList()).forEach(
|
||||
([ckName, cookieStatus]) => {
|
||||
if (ckName === cookieName) {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.remove("active");
|
||||
switch (cookieStatus) {
|
||||
case CookieStatus.true:
|
||||
acceptLabel.classList.add("active");
|
||||
break;
|
||||
case CookieStatus.false:
|
||||
denyLabel.classList.add("active");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle show hide banner details
|
||||
*/
|
||||
toggleBannerDetails() {
|
||||
this.bannerDetails.classList.toggle("cn-details-open");
|
||||
|
||||
if (
|
||||
!this.bannerDetailsCollapseBtn.dataset.open ||
|
||||
!this.bannerDetailsCollapseBtn.dataset.close
|
||||
) {
|
||||
throw new Error("Cannot find attribute data-open or data-close");
|
||||
}
|
||||
|
||||
if (this.bannerDetailsAreExpanded) {
|
||||
this.bannerDetailsCollapseBtn.innerHTML =
|
||||
this.bannerDetailsCollapseBtn.dataset.close;
|
||||
this.detailsTextOpen.classList.add("d-none");
|
||||
this.detailsTextClose.classList.remove("d-none");
|
||||
this.bannerDetails.style.height = "0px";
|
||||
this.bannerDetailsAreExpanded = false;
|
||||
} else {
|
||||
this.bannerDetailsCollapseBtn.innerHTML =
|
||||
this.bannerDetailsCollapseBtn.dataset.open;
|
||||
this.detailsTextOpen.classList.remove("d-none");
|
||||
this.detailsTextClose.classList.add("d-none");
|
||||
this.bannerDetails.style.height =
|
||||
this.bannerDetails.children[0].clientHeight + "px";
|
||||
this.bannerDetailsAreExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle Cookie modal pages
|
||||
*/
|
||||
toggleCookieModalPages() {
|
||||
this.bannerContent.classList.toggle("d-none");
|
||||
this.bannerDetails.classList.toggle("d-none");
|
||||
this.bannerDetailsContainer.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.setTabIndex();
|
||||
this.setupCookieModalList();
|
||||
this.togglePersonalizeBtn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle customize btn
|
||||
*/
|
||||
togglePersonalizeBtn() {
|
||||
const customizeBtnBannerDataset = this.customizeBtn.dataset;
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
if (this.bannerContent.classList.contains("d-none")) {
|
||||
this.customizeBtn.innerHTML =
|
||||
customizeBtnBannerDataset.openModal as string;
|
||||
} else {
|
||||
this.customizeBtn.innerHTML =
|
||||
customizeBtnBannerDataset.closeModal as string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CookieStatus {
|
||||
true = "true",
|
||||
false = "false",
|
||||
wait = "wait",
|
||||
}
|
||||
|
||||
type CookieStatusList = Record<string, keyof typeof CookieStatus>;
|
||||
|
||||
type CookiePolicy = {
|
||||
sameSite: CookiePolicySameSite;
|
||||
secure: string;
|
||||
};
|
||||
|
||||
enum CookiePolicySameSite {
|
||||
lax = "lax",
|
||||
strict = "strict",
|
||||
none = "none",
|
||||
}
|
||||
|
||||
export type CookieOptions = {
|
||||
name: string;
|
||||
description: string;
|
||||
link: string;
|
||||
labelLink: string;
|
||||
cookies: string[];
|
||||
/**
|
||||
* Fonction qui sert à initialiser la fonctionnalité
|
||||
* conduisant à la génération du cookie
|
||||
* @return void
|
||||
*/
|
||||
script: () => void;
|
||||
/**
|
||||
* Fonction qui sert à informer l'utilisateur
|
||||
* sur chaque élèment que le cookie
|
||||
* associé à la fonctionnalité
|
||||
* est désactivé et propose un lien sur
|
||||
* cookie notice pour l'activer
|
||||
* @return void
|
||||
*/
|
||||
fallback: () => void | null;
|
||||
};
|
||||
51
src/scss/themes/standard.scss
vendored
51
src/scss/themes/standard.scss
vendored
|
|
@ -82,6 +82,26 @@ $breakpoint-mobile: 535px;
|
|||
}
|
||||
}
|
||||
|
||||
// * Prevent click on clickable element using cookie notice
|
||||
|
||||
.cn-modal-bg {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cn-open .cn-modal-bg {
|
||||
position: fixed;
|
||||
z-index: 1030;
|
||||
top: 0;
|
||||
display: block;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgb(0 0 0 / 60%);
|
||||
}
|
||||
|
||||
.cn-disabled {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
#cn-wrapper {
|
||||
@extend %reset-styles;
|
||||
// Display over BS elements
|
||||
|
|
@ -96,8 +116,8 @@ $breakpoint-mobile: 535px;
|
|||
width: 3rem;
|
||||
height: 3rem;
|
||||
padding: 0.5rem;
|
||||
background-color: $ck-btn-background-color;
|
||||
border-radius: 100%;
|
||||
background-color: $ck-btn-background-color;
|
||||
box-shadow: $ck-shadow-color;
|
||||
cursor: pointer;
|
||||
|
||||
|
|
@ -134,10 +154,10 @@ $breakpoint-mobile: 535px;
|
|||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
margin: auto;
|
||||
margin-bottom: 0;
|
||||
background-color: $ck-bg-color;
|
||||
border-radius: 0;
|
||||
box-shadow: $ck-shadow-color;
|
||||
line-height: initial;
|
||||
opacity: 0;
|
||||
|
|
@ -147,15 +167,31 @@ $breakpoint-mobile: 535px;
|
|||
user-select: none;
|
||||
visibility: hidden;
|
||||
|
||||
.cn-modal-top-line {
|
||||
align-self: end;
|
||||
|
||||
#cn-close-modal {
|
||||
width: 4rem;
|
||||
height: 3rem;
|
||||
border-bottom-left-radius: 0.5rem;
|
||||
|
||||
@media (min-width: $breakpoint-mobile) {
|
||||
width: 3rem;
|
||||
height: 2rem;
|
||||
border-top-right-radius: 0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * allow child body scroll
|
||||
> * {
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
@media (min-width: $breakpoint-mobile) {
|
||||
right: $ldcweb-cn-animation-right;
|
||||
right: $cn-cookie-animation-right;
|
||||
bottom: calc($cn-cookie-button-position-bottom + 60px);
|
||||
left: $ldcweb-cn-animation-left;
|
||||
left: $cn-cookie-animation-left;
|
||||
width: 30rem;
|
||||
height: auto;
|
||||
max-height: 26rem;
|
||||
|
|
@ -302,8 +338,8 @@ $breakpoint-mobile: 535px;
|
|||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
border: 1px solid $ck-bgcolor-list;
|
||||
margin: 10px 0;
|
||||
border-radius: 20px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
span {
|
||||
|
|
@ -325,7 +361,7 @@ $breakpoint-mobile: 535px;
|
|||
}
|
||||
}
|
||||
|
||||
.ldcweb-cn {
|
||||
.cn-cookie {
|
||||
&-name {
|
||||
color: $ck-color-title;
|
||||
}
|
||||
|
|
@ -341,7 +377,7 @@ $breakpoint-mobile: 535px;
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ldcweb-cn-description {
|
||||
.cn-cookie-description {
|
||||
color: $ck-w2-color-txt;
|
||||
}
|
||||
|
||||
|
|
@ -449,6 +485,7 @@ $breakpoint-mobile: 535px;
|
|||
width: 50%;
|
||||
border-right: 1px solid $ck-borders-color;
|
||||
border-left: 1px solid $ck-borders-color;
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
#cn-settings-banner {
|
||||
|
|
|
|||
4
src/scss/variables.scss
vendored
4
src/scss/variables.scss
vendored
|
|
@ -24,8 +24,8 @@ $cn-cookie-button-z-index: 1050 !default;
|
|||
$cn-cookie-button-position-left: 1rem; /* Distance par rapport à la gauche de la fenêtre */
|
||||
$cn-cookie-button-position-right: auto; /* Distance par rapport à la droite de la fenêtre */
|
||||
$cn-cookie-button-position-bottom: 1rem; /* Distance par rapport au bas de la fenêtre */
|
||||
$ldcweb-cn-animation-left: 0; /* Position gauche de base des cookies */
|
||||
$ldcweb-cn-animation-right: auto; /* Position droite de base des cookies */
|
||||
$cn-cookie-animation-left: 0; /* Position gauche de base des cookies */
|
||||
$cn-cookie-animation-right: auto; /* Position droite de base des cookies */
|
||||
// Buttons
|
||||
$cn-button-bg-color: $ck-primary-color !default;
|
||||
$cn-button-font-family: $ck-text-font !default;
|
||||
|
|
|
|||
|
|
@ -1,764 +0,0 @@
|
|||
export enum CookieStatus {
|
||||
true = "true",
|
||||
false = "false",
|
||||
wait = "wait",
|
||||
}
|
||||
|
||||
export type CookieOptions = {
|
||||
name: string;
|
||||
description: string;
|
||||
link: string;
|
||||
labelLink: string;
|
||||
cookies: string[];
|
||||
/**
|
||||
* Fonction qui sert à initialiser la fonctionnalité
|
||||
* conduisant à la génération du cookie
|
||||
* @return void
|
||||
*/
|
||||
script: () => void;
|
||||
/**
|
||||
* Fonction qui sert à informer l'utilisateur
|
||||
* sur chaque élèment que le cookie
|
||||
* associé à la fonctionnalité
|
||||
* est désactivé et propose un lien sur
|
||||
* cookie notice pour l'activer
|
||||
* @return void
|
||||
*/
|
||||
fallback: () => void | null;
|
||||
};
|
||||
|
||||
export default class LdcwebCn {
|
||||
config: Record<string, CookieOptions>;
|
||||
cookieContainer: HTMLDivElement;
|
||||
bannerContainer: HTMLDivElement;
|
||||
bannerBtn: HTMLButtonElement;
|
||||
ldcwebCookieBtn: HTMLButtonElement;
|
||||
|
||||
ldcwebBannerParaP: HTMLDivElement;
|
||||
detailsTextOpen: HTMLParagraphElement;
|
||||
detailsTextClose: HTMLParagraphElement;
|
||||
|
||||
ldcwebBannerContent: HTMLDivElement;
|
||||
ldcwebBannerDetails: HTMLDivElement;
|
||||
ldcwebBannerBtnDetails: HTMLDivElement;
|
||||
modalContainer: HTMLDivElement;
|
||||
acceptAllBtnBanner: HTMLButtonElement;
|
||||
denyAllBtnBanner: HTMLButtonElement;
|
||||
personalizeBtnBanner: HTMLButtonElement;
|
||||
changeBtn: NodeListOf<HTMLInputElement>;
|
||||
cookiesList: HTMLUListElement;
|
||||
cookieLinks: NodeListOf<HTMLAnchorElement>;
|
||||
modalWrapper: HTMLDivElement;
|
||||
template: HTMLDivElement;
|
||||
modalBtnBoolean: boolean;
|
||||
bannerBtnTextBoolean: boolean;
|
||||
|
||||
constructor(config: Record<string, CookieOptions>) {
|
||||
// * INITIALIZE VARS
|
||||
|
||||
this.config = config;
|
||||
const cookieContainer = document.querySelector(
|
||||
"div#cn-wrapper"
|
||||
) as HTMLDivElement | null,
|
||||
ldcwebCookieBtn = document.querySelector(
|
||||
"button#cn-cookie-btn"
|
||||
) as HTMLButtonElement | null,
|
||||
bannerContainer = document.querySelector(
|
||||
"div#cn-banner"
|
||||
) as HTMLDivElement | null,
|
||||
ldcwebBannerContent = document.querySelector(
|
||||
"div.cn-banner-content"
|
||||
) as HTMLDivElement | null,
|
||||
ldcwebBannerDetails = document.querySelector(
|
||||
"div.cn-banner-details"
|
||||
) as HTMLDivElement | null,
|
||||
ldcwebBannerParaP = document.querySelector(
|
||||
"div.cn-banner-para-p"
|
||||
) as HTMLDivElement | null,
|
||||
detailsTextOpen = document.querySelector(
|
||||
"p.cn-banner-para-p-open"
|
||||
) as HTMLParagraphElement | null,
|
||||
detailsTextClose = document.querySelector(
|
||||
"p.cn-banner-para-p-close"
|
||||
) as HTMLParagraphElement | null,
|
||||
bannerBtn = document.querySelector(
|
||||
"button.cn-banner-btn-details-p"
|
||||
) as HTMLButtonElement | null,
|
||||
ldcwebBannerBtnDetails = document.querySelector(
|
||||
"div.cn-banner-btn-details"
|
||||
) as HTMLDivElement | null,
|
||||
modalContainer = document.querySelector(
|
||||
"div.cn-modal-container"
|
||||
) as HTMLDivElement | null,
|
||||
acceptAllBtnBanner = document.querySelector(
|
||||
"button#cn-accept-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
denyAllBtnBanner = document.querySelector(
|
||||
"button#cn-deny-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
personalizeBtnBanner = document.querySelector(
|
||||
"button#cn-settings-banner"
|
||||
) as HTMLButtonElement | null,
|
||||
changeBtn = document.querySelectorAll(
|
||||
"input.ldcweb-cn-change"
|
||||
) as NodeListOf<HTMLInputElement>,
|
||||
cookiesList = document.querySelector(
|
||||
"ul#ldcweb-cn-list"
|
||||
) as HTMLUListElement | null,
|
||||
cookieLinks = document.querySelectorAll(
|
||||
"a.ldcweb-cn-cookie-link"
|
||||
) as NodeListOf<HTMLAnchorElement>,
|
||||
modalWrapper = document.querySelector(
|
||||
"div.cn-modal-wrapper"
|
||||
) as HTMLDivElement,
|
||||
template = document.querySelector(
|
||||
"div#cn-li-template"
|
||||
) as HTMLDivElement | null;
|
||||
|
||||
if (!cookieContainer) {
|
||||
throw new Error("Cannot find div#cn-wrapper");
|
||||
}
|
||||
if (!ldcwebCookieBtn) {
|
||||
throw new Error("Cannot find 'button#cn-cookie-btn' element");
|
||||
}
|
||||
if (!bannerContainer) {
|
||||
throw new Error("Cannot find 'div#cn-banner' element");
|
||||
}
|
||||
if (!ldcwebBannerContent) {
|
||||
throw new Error("Cannot find 'div.cn-banner-content' element");
|
||||
}
|
||||
if (!ldcwebBannerDetails) {
|
||||
throw new Error("Cannot find 'div.cn-banner-details' element");
|
||||
}
|
||||
if (!ldcwebBannerParaP) {
|
||||
throw new Error("Cannot find 'div.cn-banner-para-p' element");
|
||||
}
|
||||
if (!detailsTextOpen) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-open' element");
|
||||
}
|
||||
if (!detailsTextClose) {
|
||||
throw new Error("Cannot find 'p.cn-banner-para-p-close' element");
|
||||
}
|
||||
if (!bannerBtn) {
|
||||
throw new Error(
|
||||
"Cannot find 'button.cn-banner-btn-details-p' element"
|
||||
);
|
||||
}
|
||||
if (!ldcwebBannerBtnDetails) {
|
||||
throw new Error("Cannot find '.cn-banner-btn-details' element");
|
||||
}
|
||||
if (!modalContainer) {
|
||||
throw new Error("Cannot find 'div.cn-modal-container' element");
|
||||
}
|
||||
if (!acceptAllBtnBanner) {
|
||||
throw new Error("Cannot find 'button#cn-accept-banner' element");
|
||||
}
|
||||
if (!denyAllBtnBanner) {
|
||||
throw new Error("Cannot find 'button#cn-deny-banner' element");
|
||||
}
|
||||
if (!personalizeBtnBanner) {
|
||||
throw new Error("Cannot find 'button.cn-settings-banner' element");
|
||||
}
|
||||
if (!cookiesList) {
|
||||
throw new Error("Cannot find 'ul#ldcweb-cn-list' element");
|
||||
}
|
||||
if (!modalWrapper) {
|
||||
throw new Error("Cannot find 'div.cn-modal-wrapper' element");
|
||||
}
|
||||
if (!template) {
|
||||
throw new Error("Cannot find 'div#cn-li-template' element");
|
||||
}
|
||||
|
||||
this.cookieContainer = cookieContainer;
|
||||
this.ldcwebCookieBtn = ldcwebCookieBtn;
|
||||
this.bannerContainer = bannerContainer;
|
||||
this.ldcwebBannerContent = ldcwebBannerContent;
|
||||
this.ldcwebBannerDetails = ldcwebBannerDetails;
|
||||
this.ldcwebBannerParaP = ldcwebBannerParaP;
|
||||
this.detailsTextOpen = detailsTextOpen;
|
||||
this.detailsTextClose = detailsTextClose;
|
||||
this.ldcwebBannerContent = ldcwebBannerContent;
|
||||
this.ldcwebBannerDetails = ldcwebBannerDetails;
|
||||
this.bannerBtn = bannerBtn;
|
||||
this.ldcwebBannerBtnDetails = ldcwebBannerBtnDetails;
|
||||
this.modalContainer = modalContainer;
|
||||
this.acceptAllBtnBanner = acceptAllBtnBanner;
|
||||
this.denyAllBtnBanner = denyAllBtnBanner;
|
||||
this.personalizeBtnBanner = personalizeBtnBanner;
|
||||
this.changeBtn = changeBtn;
|
||||
this.cookiesList = cookiesList;
|
||||
this.modalWrapper = modalWrapper;
|
||||
this.cookieLinks = cookieLinks;
|
||||
this.template = template;
|
||||
|
||||
this.modalBtnBoolean = false;
|
||||
this.bannerBtnTextBoolean = false;
|
||||
this.template = template;
|
||||
const memoryTemplate = this.template.cloneNode(true) as HTMLDivElement;
|
||||
this.template.remove();
|
||||
this.template = memoryTemplate;
|
||||
|
||||
// * LOGIC
|
||||
|
||||
const cookies = this.getLDCWebCookie("ldcwebcn-init");
|
||||
if (cookies === undefined) {
|
||||
const newCookie: string[] = [];
|
||||
|
||||
for (const [key] of Object.entries(this.config)) {
|
||||
newCookie.push(key + "=wait");
|
||||
}
|
||||
|
||||
this.openCookieModal();
|
||||
|
||||
this.saveLDCWebCookie(newCookie.join(","));
|
||||
} else {
|
||||
const test = cookies.split(",");
|
||||
test.forEach((elm) => {
|
||||
const test = elm.split("=");
|
||||
if (test[1] === "wait") {
|
||||
this.openCookieModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept a specific cookie
|
||||
*/
|
||||
const accept = (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
for (const [key, value] of Object.entries(this.config)) {
|
||||
this.addCookie(key, value);
|
||||
}
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(
|
||||
".accept > label"
|
||||
)) {
|
||||
acceptLabel.classList.add("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(
|
||||
".deny > label"
|
||||
)) {
|
||||
denyLabel.classList.remove("active");
|
||||
}
|
||||
this.hideCookieModal();
|
||||
};
|
||||
this.acceptAllBtnBanner.addEventListener("click", accept);
|
||||
|
||||
/**
|
||||
* Deny a specific cookie
|
||||
*/
|
||||
const deny = (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
for (const [key, value] of Object.entries(this.config)) {
|
||||
this.removeCookie(key, value);
|
||||
}
|
||||
for (const acceptLabel of this.cookieContainer.querySelectorAll(
|
||||
".accept > label"
|
||||
)) {
|
||||
acceptLabel.classList.remove("active");
|
||||
}
|
||||
for (const denyLabel of this.cookieContainer.querySelectorAll(
|
||||
".deny > label"
|
||||
)) {
|
||||
denyLabel.classList.add("active");
|
||||
}
|
||||
this.hideCookieModal();
|
||||
};
|
||||
this.denyAllBtnBanner.addEventListener("click", deny);
|
||||
|
||||
const openLdcwebCookies = (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
this.openCookieModal();
|
||||
};
|
||||
this.cookieLinks.forEach((cookieLink) => {
|
||||
cookieLink.addEventListener("click", openLdcwebCookies);
|
||||
});
|
||||
|
||||
/**
|
||||
* Show the modal with the list of all cookies
|
||||
*/
|
||||
const toggleCookiesModal = (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
this.ldcwebBannerContent.classList.toggle("d-none");
|
||||
this.ldcwebBannerDetails.classList.toggle("d-none");
|
||||
this.ldcwebBannerBtnDetails.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.setTabIndex();
|
||||
this.setCookieList();
|
||||
};
|
||||
this.personalizeBtnBanner.addEventListener("click", toggleCookiesModal);
|
||||
|
||||
this.personalizeBtnBanner.addEventListener("click", (e) => {
|
||||
e.preventDefault();
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
if (!this.modalBtnBoolean) {
|
||||
this.personalizeBtnOpen();
|
||||
this.modalBtnBoolean = true;
|
||||
} else {
|
||||
this.personalizeBtnClose();
|
||||
this.modalBtnBoolean = false;
|
||||
}
|
||||
});
|
||||
|
||||
this.setListenerOnChange();
|
||||
|
||||
const cookie = this.getLDCWebCookie("ldcwebcn-init");
|
||||
if (cookie === undefined) {
|
||||
throw Error("Ldcweb cookie is not set");
|
||||
}
|
||||
const test = cookie.split(",");
|
||||
test.forEach((elm) => {
|
||||
const test = elm.split("=");
|
||||
if (test[1] === "true") {
|
||||
this.config[test[0]].script();
|
||||
} else {
|
||||
if (this.config[test[0]].fallback != null) {
|
||||
this.config[test[0]].fallback();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.bannerBtn.addEventListener("click", () => {
|
||||
this.ldcwebBannerDetails.classList.toggle("cn-details-open");
|
||||
this.bannerBtn.classList.toggle("ldcweb-banner-btn-details-p-open");
|
||||
|
||||
if (!this.bannerBtn.dataset.open || !this.bannerBtn.dataset.close) {
|
||||
throw new Error(
|
||||
"Cannot find attribute data-open or data-close"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.bannerBtnTextBoolean) {
|
||||
this.bannerBtn.innerHTML = this.bannerBtn.dataset.close;
|
||||
this.detailsTextOpen.classList.add("d-none");
|
||||
this.detailsTextClose.classList.remove("d-none");
|
||||
this.ldcwebBannerDetails.style.height = "0px";
|
||||
this.bannerBtnTextBoolean = false;
|
||||
} else {
|
||||
this.bannerBtn.innerHTML = this.bannerBtn.dataset.open;
|
||||
this.detailsTextOpen.classList.remove("d-none");
|
||||
this.detailsTextClose.classList.add("d-none");
|
||||
this.ldcwebBannerDetails.style.height =
|
||||
this.ldcwebBannerDetails.children[0].clientHeight + "px";
|
||||
this.bannerBtnTextBoolean = true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Show the default vue of the cookies modal
|
||||
*/
|
||||
const resetVue = (e: { preventDefault: () => void }) => {
|
||||
e.preventDefault();
|
||||
this.openCookieModal();
|
||||
this.resetModalVue();
|
||||
};
|
||||
this.ldcwebCookieBtn.addEventListener("click", resetVue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cookies list in the modal
|
||||
*/
|
||||
setCookieList() {
|
||||
this.cookiesList.innerHTML = "";
|
||||
for (const [key, value] of Object.entries(this.config)) {
|
||||
const cookie = document.createElement("li");
|
||||
const childItem = this.template.children.item(
|
||||
0
|
||||
) as HTMLDivElement | null;
|
||||
if (childItem === null) {
|
||||
throw new Error("Cannot find child item");
|
||||
}
|
||||
cookie.append(childItem.cloneNode(true));
|
||||
const name = cookie.querySelector(
|
||||
"span.ldcweb-cn-name"
|
||||
) as HTMLSpanElement;
|
||||
const description = cookie.querySelector(
|
||||
"span.ldcweb-cn-description"
|
||||
) as HTMLSpanElement;
|
||||
const link = cookie.querySelector(
|
||||
".ldcweb-cn-link"
|
||||
) as HTMLButtonElement;
|
||||
const acceptInput = cookie.querySelector(
|
||||
".accept > input"
|
||||
) as HTMLInputElement;
|
||||
const denyInput = cookie.querySelector(
|
||||
".deny > input"
|
||||
) as HTMLInputElement;
|
||||
const acceptLabel = cookie.querySelector(
|
||||
".accept > label"
|
||||
) as HTMLLabelElement;
|
||||
const denyLabel = cookie.querySelector(
|
||||
".deny > label"
|
||||
) as HTMLLabelElement;
|
||||
|
||||
name.textContent = value.name;
|
||||
description.textContent = value.description;
|
||||
link.textContent = value.labelLink;
|
||||
link.setAttribute("href", value.link);
|
||||
acceptInput.id = key + "1";
|
||||
acceptInput.name = key;
|
||||
acceptInput.dataset.name = key;
|
||||
acceptLabel.htmlFor = key + "1";
|
||||
denyInput.id = key + "2";
|
||||
denyInput.name = key;
|
||||
denyInput.dataset.name = key;
|
||||
denyLabel.htmlFor = key + "2";
|
||||
|
||||
const acceptFn = () => {
|
||||
acceptLabel.classList.add("active");
|
||||
denyLabel.classList.remove("active");
|
||||
this.addCookie(key, value);
|
||||
},
|
||||
denyFn = () => {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.add("active");
|
||||
this.removeCookie(key, value);
|
||||
};
|
||||
this.addEvent(acceptInput, "click", acceptFn);
|
||||
this.addEventKbdValidate(acceptLabel, acceptFn);
|
||||
this.addEvent(denyInput, "click", denyFn);
|
||||
this.addEventKbdValidate(denyLabel, denyFn);
|
||||
|
||||
this.cookiesList.append(cookie);
|
||||
|
||||
const cookiesSite = this.getLDCWebCookie("ldcwebcn-init");
|
||||
if (cookiesSite === undefined) {
|
||||
// * Ldcweb cookie is not set.
|
||||
return;
|
||||
}
|
||||
const cookiesArray = cookiesSite.split(",");
|
||||
for (const cookieEl of cookiesArray) {
|
||||
const name = cookieEl.slice(0, cookieEl.indexOf("="));
|
||||
const status = cookieEl.slice(cookieEl.indexOf("=") + 1);
|
||||
if (name === key) {
|
||||
acceptLabel.classList.remove("active");
|
||||
denyLabel.classList.remove("active");
|
||||
switch (status) {
|
||||
case "true":
|
||||
acceptLabel.classList.add("active");
|
||||
break;
|
||||
case "false":
|
||||
denyLabel.classList.add("active");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setListenerOnChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a specific cookie and
|
||||
* change his status to true
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
addCookie(key: string, value: CookieOptions) {
|
||||
if (value.script) {
|
||||
value.script();
|
||||
}
|
||||
this.changeStatus(key, "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a specific cookie and
|
||||
* change his status to false
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
removeCookie(key: string, value: CookieOptions) {
|
||||
for (const cookieName of value.cookies) {
|
||||
this.deleteBrowserCookie(cookieName, "/", "." + location.host);
|
||||
}
|
||||
const cookieName = document.getElementById(key);
|
||||
if (cookieName) {
|
||||
cookieName.remove();
|
||||
}
|
||||
if (value.fallback) {
|
||||
value.fallback();
|
||||
}
|
||||
this.changeStatus(key, "false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add events for each cookie buttons
|
||||
* Activate or Deactivate a specific cookie
|
||||
*/
|
||||
setListenerOnChange() {
|
||||
for (const item of this.changeBtn) {
|
||||
const statusChange = () => {
|
||||
if (!item.dataset.name) {
|
||||
throw new Error("Dataset is missing required elements");
|
||||
}
|
||||
const status = item.dataset.status as CookieStatus | undefined;
|
||||
if (!status || !(status in CookieStatus)) {
|
||||
throw new Error("Dataset is missing required elements");
|
||||
}
|
||||
this.changeStatus(item.dataset.name, status);
|
||||
};
|
||||
this.addEvent(item, "click", statusChange);
|
||||
this.addEventKbdValidate(item, statusChange);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the status of a cookie
|
||||
*
|
||||
* @param name
|
||||
* @param status
|
||||
*/
|
||||
changeStatus(name: string, status: keyof typeof CookieStatus) {
|
||||
/** Contains array of string like youtube=true etc */
|
||||
const newCookie: string[] = [];
|
||||
const cookie = this.getLDCWebCookie("ldcwebcn-init");
|
||||
if (cookie === undefined) {
|
||||
throw Error("Ldcweb cookie is not set");
|
||||
}
|
||||
|
||||
/** specificCookieString contains youtube=true like */
|
||||
cookie.split(",").forEach((specificCookieString) => {
|
||||
/** Contanins cookie name 0 and cookie value 1 */
|
||||
const test = specificCookieString.split("=");
|
||||
// Check this cookie is the one to update
|
||||
if (test[0] === name) {
|
||||
newCookie.push(name + "=" + status);
|
||||
|
||||
if (status === "false") {
|
||||
// * Iterer sur chque cookie possible de la config
|
||||
this.config[test[0]].cookies.forEach(
|
||||
(cookieNametoRemove) => {
|
||||
const cookies =
|
||||
this.getLDCWebCookie(cookieNametoRemove);
|
||||
// * Si le navigateur possede le cookie
|
||||
if (cookies !== undefined) {
|
||||
// * Suppression du cookie et de sa version precedé dun point
|
||||
document.cookie =
|
||||
cookieNametoRemove +
|
||||
"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=" +
|
||||
document.domain +
|
||||
"; path=/";
|
||||
document.cookie =
|
||||
cookieNametoRemove +
|
||||
"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=." +
|
||||
document.domain +
|
||||
"; path=/";
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
newCookie.push(specificCookieString);
|
||||
}
|
||||
});
|
||||
|
||||
this.saveLDCWebCookie(newCookie.join(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an older expire parameter to a specific cookie
|
||||
*
|
||||
* @param name
|
||||
* @param path
|
||||
* @param domain
|
||||
*/
|
||||
deleteBrowserCookie(name: string, path: string, domain: string) {
|
||||
if (this.getLDCWebCookie(name)) {
|
||||
document.cookie =
|
||||
name +
|
||||
"=" +
|
||||
(path ? ";path=" + path : "") +
|
||||
(domain ? ";domain=" + domain : "") +
|
||||
";expires=Thu, 01 Jan 1970 00:00:01 GMT";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Ldcweb cookie
|
||||
*
|
||||
* @param name
|
||||
* @returns A string like analytics=true,youtube=true or undefined
|
||||
*/
|
||||
getLDCWebCookie(name: string) {
|
||||
const matches = document.cookie.match(
|
||||
new RegExp(
|
||||
"(?:^|; )" +
|
||||
name.replace(/([.$?*|{}()[\]\\/+^])/g, "\\$1") +
|
||||
"=([^;]*)"
|
||||
)
|
||||
);
|
||||
return matches ? decodeURIComponent(matches[1]) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEvent(element: HTMLElement, evnt: string, funct: (e: Event) => void) {
|
||||
return element.addEventListener(evnt, funct, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add event on a specific element
|
||||
*
|
||||
* @param element
|
||||
* @param evnt
|
||||
* @param funct
|
||||
* @returns
|
||||
*/
|
||||
addEventKbdValidate(element: HTMLElement, funct: (e: Event) => void) {
|
||||
return this.addEvent(element, "keyup", (e: Event) => {
|
||||
const kbdEvt = e as KeyboardEvent;
|
||||
if (
|
||||
kbdEvt.key == " " ||
|
||||
kbdEvt.code == "Space" ||
|
||||
kbdEvt.keyCode == 32 ||
|
||||
kbdEvt.key == "Enter" ||
|
||||
kbdEvt.code == "Enter" ||
|
||||
kbdEvt.keyCode == 13
|
||||
) {
|
||||
funct(kbdEvt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Save cookie content on web browser
|
||||
*
|
||||
* @param content
|
||||
*/
|
||||
saveLDCWebCookie(content: string) {
|
||||
const date = new Date();
|
||||
const newDate = new Date(date.setMonth(date.getMonth() + 13));
|
||||
document.cookie =
|
||||
"ldcwebcn-init=" +
|
||||
content +
|
||||
"; expires=" +
|
||||
newDate.toUTCString() +
|
||||
"; path=/;";
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the cookies modal
|
||||
*/
|
||||
openCookieModal() {
|
||||
document.body.classList.add("cn-open");
|
||||
|
||||
this.ldcwebBannerContent.classList.add("d-none");
|
||||
this.ldcwebBannerDetails.classList.add("d-none");
|
||||
this.ldcwebBannerBtnDetails.classList.add("d-none");
|
||||
this.modalContainer.classList.remove("d-none");
|
||||
this.modalBtnBoolean = true;
|
||||
this.personalizeBtnOpen();
|
||||
// Scroll to the top of the cookies list
|
||||
this.modalWrapper.scrollTop = 0;
|
||||
this.setTabIndex();
|
||||
this.setCookieList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup tab indexes on visible elements
|
||||
*/
|
||||
setTabIndex() {
|
||||
// * Prevent focus html tag
|
||||
document.documentElement.setAttribute("tabindex", "-1");
|
||||
setTimeout(() => {
|
||||
const focusableSelector =
|
||||
"a[href], button, [role=\"button\"], input, embed, object, iframe, textarea, select, details, [tabindex]:not([tabindex=\"-1\"])";
|
||||
|
||||
// * Only focusable elements
|
||||
[...document.body.querySelectorAll(focusableSelector)]
|
||||
.filter(
|
||||
(el) =>
|
||||
!el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden")
|
||||
)
|
||||
.forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "-1");
|
||||
(el as HTMLElement).classList.add("cn-disabled");
|
||||
});
|
||||
[...this.cookieContainer.querySelectorAll(focusableSelector)]
|
||||
.filter(
|
||||
(el) =>
|
||||
!el.hasAttribute("disabled") &&
|
||||
!el.getAttribute("aria-hidden") &&
|
||||
// * Only visible elements
|
||||
!!(
|
||||
(el as HTMLElement).offsetWidth ||
|
||||
(el as HTMLElement).offsetHeight ||
|
||||
el.getClientRects().length
|
||||
)
|
||||
)
|
||||
.forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "0");
|
||||
(el as HTMLElement).classList.remove("cn-disabled");
|
||||
});
|
||||
this.ldcwebCookieBtn.setAttribute("tabindex", "-1");
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the cookies modal
|
||||
*/
|
||||
hideCookieModal() {
|
||||
document.body.classList.remove("cn-open");
|
||||
this.ldcwebBannerContent.classList.toggle("d-none");
|
||||
this.ldcwebBannerDetails.classList.toggle("d-none");
|
||||
this.ldcwebBannerBtnDetails.classList.toggle("d-none");
|
||||
this.modalContainer.classList.toggle("d-none");
|
||||
this.unsetTabIndex();
|
||||
this.setCookieList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo setup tab indexes on visible elements
|
||||
*/
|
||||
unsetTabIndex() {
|
||||
document.documentElement.setAttribute("tabindex", "0");
|
||||
setTimeout(() => {
|
||||
document.body.querySelectorAll(".cn-disabled").forEach((el) => {
|
||||
(el as HTMLElement).setAttribute("tabindex", "0");
|
||||
(el as HTMLElement).classList.remove("cn-disabled");
|
||||
});
|
||||
this.ldcwebCookieBtn.setAttribute("tabindex", "0");
|
||||
}, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the modal view state
|
||||
*/
|
||||
resetModalVue() {
|
||||
this.ldcwebBannerContent.classList.remove("d-none");
|
||||
this.ldcwebBannerDetails.classList.remove("d-none");
|
||||
this.ldcwebBannerBtnDetails.classList.remove("d-none");
|
||||
this.modalContainer.classList.add("d-none");
|
||||
if (!this.personalizeBtnBanner.dataset.closeModal) {
|
||||
throw new Error("Cannot find attribut data-close-modal");
|
||||
}
|
||||
this.personalizeBtnBanner.innerHTML =
|
||||
this.personalizeBtnBanner.dataset.closeModal;
|
||||
this.modalBtnBoolean = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the text of the button "personalize" when the modal is opening
|
||||
*/
|
||||
personalizeBtnOpen() {
|
||||
const personalizeBtnBannerText = this.personalizeBtnBanner.dataset
|
||||
.openModal as string;
|
||||
this.personalizeBtnBanner.innerHTML = personalizeBtnBannerText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the text of the button "personalize" when the modal is closing
|
||||
*/
|
||||
personalizeBtnClose() {
|
||||
const personalizeBtnBannerText = this.personalizeBtnBanner.dataset
|
||||
.closeModal as string;
|
||||
this.personalizeBtnBanner.innerHTML = personalizeBtnBannerText;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
{
|
||||
"sourceMap": true,
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["es5", "es6", "es2021", "dom", "dom.iterable"],
|
||||
"module": "esnext",
|
||||
"declaration": true /* Generates corresponding'.d.ts' files. */,
|
||||
"declarationDir": "dist/typings" /* build '.d.ts' files to ./dist/typeings */,
|
||||
"outDir": "dist/esm/" /* build to ./dist/esm/ */,
|
||||
"target": "es2015" /* Build to ES2022 */,
|
||||
"lib": ["es2015", "es2021", "es2022", "dom", "dom.iterable"] /* Using ES2022 features and DOM APIs */,
|
||||
"module": "es2015" /* using es2020 modules */,
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"moduleResolution": "node",
|
||||
|
|
@ -12,11 +16,12 @@
|
|||
"node_modules/@types"
|
||||
]
|
||||
},
|
||||
"files": ["./src/index.ts"],
|
||||
"include": [
|
||||
"src/**/*.js",
|
||||
"src/**/*.ts",
|
||||
],
|
||||
"exclude": ["node_modules"],
|
||||
"exclude": ["webpack.config.cjs", "node_modules"],
|
||||
"compileOnSave": false,
|
||||
"experimentalDecorators": true
|
||||
}
|
||||
|
|
|
|||
60
webpack.config.cjs
Normal file
60
webpack.config.cjs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
const path = require("path");
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
return {
|
||||
devtool: "source-map",
|
||||
mode: argv.mode === "production" ? "production" : "development",
|
||||
entry: [
|
||||
path.resolve(__dirname, "./dist/esm/index.js"),
|
||||
path.resolve(__dirname, "./src/scss/themes/standard.scss")
|
||||
],
|
||||
output: {
|
||||
clean: true,
|
||||
path: path.resolve(__dirname, "./dist/umd"), // builds to ./dist/umd/
|
||||
filename: "[name].js", // index.js
|
||||
library: "CookieNotice", // aka window.CookieNotice
|
||||
libraryTarget: "umd", // supports commonjs, amd and web browsers
|
||||
globalObject: "this"
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.t|js$/,
|
||||
use: {
|
||||
loader: "babel-loader",
|
||||
options: { babelrc: true }
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.s[ac]ss$/i,
|
||||
exclude: /node_modules/,
|
||||
type: "asset/resource",
|
||||
generator: {
|
||||
filename: "css/[name].css"
|
||||
},
|
||||
use: [
|
||||
{
|
||||
loader: "sass-loader",
|
||||
options: {
|
||||
sourceMap: true,
|
||||
// Prefer `dart-sass`
|
||||
implementation: require("sass"),
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
stats: {
|
||||
errorDetails: true,
|
||||
children: true
|
||||
},
|
||||
resolve: {
|
||||
extensions: [".tsx", ".ts", ".js"],
|
||||
fallback: {
|
||||
fs: false,
|
||||
path: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
63
webpack.mix.js
vendored
63
webpack.mix.js
vendored
|
|
@ -1,63 +0,0 @@
|
|||
const path = require("path");
|
||||
const mix = require("laravel-mix");
|
||||
const { unlinkSync } = require("fs");
|
||||
|
||||
require("laravel-mix-polyfill");
|
||||
require("laravel-mix-clean");
|
||||
require("laravel-mix-eslint");
|
||||
require("laravel-mix-stylelint");
|
||||
|
||||
const polyfill = {
|
||||
enabled: true,
|
||||
bugfixes: true,
|
||||
useBuiltIns: "usage",
|
||||
targets: "last 3 version, not dead, >0.3%",
|
||||
};
|
||||
|
||||
mix.setPublicPath(path.normalize("dist"));
|
||||
mix.setResourceRoot(path.normalize("src"));
|
||||
|
||||
mix.webpackConfig({
|
||||
resolve: {
|
||||
extensions: ["*", ".js", ".ts"],
|
||||
alias: {
|
||||
"@": path.resolve("resources/assets"),
|
||||
},
|
||||
},
|
||||
// Pour debug compilation errors
|
||||
// stats: {
|
||||
// children: true,
|
||||
// warningsFilter: [/\-\-underline\-color/],
|
||||
// },
|
||||
});
|
||||
|
||||
mix.options({
|
||||
postCss: [
|
||||
require("postcss-discard-comments")({
|
||||
removeAll: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
mix.clean({
|
||||
cleanOnceBeforeBuildPatterns: ["dist/*"],
|
||||
});
|
||||
|
||||
// * COMMON
|
||||
mix.eslint({
|
||||
fix: true,
|
||||
extensions: ["js", "ts"],
|
||||
})
|
||||
.stylelint({
|
||||
configFile: ".stylelintrc.json",
|
||||
files: ["**/*.scss"],
|
||||
})
|
||||
.polyfill(polyfill)
|
||||
.version()
|
||||
.sourceMaps(false, "inline-source-map")
|
||||
|
||||
.ts("src/ts/ldcweb-cookies.ts", "js/cookie-notice.js")
|
||||
.sass("src/scss/themes/standard.scss", "css/cookie-notice-standard.css")
|
||||
.then(() => {
|
||||
unlinkSync(path.resolve("dist/mix-manifest.json"));
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue