ldc-web-cookie-notice/dist/umd/main.js
2023-06-01 14:51:39 +02:00

887 lines
No EOL
36 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__ = ({
/***/ "./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) {
/******/ var i = scripts.length - 1;
/******/ while (i > -1 && !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__("./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