Spaces:
Running
Running
File size: 3,688 Bytes
f2491d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | /**
* Cham OCR Studio — Interactive User Guide & Feature Manual Controller (/help)
* Provides ScrollSpy TOC, Reading Progress Bar, Mobile TOC Drawer, and Live Guide Search.
*/
(function () {
"use strict";
window.toggleHelpMobileToc = function () {
const sb = document.getElementById("help-sidebar");
if (sb) sb.classList.toggle("mobile-open");
};
window.filterHelpGuide = function (rawQuery) {
const q = String(rawQuery || "").trim().toLowerCase();
// Filter TOC items
document.querySelectorAll("#help-sidebar .toc-nav-item").forEach((li) => {
if (!q) {
li.style.display = "";
return;
}
li.style.display = li.innerText.toLowerCase().includes(q) ? "" : "none";
});
// Filter shortcut rows if searching inside shortcuts
document.querySelectorAll("#shortcuts-table tbody tr").forEach((row) => {
if (!q) {
row.style.display = "";
return;
}
row.style.display = row.innerText.toLowerCase().includes(q) ? "" : "none";
});
};
document.addEventListener("DOMContentLoaded", () => {
const progressBar = document.getElementById("help-progress-bar");
const links = Array.from(document.querySelectorAll(".toc-nav-link, .toc-sub-link"));
const NAV_OFFSET = 82;
const tracked = [];
links.forEach((link) => {
const href = link.getAttribute("href");
if (href && href.startsWith("#")) {
const target = document.querySelector(href);
if (target) {
tracked.push({ link, target });
link.addEventListener("click", (e) => {
e.preventDefault();
const top = target.getBoundingClientRect().top + window.pageYOffset - NAV_OFFSET;
window.scrollTo({ top, behavior: "smooth" });
history.pushState(null, "", href);
document.getElementById("help-sidebar")?.classList.remove("mobile-open");
});
}
}
});
function onScroll() {
const scrollTop = window.scrollY || document.documentElement.scrollTop;
const maxScroll = Math.max(1, document.documentElement.scrollHeight - window.innerHeight);
if (progressBar) {
progressBar.style.width = `${Math.min(100, Math.max(0, (scrollTop / maxScroll) * 100))}%`;
}
const probe = scrollTop + 120;
for (let i = tracked.length - 1; i >= 0; i--) {
const top = tracked[i].target.getBoundingClientRect().top + window.pageYOffset;
if (top <= probe) {
links.forEach((l) => l.classList.remove("active"));
tracked[i].link.classList.add("active");
break;
}
}
}
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
// Allow '/' or Ctrl+K on /help to focus the guide search input
document.addEventListener("keydown", (e) => {
if (((e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "K")) || (e.key === "/" && !["INPUT", "TEXTAREA"].includes(document.activeElement?.tagName || ""))) {
e.preventDefault();
const inp = document.getElementById("help-search-input");
if (inp) {
inp.focus();
inp.select();
}
}
});
});
})();
|