diff --git a/src/cookie-consent.mjs b/src/cookie-consent.mjs
index c50aa3b..41c9fcd 100644
--- a/src/cookie-consent.mjs
+++ b/src/cookie-consent.mjs
@@ -71,7 +71,8 @@ export default class Dialog extends HTMLElement {
saveButtonText: Config().get("labels.aria.button"),
defaultButtonLabel: Config().get("labels.button.default"),
acceptAllButton:
- Config().get("acceptAllButton") && !Preferences().hasPreferences(),
+ Config().get("acceptAllButton")
+ && !Preferences().hasPreferences(),
};
// custom content from data-attributes
const customContent = {
@@ -185,9 +186,9 @@ export default class Dialog extends HTMLElement {
const checkedCount = values.filter((v) => v.accepted).length;
const userOptionsChecked = checkedCount >= requiredCount;
if (
- this.data.acceptAllButton &&
- this.config.type === "checkbox" &&
- !userOptionsChecked
+ this.data.acceptAllButton
+ && this.config.type === "checkbox"
+ && !userOptionsChecked
) {
return values.map((value) => ({
...value,
@@ -250,8 +251,7 @@ export default class Dialog extends HTMLElement {
// Loop through arrayfiedTabListChildren
tabListChildren.forEach((input) => {
// Find all input elements
- const inputElement =
- input.firstElementChild.firstElementChild.firstElementChild;
+ const inputElement = input.firstElementChild.firstElementChild.firstElementChild;
// Loop through updated cookies
this.cookies.forEach((cookie) => {
// set the checked state to the updated cookie state
diff --git a/src/dialog-tablist.mjs b/src/dialog-tablist.mjs
index a6c2509..c84a178 100644
--- a/src/dialog-tablist.mjs
+++ b/src/dialog-tablist.mjs
@@ -27,10 +27,9 @@ const DialogTabList = (cookieInformation) => {
* `required: false`, because of #3)
* 3. Use the `checked` setting.
*/
- const shouldBeChecked =
- typeof accepted !== "undefined"
- ? accepted
- : required === true
+ const shouldBeChecked = typeof accepted !== "undefined"
+ ? accepted
+ : required === true
? required
: checked;
@@ -96,9 +95,7 @@ const DialogTabList = (cookieInformation) => {
: undefined,
}));
return `
-
+
${cookiesWithState.map(renderTab).join("")}
`;
@@ -127,8 +124,7 @@ const DialogTabList = (cookieInformation) => {
const controls = targetTab ? targetTab.getAttribute("aria-controls") : "";
tabs.forEach((tab) => tab.setAttribute("aria-selected", tab === targetTab));
panels.forEach((panel) =>
- panel.setAttribute("aria-hidden", controls !== panel.id)
- );
+ panel.setAttribute("aria-hidden", controls !== panel.id));
};
/**
@@ -140,8 +136,7 @@ const DialogTabList = (cookieInformation) => {
tabs.forEach((tab) => {
tab.addEventListener("click", (e) => {
e.preventDefault();
- const targetTab =
- tab.getAttribute("aria-selected") === "true" ? null : tab;
+ const targetTab = tab.getAttribute("aria-selected") === "true" ? null : tab;
selectTab({ tabs, panels, targetTab });
});
});
diff --git a/src/dom-toggler.mjs b/src/dom-toggler.mjs
index bac0ead..9453d4a 100644
--- a/src/dom-toggler.mjs
+++ b/src/dom-toggler.mjs
@@ -1,18 +1,17 @@
-const GENERAL_ATTRIBUTE = 'data-cookie-consent';
-const ACCEPTED_STATE_ATTRIBUTE = 'data-cookie-consent-accepted';
-const REJECTED_STATE_ATTRIBUTE = 'data-cookie-consent-rejected';
+const GENERAL_ATTRIBUTE = "data-cookie-consent";
+const ACCEPTED_STATE_ATTRIBUTE = "data-cookie-consent-accepted";
+const REJECTED_STATE_ATTRIBUTE = "data-cookie-consent-rejected";
/**
* DOM toggler, which enables conditional script tags or embedded content.
*/
-const DomToggler = config => {
-
+const DomToggler = (config) => {
/**
* Append a single script.
* @TODO append it to the same location and re-add classes and attributes.
*/
- const appendScript = script => {
- const newScript = document.createElement('script');
+ const appendScript = (script) => {
+ const newScript = document.createElement("script");
if (script.src) {
newScript.src = script.src;
} else {
@@ -29,8 +28,10 @@ const DomToggler = config => {
if (!accepted) {
return;
}
- const scripts = document.documentElement.querySelectorAll(`script[${GENERAL_ATTRIBUTE}="${id}"]`);
- [...scripts].forEach(script => {
+ const scripts = document.documentElement.querySelectorAll(
+ `script[${GENERAL_ATTRIBUTE}="${id}"]`
+ );
+ [...scripts].forEach((script) => {
appendScript(script);
script.parentNode.removeChild(script);
});
@@ -39,22 +40,22 @@ const DomToggler = config => {
/**
* Show a single iframe.
*/
- const showIframe = iframe => {
- const src = iframe.getAttribute('data-src');
+ const showIframe = (iframe) => {
+ const src = iframe.getAttribute("data-src");
if (src) {
- iframe.setAttribute('src', src);
- iframe.removeAttribute('data-src');
+ iframe.setAttribute("src", src);
+ iframe.removeAttribute("data-src");
}
};
/**
* Hide a single iframe.
*/
- const hideIframe = iframe => {
- const src = iframe.getAttribute('src');
+ const hideIframe = (iframe) => {
+ const src = iframe.getAttribute("src");
if (src) {
- iframe.setAttribute('data-src', src);
- iframe.removeAttribute('src');
+ iframe.setAttribute("data-src", src);
+ iframe.removeAttribute("src");
}
};
@@ -62,41 +63,48 @@ const DomToggler = config => {
* Show conditional iframes based on wanted state.
*/
const toggleConditionalIframes = ({ id, accepted }) => {
- const iframes = document.body.querySelectorAll(`iframe[${GENERAL_ATTRIBUTE}="${id}"]`);
- [...iframes].forEach(el => accepted ? showIframe(el) : hideIframe(el));
+ const iframes = document.body.querySelectorAll(
+ `iframe[${GENERAL_ATTRIBUTE}="${id}"]`
+ );
+ [...iframes].forEach((el) => (accepted ? showIframe(el) : hideIframe(el)));
};
/**
* Show a single element.
*/
- const showElement = el => {
- el.style.display = '';
- el.removeAttribute('aria-hidden');
- el.removeAttribute('hidden');
+ const showElement = (el) => {
+ el.style.display = "";
+ el.removeAttribute("aria-hidden");
+ el.removeAttribute("hidden");
};
/**
* Hide a single element.
*/
- const hideElement = el => {
- el.style.display = 'none';
- el.setAttribute('aria-hidden', 'true');
+ const hideElement = (el) => {
+ el.style.display = "none";
+ el.setAttribute("aria-hidden", "true");
};
-
/**
* Show conditional elements based on wanted state.
*/
const toggleConditionalElements = ({ id, accepted }) => {
- const accepts = document.body.querySelectorAll(`[${ACCEPTED_STATE_ATTRIBUTE}="${id}"]`);
- const rejects = document.body.querySelectorAll(`[${REJECTED_STATE_ATTRIBUTE}="${id}"]`);
- [...accepts].forEach(el => accepted ? showElement(el) : hideElement(el));
- [...rejects].forEach(el => accepted ? hideElement(el) : showElement(el));
+ const accepts = document.body.querySelectorAll(
+ `[${ACCEPTED_STATE_ATTRIBUTE}="${id}"]`
+ );
+ const rejects = document.body.querySelectorAll(
+ `[${REJECTED_STATE_ATTRIBUTE}="${id}"]`
+ );
+ [...accepts].forEach((el) =>
+ accepted ? showElement(el) : hideElement(el));
+ [...rejects].forEach((el) =>
+ accepted ? hideElement(el) : showElement(el));
};
return {
- toggle: preferences => {
- const cookies = config.get('cookies') || [];
- cookies.forEach(type => {
+ toggle: (preferences) => {
+ const cookies = config.get("cookies") || [];
+ cookies.forEach((type) => {
const accepted = preferences.getState(type.id);
toggleScripts({ id: type.id, accepted });
toggleConditionalElements({ id: type.id, accepted });
@@ -104,7 +112,6 @@ const DomToggler = config => {
});
},
};
-
};
export default DomToggler;
diff --git a/src/storage.mjs b/src/storage.mjs
index 1e90b5f..95fe300 100644
--- a/src/storage.mjs
+++ b/src/storage.mjs
@@ -7,14 +7,14 @@ const Storage = () => {
const storageModule = supportsLocalStorage()
? window.localStorage
: {
- attributes: {},
- setItem(key, val) {
- this.attributes[key] = val;
- },
- getItem(key) {
- return this.attributes[key];
- },
- };
+ attributes: {},
+ setItem(key, val) {
+ this.attributes[key] = val;
+ },
+ getItem(key) {
+ return this.attributes[key];
+ },
+ };
const get = (key, value) => storageModule.getItem(key, value);
const set = (key, value) => storageModule.setItem(key, value);