/** * Builds dropdown navigators for elements like: *
...
* * - Finds child elements whose id starts with prefix * - Uses their `title` attribute as label * - Scrolls to them on selection */ (function initInlineNavigators () { function smoothScrollToId (id) { const el = document.getElementById(id); if (!el) return; // If you have a sticky header, this helps avoid hiding the target under it: // Use CSS: scroll-margin-top on the target elements (recommended). el.scrollIntoView({ behavior: "smooth", block: "start" }); history.replaceState(null, "", "#" + encodeURIComponent(id)); } document.querySelectorAll(".inlineNavigator").forEach(nav => { const prefix = nav.dataset.targetPrefix || ""; if (!prefix) return; const scope = nav.parentElement; const select = nav.querySelector(".inlineNavigatorSelect"); if (!select) return; // Find elements with id starting with prefix, within scope const candidates = scope.querySelectorAll(`[id^="${CSS.escape(prefix)}"]`); // Clear old options (keep first "Select…" option if present) select.querySelectorAll("option:not(:first-child)").forEach(o => o.remove()); // Add options candidates.forEach(el => { const id = el.id; const label = (el.getAttribute("title") || "").trim() || id; const opt = document.createElement("option"); opt.value = id; opt.textContent = label; select.appendChild(opt); }); // If there are no targets, hide the whole widget if (candidates.length === 0) { nav.style.display = "none"; return; } // Scroll on selection select.addEventListener("change", () => { if (!select.value) return; smoothScrollToId(select.value); select.value = ""; // reset }); }); })();