(function () { const HEADER_TAGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; const IN_PAGE_NAV_HTML_CLASS = 'in-page-toc'; const SCROLLABLE_NAV_CONTAINER_SELECTOR = 'ul.nav-items'; /* Given a container of AsciiDoc .sectN elementss, * returns an object containing navigation structure like this: * { items: [ { title: "Some title", path: "./#some-title", items: [ ...subitems ] }, ... } * Works recursively through nested sections. */ function getAdocTocItems(containerEl, sectLvl) { sectLvl = sectLvl || 1; var items = []; const topLevelSections = Array.from(containerEl.children).filter((el) => { return el.matches(`div.sect${sectLvl}`); }); for (let sectionEl of topLevelSections) { const headerEl = Array.from(sectionEl.children).filter((el) => { for (let hTagName of HEADER_TAGS) { if (el.matches(hTagName)) { return true; } } return false; })[0]; const headerId = headerEl.getAttribute('id'); var subItems = []; const sectionBody = sectionEl.querySelector('div.sectionbody'); if (sectionBody) { subItems = getAdocTocItems(sectionBody, sectLvl + 1); } else { subItems = getAdocTocItems(sectionEl, sectLvl + 1); } items.push({ title: headerEl.innerText, description: headerEl.innerText, path: `./#${headerId}`, items: subItems, id: headerId, }); } return items; } function highlightSelected(headerId, itemPath) { let selectedItemEl; for (const itemEl of document.querySelectorAll(`.${IN_PAGE_NAV_HTML_CLASS} li`)) { const link = (itemEl.firstChild || {}).firstChild; if (link && link.getAttribute('href') == itemPath) { itemEl.classList.add('highlighted'); selectedItemEl = itemEl; } else { itemEl.classList.remove('highlighted'); } } for (const hTag of HEADER_TAGS) { for (const headerEl of document.querySelectorAll(hTag)) { headerEl.classList.remove('highlighted'); } } const selectedHeaderEl = document.getElementById(headerId); selectedHeaderEl.classList.add('highlighted'); return selectedItemEl; } /* Given a list of navigation items, returns an