// Populate the sidebar
//
// This is a script, and not included directly in the page, to control the total size of the book.
// The TOC contains an entry for each page, so if each page includes a copy of the TOC,
// the total size of the page becomes O(n**2).
class MDBookSidebarScrollbox extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = '
- 1. carapace-bin
❱
- 1.1. Install
❱
- 1.1.1. Selfupdate
- 1.2. Setup
❱
- 1.2.1. Environment
- 1.3. Completers
- 1.4. Style
- 1.5. Bridges
- 1.6. Spec
❱
- 1.6.1. User
- 1.6.2. Bridge
- 1.6.3. Embed
- 1.6.4. Run
- 1.6.5. Shim
- 1.6.6. Scrape
- 1.6.7. Codegen
- 1.6.8. Examples
- 1.6.9. Macros
- 1.7. Overlay
- 1.8. Variable
❱
- 1.8.1. Conditions
- 1.9. Development
❱
- 1.9.1. Project Layout
- 1.9.2. Build
- 1.9.3. Docker
- 1.9.4. Creating Completers
❱
- 1.9.4.1. Manually
- 1.9.4.2. Parsing
- 1.9.4.3. Scraping
- 1.9.4.4. Examples
- 1.9.5. Updating Completers
- 1.9.6. Best Practices
❱
- 1.9.6.1. Coupled Actions
- 1.9.7. Tools
❱
- 1.9.7.1. carapace-fmt
- 1.9.7.2. carapace-lint
- 1.9.7.3. carapace-parse
- 1.9.7.4. carapace-generate
- 1.10. Release Notes
❱
- 1.10.1. v1.x
- 1.10.2. v1.3
- 1.10.3. v1.2
- 1.10.4. v1.1
- 1.10.5. v1.0
- 1.10.6. v0.30
- 1.10.7. v0.29
- 1.10.8. v0.28
- 1.10.9. v0.27
- 1.10.10. v0.26
- 1.10.11. v0.25
- 1.10.12. v0.24
- 1.10.13. v0.23
- 1.10.14. v0.22
- 1.10.15. v0.21
- 1.10.16. v0.20
- 1.10.17. v0.19
- 1.10.18. v0.18
- 1.10.19. v0.17
- 1.10.20. v0.16
- 1.10.21. v0.15
- 1.10.22. v0.14
- 1.10.23. v0.13
- 1.10.24. v0.12
- 1.10.25. v0.11
';
// Set the current, active page, and reveal it if it's hidden
let current_page = document.location.href.toString();
if (current_page.endsWith("/")) {
current_page += "index.html";
}
var links = Array.prototype.slice.call(this.querySelectorAll("a"));
var l = links.length;
for (var i = 0; i < l; ++i) {
var link = links[i];
var href = link.getAttribute("href");
if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
link.href = path_to_root + href;
}
// The "index" page is supposed to alias the first chapter in the book.
if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html"))) {
link.classList.add("active");
var parent = link.parentElement;
if (parent && parent.classList.contains("chapter-item")) {
parent.classList.add("expanded");
}
while (parent) {
if (parent.tagName === "LI" && parent.previousElementSibling) {
if (parent.previousElementSibling.classList.contains("chapter-item")) {
parent.previousElementSibling.classList.add("expanded");
}
}
parent = parent.parentElement;
}
}
}
// Track and set sidebar scroll position
this.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', this.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
this.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
// Toggle buttons
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
function toggleSection(ev) {
ev.currentTarget.parentElement.classList.toggle('expanded');
}
Array.from(sidebarAnchorToggles).forEach(function (el) {
el.addEventListener('click', toggleSection);
});
}
}
window.customElements.define("mdbook-sidebar-scrollbox", MDBookSidebarScrollbox);