mirror of
https://gitlab.com/vyla-entertainment/documentation.git
synced 2026-11-19 17:07:22 -05:00
aded themes
This commit is contained in:
113
assets/app.js
113
assets/app.js
@@ -3,6 +3,13 @@ var ICONS = {
|
||||
system: '<rect x="2" y="3" width="20" height="14" rx="2"/><path d="M8 21h8M12 17v4"/>',
|
||||
light: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M6.3 17.7l-1.4 1.4M19.1 4.9l-1.4 1.4"/>',
|
||||
dark: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
|
||||
midnight: '<path d="M12 2a10 10 0 1 0 10 10A10 10 0 0 1 12 2Z"/>',
|
||||
nord: '<path d="m2 12 5-5 5 5 5-5 5 5"/><path d="M12 7v14"/>',
|
||||
dracula: '<path d="M7 3v7l5 3 5-3V3"/><path d="M7 14l5 7 5-7"/>',
|
||||
forest: '<path d="m12 2 7 12h-4l3 6H6l3-6H5z"/>',
|
||||
sunset: '<path d="M17 18a5 5 0 0 0-10 0"/><path d="M12 2v4M4.22 10.22l2.83 2.83M1 18h4M19 18h4M16.95 13.05l2.83-2.83M12 13a5 5 0 0 0-5 5h10a5 5 0 0 0-5-5z"/>',
|
||||
cyberpunk: '<path d="M4 4h16v16H4z"/><path d="M4 9h16M9 4v16"/>',
|
||||
halloween: '<circle cx="12" cy="12" r="9"/><path d="M9 10h.01M15 10h.01M8 15s1.5 2 4 2 4-2 4-2"/><path d="M12 3v3"/>',
|
||||
search: '<circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/>',
|
||||
menu: '<path d="M4 6h16M4 12h10M4 18h16"/>',
|
||||
doc: '<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5M9 13h6M9 17h6"/>',
|
||||
@@ -14,6 +21,33 @@ var ICONS = {
|
||||
chevronRight: '<path d="m9 18 6-6-6-6"/>'
|
||||
};
|
||||
|
||||
var THEMES_GENERAL = [
|
||||
{ id: "dark", label: "Dark" },
|
||||
{ id: "light", label: "Light" },
|
||||
{ id: "midnight", label: "Midnight" },
|
||||
{ id: "nord", label: "Nord" },
|
||||
{ id: "dracula", label: "Dracula" },
|
||||
{ id: "forest", label: "Forest" },
|
||||
{ id: "sunset", label: "Sunset" },
|
||||
{ id: "cyberpunk", label: "Cyberpunk" }
|
||||
];
|
||||
|
||||
var THEMES_SEASONAL = [
|
||||
{ id: "halloween", label: "Halloween" }
|
||||
];
|
||||
|
||||
var THEME_VIDEOS = {
|
||||
halloween: "https://www.pexels.com/download/video/5605039/",
|
||||
dark: "https://www.pexels.com/download/video/31270356/",
|
||||
light: "https://www.pexels.com/download/video/13956986/",
|
||||
midnight: "https://www.pexels.com/download/video/15860507/",
|
||||
nord: "https://www.pexels.com/download/video/31468607/",
|
||||
dracula: "https://www.pexels.com/download/video/8116002/",
|
||||
forest: "https://www.pexels.com/download/video/11265968/",
|
||||
sunset: "https://www.pexels.com/download/video/855437/",
|
||||
cyberpunk: "https://www.pexels.com/download/video/32336464/"
|
||||
};
|
||||
|
||||
var SITE_TREE = [
|
||||
{
|
||||
id: "vyla",
|
||||
@@ -116,25 +150,32 @@ function esc(s) {
|
||||
}
|
||||
|
||||
function getThemeMode() {
|
||||
var v = localStorage.getItem(THEME_KEY);
|
||||
return v === "light" || v === "dark" ? v : "system";
|
||||
return localStorage.getItem(THEME_KEY) || "halloween";
|
||||
}
|
||||
|
||||
function applyTheme() {
|
||||
var mode = getThemeMode();
|
||||
var dark = mode === "dark" || (mode === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches);
|
||||
document.documentElement.classList.toggle("dark", dark);
|
||||
document.documentElement.setAttribute("data-theme", mode);
|
||||
var logo = document.getElementById("brand-logo");
|
||||
if (logo) logo.src = dark ? "/assets/images/logo.png" : "/assets/images/dark_logo.png";
|
||||
if (logo) logo.src = mode === "light" ? "/assets/images/dark_logo.png" : "/assets/images/logo.png";
|
||||
var targetSrc = THEME_VIDEOS[mode] || THEME_VIDEOS.halloween;
|
||||
document.querySelectorAll(".body-blurred-video, .header-video").forEach(function (v) {
|
||||
if (v.getAttribute("src") !== targetSrc) {
|
||||
v.src = targetSrc;
|
||||
v.load();
|
||||
v.play().catch(function () { });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setTheme(mode) {
|
||||
if (mode === "system") localStorage.removeItem(THEME_KEY);
|
||||
else localStorage.setItem(THEME_KEY, mode);
|
||||
localStorage.setItem(THEME_KEY, mode);
|
||||
applyTheme();
|
||||
refreshThemeUI();
|
||||
var menu = document.getElementById("theme-menu");
|
||||
if (menu) menu.classList.remove("open");
|
||||
var segMenu = document.getElementById("theme-seg-menu");
|
||||
if (segMenu) segMenu.classList.remove("open");
|
||||
}
|
||||
|
||||
function toggleThemeMenu(e) {
|
||||
@@ -146,10 +187,16 @@ function toggleThemeMenu(e) {
|
||||
function refreshThemeUI() {
|
||||
var mode = getThemeMode();
|
||||
var btn = document.getElementById("theme-toggle");
|
||||
if (btn) btn.innerHTML = icon(mode);
|
||||
document.querySelectorAll("#theme-menu button, #theme-seg button").forEach(function (b) {
|
||||
if (btn) btn.innerHTML = icon(ICONS[mode] ? mode : "dark");
|
||||
document.querySelectorAll("#theme-menu button, #theme-seg button[data-mode], #theme-seg-menu button").forEach(function (b) {
|
||||
b.classList.toggle("on", b.getAttribute("data-mode") === mode);
|
||||
});
|
||||
var moreBtn = document.getElementById("theme-seg-more");
|
||||
if (moreBtn) {
|
||||
var isOther = mode !== "dark" && mode !== "light";
|
||||
moreBtn.classList.toggle("on", isOther);
|
||||
moreBtn.innerHTML = icon(ICONS[mode] ? mode : "halloween");
|
||||
}
|
||||
}
|
||||
|
||||
function buildThemeControls() {
|
||||
@@ -160,12 +207,18 @@ function buildThemeControls() {
|
||||
wrap.className = "theme-wrap";
|
||||
btn.parentNode.insertBefore(wrap, btn);
|
||||
wrap.appendChild(btn);
|
||||
var modes = ["system", "light", "dark"];
|
||||
var menu = document.createElement("div");
|
||||
menu.id = "theme-menu";
|
||||
menu.innerHTML = modes.map(function (m) {
|
||||
return '<button type="button" data-mode="' + m + '">' + icon(m) + '<span>' + m.charAt(0).toUpperCase() + m.slice(1) + '</span><i class="check">✓</i></button>';
|
||||
}).join("");
|
||||
var html = '<div class="theme-menu-label">General</div>';
|
||||
THEMES_GENERAL.forEach(function (t) {
|
||||
html += '<button type="button" data-mode="' + t.id + '">' + icon(t.id) + '<span>' + esc(t.label) + '</span><i class="check">✓</i></button>';
|
||||
});
|
||||
html += '<div class="theme-menu-divider"></div>';
|
||||
html += '<div class="theme-menu-label">Seasonal</div>';
|
||||
THEMES_SEASONAL.forEach(function (t) {
|
||||
html += '<button type="button" data-mode="' + t.id + '">' + icon(t.id) + '<span>' + esc(t.label) + '</span><i class="check">✓</i></button>';
|
||||
});
|
||||
menu.innerHTML = html;
|
||||
wrap.appendChild(menu);
|
||||
menu.addEventListener("click", function (e) {
|
||||
var b = e.target.closest("button");
|
||||
@@ -586,16 +639,35 @@ function buildMobileBar(currentTab, currentItem) {
|
||||
var sideLinks = document.createElement("div");
|
||||
sideLinks.className = "side-links";
|
||||
|
||||
var modes = ["system", "light", "dark"];
|
||||
var seg = document.createElement("div");
|
||||
seg.id = "theme-seg";
|
||||
seg.innerHTML = modes.map(function (m) {
|
||||
return '<button type="button" data-mode="' + m + '" aria-label="' + m + '">' + icon(m) + '</button>';
|
||||
}).join("");
|
||||
var segHtml = '<button type="button" data-mode="dark" aria-label="Dark">' + icon("dark") + '</button>' +
|
||||
'<button type="button" data-mode="light" aria-label="Light">' + icon("light") + '</button>' +
|
||||
'<button type="button" id="theme-seg-more" aria-label="All themes">' + icon("halloween") + '</button>' +
|
||||
'<div id="theme-seg-menu">' +
|
||||
'<div class="theme-menu-label">General</div>';
|
||||
THEMES_GENERAL.forEach(function (t) {
|
||||
segHtml += '<button type="button" data-mode="' + t.id + '">' + icon(t.id) + '<span>' + esc(t.label) + '</span><i class="check">✓</i></button>';
|
||||
});
|
||||
segHtml += '<div class="theme-menu-divider"></div><div class="theme-menu-label">Seasonal</div>';
|
||||
THEMES_SEASONAL.forEach(function (t) {
|
||||
segHtml += '<button type="button" data-mode="' + t.id + '">' + icon(t.id) + '<span>' + esc(t.label) + '</span><i class="check">✓</i></button>';
|
||||
});
|
||||
segHtml += '</div>';
|
||||
seg.innerHTML = segHtml;
|
||||
|
||||
seg.addEventListener("click", function (e) {
|
||||
var btn = e.target.closest("button");
|
||||
if (btn) setTheme(btn.getAttribute("data-mode"));
|
||||
var moreBtn = e.target.closest("#theme-seg-more");
|
||||
var segMenu = document.getElementById("theme-seg-menu");
|
||||
if (moreBtn && segMenu) {
|
||||
segMenu.classList.toggle("open");
|
||||
return;
|
||||
}
|
||||
var btn = e.target.closest("button[data-mode]");
|
||||
if (btn) {
|
||||
setTheme(btn.getAttribute("data-mode"));
|
||||
if (segMenu) segMenu.classList.remove("open");
|
||||
}
|
||||
});
|
||||
|
||||
sideLinks.appendChild(seg);
|
||||
@@ -812,6 +884,7 @@ function loadPage() {
|
||||
})
|
||||
.then(function (html) {
|
||||
contentEl.innerHTML = html;
|
||||
applyTheme();
|
||||
window.scrollTo(0, 0);
|
||||
})
|
||||
.catch(function () {
|
||||
@@ -1152,7 +1225,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
var sidebar = document.getElementById("sidebar");
|
||||
var menu = document.getElementById("theme-menu");
|
||||
var segMenu = document.getElementById("theme-seg-menu");
|
||||
if (menu && !e.target.closest(".theme-wrap")) menu.classList.remove("open");
|
||||
if (segMenu && !e.target.closest("#theme-seg")) segMenu.classList.remove("open");
|
||||
if (
|
||||
sidebar &&
|
||||
sidebar.classList.contains("open") &&
|
||||
|
||||
Reference in New Issue
Block a user