// In-text links to a section on another (or the same) page of a book: // , 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. function set_link_listeners() { Array.from(document.getElementsByClassName("pagelink")).forEach( function (elt) { if (elt.getAttribute("data-bound")) { return; } elt.setAttribute("data-bound", "true"); elt.addEventListener("click", function(event) { event.preventDefault(); let basename = elt.getAttribute("data-page"); let id = elt.getAttribute("data-id"); go_to_section(elt, basename, id); }); }); } window.addEventListener("load", set_link_listeners);