split javascript file into multiple
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user