split javascript file into multiple

This commit is contained in:
2026-09-21 21:25:31 +02:00
parent b09f2029ed
commit cc91f7d4ff
17 changed files with 473 additions and 461 deletions
+14
View File
@@ -0,0 +1,14 @@
export function setCookie(name, value, maxAge) {
document.cookie = `${name}=${value}; path=/; max-age=${maxAge}`;
}
export function getCookie(name) {
const cookies = document.cookie.split("; ");
for (let c of cookies) {
const [key, value] = c.split("=");
if (key === name) return value;
}
return null;
}
+9
View File
@@ -0,0 +1,9 @@
export async function loadContent(lang) {
const response = await fetch(`./lang/${lang}.json`);
return response.json();
}
export async function loadImageConfig() {
const response = await fetch("./config/img_config.json");
return response.json();
}
+19
View File
@@ -0,0 +1,19 @@
export function formatDate(date, locale) {
const dateObj = new Date(date);
if (isNaN(dateObj.getTime())) {
return date;
}
return new Intl.DateTimeFormat(locale || "de-DE", {
dateStyle: "medium"
}).format(dateObj);
}
// "from <start> to <end>", with the wording taken from the language file.
export function formatDateRange(item) {
const startDate = formatDate(item.start, item.locale);
const endDate = formatDate(item.end, item.locale);
return item.from + "\n" + startDate + "\n" + item.to + "\n" + endDate;
}
+7
View File
@@ -0,0 +1,7 @@
// Creates an element with an optional class name and text content.
export function el(tag, className, text) {
const element = document.createElement(tag);
if (className) element.className = className;
if (text !== undefined) element.textContent = text;
return element;
}