From 04acc4bb30aafb4f8dff83822c1d0563fb549f95 Mon Sep 17 00:00:00 2001 From: Kris Date: Mon, 11 Dec 2023 16:17:46 -0500 Subject: [PATCH] FIX: only add classes if TOC is present (#70) --- javascripts/discourse/initializers/disco-toc-main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/javascripts/discourse/initializers/disco-toc-main.js b/javascripts/discourse/initializers/disco-toc-main.js index 8a984eb..4324a7c 100644 --- a/javascripts/discourse/initializers/disco-toc-main.js +++ b/javascripts/discourse/initializers/disco-toc-main.js @@ -82,13 +82,15 @@ export default { ); api.onAppEvent("topic:current-post-changed", (args) => { + const hasCookedTOC = document.querySelector(".d-toc-cooked"); + // manages the timeline area width via CSS - if (document.querySelector(".d-toc-cooked")) { + if (hasCookedTOC) { document.body.classList.add("d-toc-available"); } // manages timeline visibility - if (args.post.post_number === 1) { + if (hasCookedTOC && args.post.post_number === 1) { if (!TOChidden) { handleButtonAndBody("show"); } else { @@ -96,7 +98,7 @@ export default { } // don't show the toggle if there's only 1 post - if (args.post.topic.posts_count !== 1) { + if (hasCookedTOC && args.post.topic.posts_count !== 1) { document.body.classList.add("d-toc-timeline-toggleable"); } } else {