2026-07-18 18:48:23 +02:00
|
|
|
|
2026-10-12 20:55:39 +02:00
|
|
|
// In-text links to a section on another (or the same) page of a book:
|
|
|
|
|
// <a class="pagelink" data-page="BASENAME" data-id="ID">, which @document
|
|
|
|
|
// emits for @link ... :section @ (document_html.cpp, resolve_section_links).
|
|
|
|
|
// go_to_section() swaps in the embedded page and scrolls to the id, and
|
|
|
|
|
// calls this again for the links of the page it just showed. Each anchor
|
|
|
|
|
// is bound once: a page shown twice is the same nodes bound twice otherwise.
|
2026-07-18 18:48:23 +02:00
|
|
|
function set_link_listeners() {
|
|
|
|
|
Array.from(document.getElementsByClassName("pagelink")).forEach(
|
|
|
|
|
function (elt) {
|
2026-10-12 20:55:39 +02:00
|
|
|
if (elt.getAttribute("data-bound")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
elt.setAttribute("data-bound", "true");
|
2026-07-18 18:48:23 +02:00
|
|
|
elt.addEventListener("click", function(event) {
|
2026-10-12 20:55:39 +02:00
|
|
|
event.preventDefault();
|
2026-07-18 18:48:23 +02:00
|
|
|
let basename = elt.getAttribute("data-page");
|
|
|
|
|
let id = elt.getAttribute("data-id");
|
|
|
|
|
go_to_section(elt, basename, id);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-12 20:55:39 +02:00
|
|
|
window.addEventListener("load", set_link_listeners);
|