[gi-docgen/hide-toc: 1/2] template: Hide the toc navigation bar when searching




commit 41f947dc6a58590a0d7ea96527c202c272a5095b
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Sep 2 14:02:18 2021 +0100

    template: Hide the toc navigation bar when searching
    
    Just like we hide the main content block. This prevents misrendering
    when searching from a page with a table of contents.

 gidocgen/templates/basic/class.html     | 2 +-
 gidocgen/templates/basic/interface.html | 2 +-
 gidocgen/templates/basic/search.js      | 8 ++++++++
 gidocgen/templates/basic/struct.html    | 2 +-
 4 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/gidocgen/templates/basic/class.html b/gidocgen/templates/basic/class.html
index 8ebab5f..e484c55 100644
--- a/gidocgen/templates/basic/class.html
+++ b/gidocgen/templates/basic/class.html
@@ -52,7 +52,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
 {% endmacro %}
 
 {% block navbar %}
-<div class="toc">
+<div id="toc" class="toc">
   <nav aria-labelledby="toc-title">
     <p id="toc-title">Content</p>
     <ul class="toc-list">
diff --git a/gidocgen/templates/basic/interface.html b/gidocgen/templates/basic/interface.html
index 9bc62dd..1039039 100644
--- a/gidocgen/templates/basic/interface.html
+++ b/gidocgen/templates/basic/interface.html
@@ -51,7 +51,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
 {% endmacro %}
 
 {% block navbar %}
-<div class="toc">
+<div id="toc" class="toc">
   <nav aria-labelledby="toc-title">
     <p id="toc-title">Content</p>
     <ul class="toc-list">
diff --git a/gidocgen/templates/basic/search.js b/gidocgen/templates/basic/search.js
index c289353..b9b8b4a 100644
--- a/gidocgen/templates/basic/search.js
+++ b/gidocgen/templates/basic/search.js
@@ -35,6 +35,7 @@ const refs = {
     form: null,
     search: null,
     main: null,
+    toc: null,
 };
 
 let searchIndex = undefined;
@@ -56,6 +57,7 @@ function onDidLoadSearchIndex(data) {
     refs.form   = document.querySelector("#search-form");
     refs.search = document.querySelector("#search");
     refs.main   = document.querySelector("#main");
+    refs.toc    = document.querySelector("#toc");
 
     attachInputHandlers();
 
@@ -122,12 +124,18 @@ function search(query) {
 
 function showSearchResults() {
     addClass(refs.main, "hidden");
+    if (refs.toc) {
+        addClass(refs.toc, "hidden");
+    }
     removeClass(refs.search, "hidden");
 }
 
 function hideSearchResults() {
     addClass(refs.search, "hidden");
     removeClass(refs.main, "hidden");
+    if (refs.toc) {
+        removeClass(refs.toc, "hidden");
+    }
 }
 
 function renderResults(query, results) {
diff --git a/gidocgen/templates/basic/struct.html b/gidocgen/templates/basic/struct.html
index 0e42462..0b0f27a 100644
--- a/gidocgen/templates/basic/struct.html
+++ b/gidocgen/templates/basic/struct.html
@@ -48,7 +48,7 @@ SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later
 {% endmacro %}
 
 {% block navbar %}
-<div class="toc">
+<div id="toc" class="toc">
   <nav aria-labelledby="toc-title">
     <p id="toc-title">Content</p>
     <ul class="toc-list">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]