Jacky Zhao
2023-06-17 8bfee04c8c6948a88114d53769d4bb89b8ec7bf5
quartz/components/scripts/toc.inline.ts
@@ -14,19 +14,26 @@
  }
})
function toggleCollapsible(this: HTMLElement) {
function toggleToc(this: HTMLElement) {
  this.classList.toggle("collapsed")
  const content = this.nextElementSibling as HTMLElement
  content.classList.toggle("collapsed")
  content.style.maxHeight = content.style.maxHeight === "0px" ? content.scrollHeight + "px" : "0px"
}
function setupToc() {
  const toc = document.getElementById("toc")
  if (toc) {
    const content = toc.nextElementSibling as HTMLElement
    content.style.maxHeight = content.scrollHeight + "px"
    toc.removeEventListener("click", toggleToc)
    toc.addEventListener("click", toggleToc)
  }
}
window.addEventListener("resize", setupToc)
document.addEventListener("nav", () => {
  const toc = document.getElementById("toc")!
  const content = toc.nextElementSibling as HTMLElement
  content.style.maxHeight = content.scrollHeight + "px"
  toc.removeEventListener("click", toggleCollapsible)
  toc.addEventListener("click", toggleCollapsible)
  setupToc()
  // update toc entry highlighting
  observer.disconnect()