36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
// Admin dashboard utilities
|
|
|
|
// Format JSON for display in modals
|
|
function formatJSON(json) {
|
|
try {
|
|
const parsed = typeof json === "string" ? JSON.parse(json) : json;
|
|
return JSON.stringify(parsed, null, 2);
|
|
} catch (e) {
|
|
return json;
|
|
}
|
|
}
|
|
|
|
// Handle HTMX navigation for admin sections
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
// Update active nav item after HTMX navigation
|
|
document.body.addEventListener("htmx:afterSwap", function (event) {
|
|
if (event.detail.target.id === "admin-content") {
|
|
// Get the current URL path
|
|
const path = window.location.pathname;
|
|
const section = path.split("/").pop() || "users";
|
|
|
|
// Update active state on nav items
|
|
document.querySelectorAll("nav a").forEach(function (link) {
|
|
const href = link.getAttribute("href");
|
|
if (href && href.includes("/" + section)) {
|
|
link.classList.remove("text-subtext0", "hover:bg-surface1", "hover:text-text");
|
|
link.classList.add("bg-blue", "text-mantle", "font-semibold");
|
|
} else {
|
|
link.classList.remove("bg-blue", "text-mantle", "font-semibold");
|
|
link.classList.add("text-subtext0", "hover:bg-surface1", "hover:text-text");
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|