955 lines
No EOL
37 KiB
JavaScript
Vendored
955 lines
No EOL
37 KiB
JavaScript
Vendored
(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__ = ({
|
|
|
|
/***/ "./src/ts/index.ts":
|
|
/*!*************************!*\
|
|
!*** ./src/ts/index.ts ***!
|
|
\*************************/
|
|
/***/ (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(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
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 _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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
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 _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
/** 4.1.1 */
|
|
var CookieNotice = /*#__PURE__*/function () {
|
|
/** Cookie expiration date as specified in the cookie itself */
|
|
|
|
function CookieNotice(config) {
|
|
var _this = this;
|
|
_classCallCheck(this, CookieNotice);
|
|
_defineProperty(this, "browserCookieName", "cn-init");
|
|
/** Cookie life time */
|
|
_defineProperty(this, "cookieTimeLife", 6);
|
|
/** The index on which store the expiration date */
|
|
_defineProperty(this, "cookieExpirationName", "_expiration");
|
|
/** Cookie policies for each functionality */
|
|
_defineProperty(this, "cookiePolicies", {
|
|
sameSite: CookiePolicySameSite.lax,
|
|
secure: ""
|
|
});
|
|
// * Setup Config
|
|
this.config = config;
|
|
|
|
// * Setup cookie expiration date
|
|
var cookieExpirationDate = this.readCookiesExpirationDate();
|
|
if (!cookieExpirationDate) {
|
|
cookieExpirationDate = new Date();
|
|
cookieExpirationDate.setMonth(cookieExpirationDate.getMonth() + this.cookieTimeLife);
|
|
}
|
|
this.cookieExpirationDate = cookieExpirationDate;
|
|
|
|
// * 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(".cn-cookie-link"),
|
|
bannerContainer = document.querySelector("div#cn-banner"),
|
|
bannerContent = document.querySelector("div.cn-banner-content"),
|
|
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 (!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.bannerContainer = bannerContainer;
|
|
this.bannerContent = bannerContent;
|
|
this.cookiesUnorderedList = cookiesUnorderedList;
|
|
this.modalWrapper = modalWrapper;
|
|
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;
|
|
this.restrictCloseModal = true;
|
|
|
|
// * 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.cookieShowModalBtn, "click", this.toggleCookieModal);
|
|
this.cookieLinkShowCustomizeModalList.forEach(function (cookieLink) {
|
|
_this.addEventPrevent(cookieLink, "click", _this.openCookieModalToCookiePage);
|
|
_this.addEventKbdValidate(cookieLink, _this.openCookieModalToCookiePage);
|
|
});
|
|
|
|
// * Setup CN Cookie
|
|
if (!this.cookiesMatchesConfig() || this.cookiesOlderThan(new Date())) {
|
|
// * Setup Browser Cookie if none.
|
|
this.resetBrowserCookie();
|
|
this.openCookieModalToBannerPage();
|
|
}
|
|
this.updateRestrictCloseModal();
|
|
|
|
// * Cookie should have been created from here.
|
|
Object.entries(this.getCookieStatusList()).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
|
|
|
|
/**
|
|
* Update restrict for closing cookie modal
|
|
*/
|
|
return _createClass(CookieNotice, [{
|
|
key: "updateRestrictCloseModal",
|
|
value: function updateRestrictCloseModal() {
|
|
this.restrictCloseModal = Object.values(this.getCookieStatusList()).includes(CookieStatus.wait) ? true : false;
|
|
this.restrictCloseModal ? this.cookieCloseModalBtn.classList.add("d-none") : this.cookieCloseModalBtn.classList.remove("d-none");
|
|
this.restrictCloseModal ? this.modalBg.classList.add("cn-modal-bg-active") : this.modalBg.classList.remove("cn-modal-bg-active");
|
|
}
|
|
|
|
/**
|
|
* Get cookies expiration date or null if not defined alread
|
|
*/
|
|
}, {
|
|
key: "readCookiesExpirationDate",
|
|
value: function readCookiesExpirationDate() {
|
|
var _this$getBrowserCooki,
|
|
_this2 = this;
|
|
var cookies = (_this$getBrowserCooki = this.getBrowserCookieValue()) !== null && _this$getBrowserCooki !== void 0 ? _this$getBrowserCooki : "",
|
|
expirationDateString = cookies.split(",").find(function (cookieString) {
|
|
return cookieString.startsWith(_this2.cookieExpirationName);
|
|
});
|
|
if (!expirationDateString) {
|
|
return null;
|
|
}
|
|
try {
|
|
var epochExpiration = Number.parseInt(expirationDateString.replace("".concat(this.cookieExpirationName, "="), ""));
|
|
if (isNaN(epochExpiration)) {
|
|
return null;
|
|
}
|
|
return new Date(epochExpiration);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if the cookies date are older than a specified date
|
|
* @param date The limit date for cookies
|
|
*/
|
|
}, {
|
|
key: "cookiesOlderThan",
|
|
value: function cookiesOlderThan(date) {
|
|
return this.cookieExpirationDate.getTime() < date.getTime();
|
|
}
|
|
|
|
/**
|
|
* Check if the actual cookie matches the config
|
|
*/
|
|
}, {
|
|
key: "cookiesMatchesConfig",
|
|
value: function cookiesMatchesConfig() {
|
|
var cookies = this.getCookieStatusList();
|
|
return Object.keys(cookies).length === Object.keys(this.config).length;
|
|
}
|
|
|
|
/**
|
|
* Accept a all cookies
|
|
*/
|
|
}, {
|
|
key: "acceptAllCookies",
|
|
value: function acceptAllCookies() {
|
|
var _this3 = this;
|
|
Object.keys(this.config).forEach(function (cookieName) {
|
|
return _this3.acceptCookie(cookieName);
|
|
});
|
|
this.closeCookieModal();
|
|
}
|
|
|
|
/**
|
|
* Accept a specific cookie
|
|
*/
|
|
}, {
|
|
key: "acceptCookie",
|
|
value: function acceptCookie(cookieName) {
|
|
var _this$cookieContainer, _this$cookieContainer2;
|
|
var cookieOptions = this.getCookie(cookieName);
|
|
this.setCookieStatus(cookieName, CookieStatus.true, cookieOptions);
|
|
(_this$cookieContainer = this.cookieContainer.querySelector("#".concat(cookieName, "-accept"))) === null || _this$cookieContainer === void 0 || (_this$cookieContainer = _this$cookieContainer.classList) === null || _this$cookieContainer === void 0 || _this$cookieContainer.add("active");
|
|
(_this$cookieContainer2 = this.cookieContainer.querySelector("#".concat(cookieName, "-deny"))) === null || _this$cookieContainer2 === void 0 || (_this$cookieContainer2 = _this$cookieContainer2.classList) === null || _this$cookieContainer2 === void 0 || _this$cookieContainer2.remove("active");
|
|
}
|
|
|
|
/**
|
|
* Deny a all cookies
|
|
*/
|
|
}, {
|
|
key: "denyAllCookies",
|
|
value: function denyAllCookies() {
|
|
var _this4 = this;
|
|
Object.keys(this.config).forEach(function (cookieName) {
|
|
return _this4.denyCookie(cookieName);
|
|
});
|
|
this.closeCookieModal();
|
|
}
|
|
|
|
/**
|
|
* Deny a specific cookie
|
|
*/
|
|
}, {
|
|
key: "denyCookie",
|
|
value: function denyCookie(cookieName) {
|
|
var _this$cookieContainer3, _this$cookieContainer4;
|
|
var cookieOptions = this.getCookie(cookieName);
|
|
this.setCookieStatus(cookieName, CookieStatus.false, cookieOptions);
|
|
(_this$cookieContainer3 = this.cookieContainer.querySelector("#".concat(cookieName, "-deny"))) === null || _this$cookieContainer3 === void 0 || (_this$cookieContainer3 = _this$cookieContainer3.classList) === null || _this$cookieContainer3 === void 0 || _this$cookieContainer3.add("active");
|
|
(_this$cookieContainer4 = this.cookieContainer.querySelector("#".concat(cookieName, "-accept"))) === null || _this$cookieContainer4 === void 0 || (_this$cookieContainer4 = _this$cookieContainer4.classList) === null || _this$cookieContainer4 === void 0 || _this$cookieContainer4.remove("active");
|
|
}
|
|
|
|
/**
|
|
* Deny all waiting cookies
|
|
*/
|
|
}, {
|
|
key: "denyAllWaitingCookies",
|
|
value: function denyAllWaitingCookies() {
|
|
var _this5 = this;
|
|
Object.entries(this.getCookieStatusList()).forEach(function (_ref3) {
|
|
var _ref4 = _slicedToArray(_ref3, 2),
|
|
cookieName = _ref4[0],
|
|
cookieStatus = _ref4[1];
|
|
if (cookieStatus === CookieStatus.wait) {
|
|
_this5.setBrowserCookieStatus(cookieName, CookieStatus.false);
|
|
return;
|
|
}
|
|
});
|
|
this.updateRestrictCloseModal();
|
|
}
|
|
|
|
/**
|
|
* Get a specific cookie config
|
|
*/
|
|
}, {
|
|
key: "getCookie",
|
|
value: function getCookie(cookieName) {
|
|
var _Object$entries$find;
|
|
var cookieOptions = (_Object$entries$find = Object.entries(this.config).find(function (entry) {
|
|
return entry[0] === cookieName;
|
|
})) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1];
|
|
if (cookieOptions === undefined) {
|
|
throw new Error("Cookie options ".concat(cookieName, " not found in list"));
|
|
}
|
|
return cookieOptions;
|
|
}
|
|
|
|
/**
|
|
* Fetch the cookie status list
|
|
*
|
|
* @returns the cookie status list
|
|
*/
|
|
}, {
|
|
key: "getCookieStatusList",
|
|
value: function getCookieStatusList() {
|
|
var _this6 = this;
|
|
var cookies = this.getBrowserCookieValue(),
|
|
statusList = {};
|
|
if (cookies === undefined) {
|
|
return statusList;
|
|
}
|
|
/** specificCookieString contains youtube=true like */
|
|
cookies.split(",")
|
|
// * Ignore timestamp
|
|
.filter(function (specificCookieString) {
|
|
return !specificCookieString.startsWith(_this6.cookieExpirationName);
|
|
}).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) {
|
|
console.log("setcookie status ".concat(cookieName, " ").concat(status));
|
|
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);
|
|
this.updateRestrictCloseModal();
|
|
}
|
|
|
|
/**
|
|
* 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(),
|
|
content = Object.entries(statusList).map(function (_ref5) {
|
|
var _ref6 = _slicedToArray(_ref5, 2),
|
|
cookieName = _ref6[0],
|
|
cookieStatus = _ref6[1];
|
|
return "".concat(cookieName, "=").concat(cookieStatus);
|
|
});
|
|
// * Update expiration date
|
|
this.cookieExpirationDate = new Date(date.setMonth(date.getMonth() + this.cookieTimeLife));
|
|
// * Append expiration date
|
|
content.push("".concat(this.cookieExpirationName, "=").concat(this.cookieExpirationDate.getTime()));
|
|
document.cookie = "".concat(this.browserCookieName, "=").concat(content.join(","), ";path=/").concat(location.hostname ? ";domain=".concat(location.hostname) : "", ";expires=").concat(this.cookieExpirationDate.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;");
|
|
document.cookie = "".concat(this.browserCookieName, "=;path=/").concat(location.hostname ? ";domain=".concat(location.hostname) : "", ";expires=Thu, 01 Jan 1970 00:00:01 GMT;");
|
|
}
|
|
}
|
|
}, {
|
|
key: "getCookiePoliciesAsString",
|
|
value: function getCookiePoliciesAsString() {
|
|
return Object.entries(this.cookiePolicies).map(function (_ref7) {
|
|
var _ref8 = _slicedToArray(_ref7, 2),
|
|
policyName = _ref8[0],
|
|
policyValue = _ref8[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 (_ref9) {
|
|
var _ref10 = _slicedToArray(_ref9, 1),
|
|
cookieName = _ref10[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 _this7 = this;
|
|
return element.addEventListener(evnt, function (e) {
|
|
e.preventDefault();
|
|
funct.call(_this7, e);
|
|
}, false);
|
|
}
|
|
|
|
/**
|
|
* Add event on a specific element
|
|
*
|
|
* @param element
|
|
* @param evnt
|
|
* @param funct
|
|
* @returns
|
|
*/
|
|
}, {
|
|
key: "addEventKbdValidate",
|
|
value: function addEventKbdValidate(element, funct) {
|
|
var _this8 = this;
|
|
return this.addEvent(element, "keydown", 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(_this8, kbdEvt);
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
}
|
|
|
|
// 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.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() {
|
|
this.updateRestrictCloseModal();
|
|
if (!this.restrictCloseModal) {
|
|
document.body.classList.remove("cn-open");
|
|
this.unsetTabIndex();
|
|
this.setupCookieModalList();
|
|
} else {
|
|
throw new Error("You need to accept or refuse all cookies");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setup tab indexes on visible elements
|
|
*/
|
|
}, {
|
|
key: "setTabIndex",
|
|
value: function setTabIndex() {
|
|
var _this9 = 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(_this9.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");
|
|
});
|
|
_this9.cookieShowModalBtn.setAttribute("tabindex", "-1");
|
|
}, 500);
|
|
}
|
|
|
|
/**
|
|
* Undo setup tab indexes on visible elements
|
|
*/
|
|
}, {
|
|
key: "unsetTabIndex",
|
|
value: function unsetTabIndex() {
|
|
var _this10 = 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");
|
|
});
|
|
_this10.cookieShowModalBtn.setAttribute("tabindex", "0");
|
|
}, 500);
|
|
}
|
|
|
|
/**
|
|
* Reset the modal view state
|
|
*/
|
|
}, {
|
|
key: "resetCookieModal",
|
|
value: function resetCookieModal() {
|
|
this.bannerContent.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 _this11 = this;
|
|
this.cookiesUnorderedList.innerHTML = "";
|
|
Object.entries(this.config).forEach(function (_ref11) {
|
|
var _ref12 = _slicedToArray(_ref11, 2),
|
|
cookieName = _ref12[0],
|
|
cookieConfig = _ref12[1];
|
|
var cookie = document.createElement("li");
|
|
var childItem = _this11.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 + "-accept";
|
|
acceptInput.name = cookieName;
|
|
acceptInput.dataset.name = cookieName;
|
|
acceptLabel.htmlFor = cookieName + "-accept";
|
|
acceptLabel.textContent = "".concat(acceptLabel.textContent, " ").concat(cookieName);
|
|
acceptLabel.title = "".concat(acceptLabel.textContent, " ").concat(cookieName);
|
|
denyInput.id = cookieName + "-deny";
|
|
denyInput.name = cookieName;
|
|
denyInput.dataset.name = cookieName;
|
|
denyLabel.htmlFor = cookieName + "-deny";
|
|
denyLabel.textContent = "".concat(denyLabel.textContent, " ").concat(cookieName);
|
|
denyLabel.title = "".concat(denyLabel.textContent, " ").concat(cookieName);
|
|
var acceptFn = function acceptFn() {
|
|
acceptLabel.classList.add("active");
|
|
denyLabel.classList.remove("active");
|
|
_this11.setCookieStatus(cookieName, CookieStatus.true, cookieConfig);
|
|
},
|
|
denyFn = function denyFn() {
|
|
acceptLabel.classList.remove("active");
|
|
denyLabel.classList.add("active");
|
|
_this11.setCookieStatus(cookieName, CookieStatus.false, cookieConfig);
|
|
};
|
|
_this11.addEvent(acceptInput, "click", acceptFn);
|
|
_this11.addEventKbdValidate(acceptLabel, acceptFn);
|
|
_this11.addEvent(denyInput, "click", denyFn);
|
|
_this11.addEventKbdValidate(denyLabel, denyFn);
|
|
_this11.cookiesUnorderedList.append(cookie);
|
|
if (!_this11.hasBrowserCookie()) {
|
|
// * Ldcweb cookie is not set.
|
|
return;
|
|
}
|
|
// * Setup list status state
|
|
Object.entries(_this11.getCookieStatusList()).forEach(function (_ref13) {
|
|
var _ref14 = _slicedToArray(_ref13, 2),
|
|
ckName = _ref14[0],
|
|
cookieStatus = _ref14[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 Cookie modal pages
|
|
*/
|
|
}, {
|
|
key: "toggleCookieModalPages",
|
|
value: function toggleCookieModalPages() {
|
|
this.bannerContent.classList.toggle("d-none");
|
|
this.modalContainer.classList.toggle("d-none");
|
|
if (!this.modalContainer.classList.contains("d-none")) {
|
|
this.denyAllWaitingCookies();
|
|
}
|
|
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;
|
|
this.customizeBtn.title = customizeBtnBannerDataset.openModal;
|
|
} else {
|
|
this.customizeBtn.innerHTML = customizeBtnBannerDataset.closeModal;
|
|
this.customizeBtn.title = customizeBtnBannerDataset.closeModal;
|
|
}
|
|
}
|
|
}]);
|
|
}();
|
|
|
|
var CookieStatus = /*#__PURE__*/function (CookieStatus) {
|
|
CookieStatus["true"] = "true";
|
|
CookieStatus["false"] = "false";
|
|
CookieStatus["wait"] = "wait";
|
|
return CookieStatus;
|
|
}(CookieStatus || {});
|
|
var CookiePolicySameSite = /*#__PURE__*/function (CookiePolicySameSite) {
|
|
CookiePolicySameSite["lax"] = "lax";
|
|
CookiePolicySameSite["strict"] = "strict";
|
|
CookiePolicySameSite["none"] = "none";
|
|
return 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) {
|
|
/******/ var i = scripts.length - 1;
|
|
/******/ while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].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__("./src/ts/index.ts");
|
|
/******/ // 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
|