add fully generated homepage
This commit is contained in:
1 parent
7a7f0129b3
commit
f9a5fe7e7d
6 files changed
+916
No files matched your search
@@ -0,0 +1,117 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var root = document.documentElement;
|
||||
var themeToggle = document.querySelector(".theme-toggle");
|
||||
var themeColor = document.getElementById("theme-color");
|
||||
var themeColors = { light: "#ffffff", dark: "#0b0b0c" };
|
||||
|
||||
function setTheme(theme, persist) {
|
||||
root.dataset.theme = theme;
|
||||
|
||||
if (themeToggle) {
|
||||
themeToggle.setAttribute("aria-pressed", String(theme === "dark"));
|
||||
}
|
||||
|
||||
if (themeColor) {
|
||||
themeColor.setAttribute("content", themeColors[theme]);
|
||||
}
|
||||
|
||||
if (persist) {
|
||||
try {
|
||||
localStorage.setItem("theme", theme);
|
||||
} catch (error) {
|
||||
/* Storage can be unavailable; the choice still applies for this visit. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setTheme(root.dataset.theme === "dark" ? "dark" : "light", false);
|
||||
|
||||
if (themeToggle) {
|
||||
themeToggle.addEventListener("click", function () {
|
||||
setTheme(root.dataset.theme === "dark" ? "light" : "dark", true);
|
||||
});
|
||||
}
|
||||
|
||||
var clock = document.getElementById("clock");
|
||||
|
||||
if (clock) {
|
||||
try {
|
||||
var timeFormat = new Intl.DateTimeFormat("de-CH", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
timeZone: "Europe/Zurich"
|
||||
});
|
||||
|
||||
var updateClock = function () {
|
||||
var now = new Date();
|
||||
clock.textContent = timeFormat.format(now);
|
||||
clock.setAttribute("datetime", now.toISOString());
|
||||
};
|
||||
|
||||
updateClock();
|
||||
window.setInterval(updateClock, 15000);
|
||||
} catch (error) {
|
||||
clock.textContent = "";
|
||||
}
|
||||
}
|
||||
|
||||
var year = document.getElementById("year");
|
||||
|
||||
if (year) {
|
||||
year.textContent = String(new Date().getFullYear());
|
||||
}
|
||||
|
||||
var dialogs = Array.prototype.slice.call(document.querySelectorAll("dialog"));
|
||||
|
||||
function syncScrollLock() {
|
||||
var hasOpenDialog = dialogs.some(function (dialog) {
|
||||
return dialog.open;
|
||||
});
|
||||
|
||||
document.body.classList.toggle("has-dialog", hasOpenDialog);
|
||||
}
|
||||
|
||||
document.querySelectorAll("[data-dialog]").forEach(function (button) {
|
||||
var dialog = document.getElementById(button.getAttribute("data-dialog"));
|
||||
|
||||
if (!dialog || typeof dialog.showModal !== "function") {
|
||||
return;
|
||||
}
|
||||
|
||||
button.addEventListener("click", function () {
|
||||
dialog.showModal();
|
||||
syncScrollLock();
|
||||
});
|
||||
});
|
||||
|
||||
dialogs.forEach(function (dialog) {
|
||||
var closeButton = dialog.querySelector(".dialog-close");
|
||||
|
||||
if (closeButton) {
|
||||
closeButton.addEventListener("click", function () {
|
||||
dialog.close();
|
||||
});
|
||||
}
|
||||
|
||||
dialog.addEventListener("click", function (event) {
|
||||
if (event.target !== dialog) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rect = dialog.getBoundingClientRect();
|
||||
var inside =
|
||||
event.clientX >= rect.left &&
|
||||
event.clientX <= rect.right &&
|
||||
event.clientY >= rect.top &&
|
||||
event.clientY <= rect.bottom;
|
||||
|
||||
if (!inside) {
|
||||
dialog.close();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.addEventListener("close", syncScrollLock);
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user