2022-10-27 17:27:20 +01:00
|
|
|
import { celebrations } from "../config.js";
|
2023-05-16 21:13:11 +01:00
|
|
|
import emoji from "../emoji.js";
|
2022-10-27 17:27:20 +01:00
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
export function switcher(obj) {
|
|
|
|
let items = ``;
|
2023-02-12 07:40:49 +00:00
|
|
|
if (obj.name === "download") {
|
2023-01-29 18:28:10 +00:00
|
|
|
items = obj.items;
|
2023-01-29 18:17:33 +00:00
|
|
|
} else {
|
|
|
|
for (let i = 0; i < obj.items.length; i++) {
|
|
|
|
let classes = obj.items[i]["classes"] ? obj.items[i]["classes"] : []
|
|
|
|
items += `<button id="${obj.name}-${obj.items[i]["action"]}" class="switch${classes.length > 0 ? ' ' + classes.join(' ') : ''}" onclick="changeSwitcher('${obj.name}', '${obj.items[i]["action"]}')">${obj.items[i]["text"] ? obj.items[i]["text"] : obj.items[i]["action"]}</button>`
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-04-03 17:36:23 +01:00
|
|
|
|
2023-05-18 18:05:29 +01:00
|
|
|
if (obj.noParent) return `<div id="${obj.name}" class="switches">${items}</div>`;
|
2023-01-29 18:17:33 +00:00
|
|
|
return `<div id="${obj.name}-switcher" class="switch-container">
|
2022-08-12 14:36:19 +01:00
|
|
|
${obj.subtitle ? `<div class="subtitle">${obj.subtitle}</div>` : ``}
|
|
|
|
<div class="switches">${items}</div>
|
|
|
|
${obj.explanation ? `<div class="explanation">${obj.explanation}</div>` : ``}
|
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
|
2023-01-29 18:17:33 +00:00
|
|
|
export function checkbox(action, text, paddingType, aria) {
|
2022-09-28 13:21:36 +01:00
|
|
|
let paddingClass = ` `
|
|
|
|
switch (paddingType) {
|
|
|
|
case 1:
|
|
|
|
paddingClass += "bottom-margin"
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
paddingClass += "top-margin"
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
paddingClass += "no-margin"
|
|
|
|
break;
|
2023-01-29 18:17:33 +00:00
|
|
|
case 4:
|
|
|
|
paddingClass += "top-margin-only"
|
2022-09-28 13:21:36 +01:00
|
|
|
}
|
|
|
|
return `<label id="${action}-chkbx" class="checkbox${paddingClass}">
|
2022-10-02 15:13:33 +01:00
|
|
|
<input id="${action}" type="checkbox" ${aria ? `aria-label="${aria}"` : `aria-label="${text}"`} onclick="checkbox('${action}')">
|
2022-08-12 14:36:19 +01:00
|
|
|
<span>${text}</span>
|
|
|
|
</label>`
|
|
|
|
}
|
2022-12-17 11:09:49 +00:00
|
|
|
export function sep(paddingType) {
|
|
|
|
let paddingClass = ``
|
|
|
|
switch(paddingType) {
|
|
|
|
case 0:
|
|
|
|
paddingClass += ` top-margin`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return `<div class="separator${paddingClass}"></div>`
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
export function popup(obj) {
|
|
|
|
let classes = obj.classes ? obj.classes : []
|
|
|
|
let body = obj.body;
|
|
|
|
if (Array.isArray(obj.body)) {
|
|
|
|
body = ``
|
|
|
|
for (let i = 0; i < obj.body.length; i++) {
|
2022-10-09 18:44:00 +01:00
|
|
|
if (obj.body[i]["text"].length > 0) {
|
|
|
|
classes = obj.body[i]["classes"] ? obj.body[i]["classes"] : []
|
2022-10-24 14:03:11 +01:00
|
|
|
if (i !== obj.body.length - 1 && !obj.body[i]["nopadding"]) {
|
2022-10-09 18:44:00 +01:00
|
|
|
classes.push("desc-padding")
|
|
|
|
}
|
|
|
|
body += obj.body[i]["raw"] ? obj.body[i]["text"] : `<div id="popup-desc" class="${classes.length > 0 ? classes.join(' ') : ''}">${obj.body[i]["text"]}</div>`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `
|
2022-08-19 18:54:20 +01:00
|
|
|
${obj.standalone ? `<div id="popup-${obj.name}" class="popup center box${classes.length > 0 ? ' ' + classes.join(' ') : ''}" style="visibility: hidden;">` : ''}
|
2022-08-12 14:36:19 +01:00
|
|
|
<div id="popup-header" class="popup-header">
|
2023-01-29 18:17:33 +00:00
|
|
|
${obj.standalone && !obj.buttonOnly ? `<button id="close-button" class="switch up" onclick="popup('${obj.name}', 0)" ${obj.header.closeAria ? `aria-label="${obj.header.closeAria}"` : ''}>x</button>` : ''}
|
|
|
|
${obj.buttonOnly ? obj.header.emoji : ``}
|
2022-08-22 15:10:54 +01:00
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
2022-08-12 14:36:19 +01:00
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}
|
|
|
|
</div>
|
2022-08-19 18:54:20 +01:00
|
|
|
<div id="popup-content"${obj.footer ? ' class="with-footer"' : ''}>
|
|
|
|
${body}${obj.buttonOnly ? `<button id="close-error" class="switch" onclick="popup('${obj.name}', 0)">${obj.buttonText}</button>` : ''}
|
|
|
|
</div>
|
2022-08-12 14:36:19 +01:00
|
|
|
${obj.footer ? `<div id="popup-footer" class="popup-footer">
|
2022-08-22 15:10:54 +01:00
|
|
|
<a id="popup-bottom" class="popup-footer-content" target="_blank" href="${obj.footer.url}">${obj.footer.text}</a>
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>` : ''}
|
2022-08-19 18:54:20 +01:00
|
|
|
${obj.standalone ? `</div>` : ''}`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function multiPagePopup(obj) {
|
|
|
|
let tabs = ``
|
|
|
|
let tabContent = ``
|
|
|
|
for (let i = 0; i < obj.tabs.length; i++) {
|
|
|
|
tabs += `<button id="tab-button-${obj.name}-${obj.tabs[i]["name"]}" class="switch tab tab-${obj.name}" onclick="changeTab(event, 'tab-${obj.name}-${obj.tabs[i]["name"]}', '${obj.name}')">${obj.tabs[i]["title"]}</button>`
|
|
|
|
tabContent += `<div id="tab-${obj.name}-${obj.tabs[i]["name"]}" class="popup-tab-content tab-content-${obj.name}">${obj.tabs[i]["content"]}</div>`
|
|
|
|
}
|
|
|
|
return `
|
|
|
|
<div id="popup-${obj.name}" class="popup center box scrollable" style="visibility: hidden;">
|
|
|
|
<div id="popup-content">${obj.header ? `<div id="popup-header" class="popup-header">
|
2022-08-22 15:10:54 +01:00
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
2022-08-12 14:36:19 +01:00
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
2022-08-16 08:14:19 +01:00
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}</div>` : ''}${tabContent}</div>
|
2023-05-19 11:13:38 +01:00
|
|
|
<div id="popup-tabs" class="switches popup-tabs"><div class="switches popup-tabs-child">${tabs}</div><button id="close-button" class="switch tab-${obj.name}" onclick="popup('${obj.name}', 0)" ${obj.closeAria ? `aria-label="${obj.closeAria}"` : ''}>x</button></div>
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>`
|
|
|
|
}
|
2023-01-29 18:17:33 +00:00
|
|
|
export function collapsibleList(arr) {
|
|
|
|
let items = ``
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
items += `<div id="${arr[i]["name"]}-collapse" class="collapse-list">
|
|
|
|
<div class="collapse-header" onclick="expandCollapsible(event)">
|
|
|
|
<div class="collapse-title">${arr[i]["title"]}</div>
|
|
|
|
<div class="collapse-indicator">^</div>
|
|
|
|
</div>
|
|
|
|
<div id="${arr[i]["name"]}-body" class="collapse-body">${arr[i]["body"]}</div>
|
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
2022-09-03 16:32:39 +01:00
|
|
|
export function popupWithBottomButtons(obj) {
|
|
|
|
let tabs = ``
|
|
|
|
for (let i = 0; i < obj.buttons.length; i++) {
|
|
|
|
tabs += obj.buttons[i]
|
|
|
|
}
|
2023-01-29 18:17:33 +00:00
|
|
|
tabs += `<button id="close-button" class="switch tab-${obj.name}" onclick="popup('${obj.name}', 0)" ${obj.closeAria ? `aria-label="${obj.closeAria}"` : ''}>x</button>`
|
2022-09-03 16:32:39 +01:00
|
|
|
return `
|
|
|
|
<div id="popup-${obj.name}" class="popup center box scrollable" style="visibility: hidden;">
|
|
|
|
<div id="popup-content">${obj.header ? `<div id="popup-header" class="popup-header">
|
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}
|
|
|
|
${obj.header.explanation ? `<div class="explanation">${obj.header.explanation}</div>` : ''}</div>` : ''}${obj.content}</div>
|
|
|
|
<div id="popup-buttons" class="switches popup-tabs">${tabs}</div>
|
|
|
|
</div>`
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
export function backdropLink(link, text) {
|
2023-01-29 18:17:33 +00:00
|
|
|
return `<a class="text-backdrop italic" href="${link}" target="_blank">${text}</a>`
|
|
|
|
}
|
2023-05-16 21:31:22 +01:00
|
|
|
export function socialLink(emji, name, handle, url) {
|
|
|
|
return `<div class="cobalt-support-link">${emji} ${name}: <a class="text-backdrop italic" href="${url}" target="_blank">${handle}</a></div>`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
export function settingsCategory(obj) {
|
|
|
|
return `<div id="settings-${obj.name}" class="settings-category">
|
|
|
|
<div class="category-title">${obj.title ? obj.title : obj.name}</div>
|
2023-01-29 18:17:33 +00:00
|
|
|
<div class="category-content">${obj.body}</div>
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function footerButtons(obj) {
|
|
|
|
let items = ``
|
|
|
|
for (let i = 0; i < obj.length; i++) {
|
2022-09-08 17:02:55 +01:00
|
|
|
switch (obj[i]["type"]) {
|
|
|
|
case "toggle":
|
2022-10-02 15:13:33 +01:00
|
|
|
items += `<button id="${obj[i]["name"]}-footer" class="switch footer-button" onclick="toggle('${obj[i]["name"]}')" aria-label="${obj[i]["aria"]}">${obj[i]["text"]}</button>`;
|
2022-09-08 17:02:55 +01:00
|
|
|
break;
|
|
|
|
case "action":
|
2022-10-02 15:13:33 +01:00
|
|
|
items += `<button id="${obj[i]["name"]}-footer" class="switch footer-button" onclick="${obj[i]["action"]}()" aria-label="${obj[i]["aria"]}">${obj[i]["text"]}</button>`;
|
2022-09-08 17:02:55 +01:00
|
|
|
break;
|
|
|
|
case "popup":
|
2023-05-16 21:13:11 +01:00
|
|
|
let buttonName = obj[i]["context"] ? `${obj[i]["name"]}-${obj[i]["context"]}` : obj[i]["name"],
|
|
|
|
context = obj[i]["context"] ? `, '${obj[i]["context"]}'` : '',
|
|
|
|
buttonName2,
|
|
|
|
context2;
|
|
|
|
|
|
|
|
if (obj[i+1]) {
|
|
|
|
buttonName2 = obj[i+1]["context"] ? `${obj[i+1]["name"]}-${obj[i+1]["context"]}` : obj[i+1]["name"];
|
|
|
|
context2 = obj[i+1]["context"] ? `, '${obj[i+1]["context"]}'` : '';
|
|
|
|
}
|
|
|
|
|
2022-11-20 13:46:08 +00:00
|
|
|
items += `
|
|
|
|
<div class="footer-pair">
|
2023-05-16 21:13:11 +01:00
|
|
|
<button id="${buttonName}-footer" class="switch footer-button" onclick="popup('${obj[i]["name"]}', 1${context})" aria-label="${obj[i]["aria"]}">${obj[i]["text"]}</button>
|
|
|
|
${obj[i+1] ? `<button id="${buttonName2}-footer" class="switch footer-button" onclick="popup('${obj[i+1]["name"]}', 1${context2})" aria-label="${obj[i+1]["aria"]}">${obj[i+1]["text"]}</button>`: ''}
|
2022-11-20 13:46:08 +00:00
|
|
|
</div>`;
|
2022-09-08 17:02:55 +01:00
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
return `
|
|
|
|
<div id="footer-buttons">${items}</div>`
|
|
|
|
}
|
2022-12-17 11:09:49 +00:00
|
|
|
export function explanation(text) {
|
|
|
|
return `<div class="explanation">${text}</div>`
|
|
|
|
}
|
2022-10-27 17:27:20 +01:00
|
|
|
export function celebrationsEmoji() {
|
2023-05-16 21:13:11 +01:00
|
|
|
try {
|
|
|
|
let n = new Date().toISOString().split('T')[0].split('-');
|
|
|
|
let dm = `${n[1]}-${n[2]}`;
|
|
|
|
let f = Object.keys(celebrations).includes(dm) ? celebrations[dm] : "🐲";
|
|
|
|
return f != "🐲" ? emoji(f, 22) : false;
|
|
|
|
} catch (e) {
|
|
|
|
return false
|
|
|
|
}
|
2022-10-27 17:27:20 +01:00
|
|
|
}
|