From 61db75bd76aa378ce2654aac3ede0088fd5642a7 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 11 Mar 2026 14:13:57 +0100 Subject: [PATCH] fix: hide TOC widget wrapper when no headings found When tocScanner finds no .e-content or fewer than 3 headings, hide the parent .widget-collapsible container so the empty collapsible chrome (header button, border) doesn't show. Confab-Link: http://localhost:8080/sessions/cc343b15-8d10-43cd-a48f-ca912eb79b83 --- js/toc-scanner.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/toc-scanner.js b/js/toc-scanner.js index 1b0f904..5bc11f0 100644 --- a/js/toc-scanner.js +++ b/js/toc-scanner.js @@ -11,10 +11,10 @@ document.addEventListener("alpine:init", () => { init() { const content = document.querySelector(".e-content"); - if (!content) return; + if (!content) { this._hideWrapper(); return; } const headings = content.querySelectorAll("h2[id], h3[id], h4[id]"); - if (headings.length < 3) return; + if (headings.length < 3) { this._hideWrapper(); return; } this.items = Array.from(headings).map((h) => ({ id: h.id, @@ -39,6 +39,11 @@ document.addEventListener("alpine:init", () => { headings.forEach((h) => this._observer.observe(h)); }, + _hideWrapper() { + const wrapper = this.$root.closest(".widget-collapsible"); + if (wrapper) wrapper.style.display = "none"; + }, + destroy() { if (this._observer) this._observer.disconnect(); },