/* Shared chrome for panel UI page mockups. Each screen is its own HTML file; this script injects radios, gallery, nav, sprite, and the help drawer so file:// viewing does not need a module fetch. */ (function () { if (document.body.dataset.shell === "1") return; document.body.dataset.shell = "1"; var main = document.querySelector("main"); if (!main) return; var page = document.body.getAttribute("data-page") || ""; var navKey = document.body.getAttribute("data-nav") || page; var title = document.body.getAttribute("data-title") || document.title; var globalOnly = document.body.getAttribute("data-global-only") === "1"; document.body.insertAdjacentHTML("afterbegin", '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' ); var q = new URLSearchParams(location.search); if (q.get("view") === "phone") document.getElementById("vp-phone").checked = true; if (q.get("role") === "domain") document.getElementById("role-domain").checked = true; if (q.get("theme") === "dark") document.getElementById("theme-dark").checked = true; if (q.get("inbound") === "0") document.getElementById("feat-inbound").checked = false; var gallery = '"; var sprite = '"; function icon(id) { return ''; } var navHtml = '"; var phone = '
' + '" + '' + '' + '' + "
"; var help = '' + '"; var app = document.createElement("div"); app.className = "app"; app.innerHTML = navHtml + '
' + phone + "
"; main.parentNode.insertBefore(app, main); app.insertAdjacentHTML("beforebegin", gallery + sprite); app.querySelector(".stage").appendChild(main); app.insertAdjacentHTML("afterend", help); var cur = app.querySelector(".n-" + navKey); if (cur) cur.setAttribute("aria-current", "page"); var grow = app.querySelector(".phone-title"); if (grow) grow.textContent = title; var skip = { "index.html": 1, "system.html": 1, "app.html": 1 }; function qs() { var p = new URLSearchParams(); if (document.getElementById("vp-phone").checked) p.set("view", "phone"); if (document.getElementById("role-domain").checked) p.set("role", "domain"); if (document.getElementById("theme-dark").checked) p.set("theme", "dark"); if (!document.getElementById("feat-inbound").checked) p.set("inbound", "0"); var s = p.toString(); return s ? "?" + s : ""; } function withQuery(href) { if (!href) return href; if (href.charAt(0) === "#" || /^(https?:|mailto:|javascript:)/i.test(href)) return href; var hash = ""; var path = href; var hashAt = href.indexOf("#"); if (hashAt >= 0) { hash = href.slice(hashAt); path = href.slice(0, hashAt); } var qAt = path.indexOf("?"); var file = qAt >= 0 ? path.slice(0, qAt) : path; var extra = qAt >= 0 ? path.slice(qAt + 1) : ""; var base = file.split("/").pop(); if (!base || !/\.html$/i.test(base) || skip[base]) return href; var p = new URLSearchParams(extra); var curQs = new URLSearchParams(qs().replace(/^\?/, "")); ["view", "role", "theme", "inbound"].forEach(function (k) { if (curQs.has(k)) p.set(k, curQs.get(k)); else p.delete(k); }); var s = p.toString(); return base + (s ? "?" + s : "") + hash; } function rewriteLinks() { document.querySelectorAll("a[href]").forEach(function (a) { var raw = a.getAttribute("href"); if (!raw) return; a.setAttribute("href", withQuery(raw)); }); } function brandHref() { var brand = document.querySelector(".nav .brand"); if (!brand) return; brand.setAttribute("href", withQuery( document.getElementById("role-domain").checked ? "domains.html" : "status.html" )); } function gate() { brandHref(); if (!document.getElementById("role-domain").checked) return; if (globalOnly) location.replace(withQuery("domains.html")); } function syncUrl() { if (history.replaceState) { history.replaceState(null, "", location.pathname.split("/").pop() + qs() + location.hash); } rewriteLinks(); brandHref(); gate(); } ["role-global", "role-domain", "vp-desktop", "vp-phone", "theme-light", "theme-dark", "feat-inbound"].forEach(function (id) { var el = document.getElementById(id); if (el) el.addEventListener("change", syncUrl); }); document.querySelectorAll(".nav a").forEach(function (a) { a.addEventListener("click", function () { var open = document.getElementById("nav-open"); if (open) open.checked = false; }); }); rewriteLinks(); gate(); })();