left4me/l4d2web/static/js/file-tree.js
mwiegand a11d030edd
feat(l4d2-web): overlay detail Files section with HTMX file tree + downloads
Adds a server-rendered collapsible file tree section to the overlay
detail page so users can verify what their script/workshop overlays
produced and pull individual artifacts (VPKs, configs) without SSH.
HTMX-driven lazy folder expansion with click-to-download via send_file;
symlinks land anywhere under LEFT4ME_ROOT (so workshop addons stream
from the shared cache) but escapes are refused. Same access rule as the
rest of the page (admin or owner). 39 new tests; full web suite green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 20:16:25 +02:00

15 lines
653 B
JavaScript

// Toggle expand/collapse for file-tree folder rows. HTMX handles the
// initial fetch (hx-trigger="click once"); this script handles every
// subsequent click without re-fetching.
(function () {
document.addEventListener("click", function (event) {
const button = event.target.closest(".file-tree-toggle");
if (!button) return;
const expanded = button.getAttribute("aria-expanded") === "true";
button.setAttribute("aria-expanded", expanded ? "false" : "true");
const children = button.nextElementSibling;
if (children && children.classList.contains("file-tree-children")) {
children.hidden = expanded;
}
});
})();