aboutsummaryrefslogtreecommitdiff
path: root/templates/partials/doc/toc_script.html
diff options
context:
space:
mode:
authorsptaule <lecas83@gmail.com>2022-01-27 18:10:37 +0100
committersptaule <lecas83@gmail.com>2022-01-27 18:10:37 +0100
commit1da8b90340235753b935a880d797cb796700d151 (patch)
treee6c98c0999eb3b58e3ebfd72b88c4379a8fa51d0 /templates/partials/doc/toc_script.html
parenta8d6c4635cf4e49320ebee8ee6f348769b65ffa8 (diff)
downloadgaragehq.deuxfleurs.fr-1da8b90340235753b935a880d797cb796700d151.tar.gz
garagehq.deuxfleurs.fr-1da8b90340235753b935a880d797cb796700d151.zip
Doc refactor, doc and index QoL, fix search: working on every page
Diffstat (limited to 'templates/partials/doc/toc_script.html')
-rw-r--r--templates/partials/doc/toc_script.html23
1 files changed, 21 insertions, 2 deletions
diff --git a/templates/partials/doc/toc_script.html b/templates/partials/doc/toc_script.html
index a858c94..df115b0 100644
--- a/templates/partials/doc/toc_script.html
+++ b/templates/partials/doc/toc_script.html
@@ -1,9 +1,29 @@
-<script type="text/javascript">
+<script>
const menuBarHeight = document.querySelector("nav.navbar").clientHeight;
+const mainTocMenuWidth = document.getElementById('main-toc-menu').clientWidth;
const tocItems = document.querySelectorAll(".toc");
const navSections = new Array(tocItems.length);
+ // Global ToC
+/*
+ Fixed ToC when user scrolls.
+*/
+
+window.addEventListener('scroll', function() {
+ if (window.scrollY >= menuBarHeight) {
+ document.getElementById('main-toc-menu').classList.add('fixed', 'top-0', 'left-0');
+ document.getElementById('main-toc-menu').style.width = mainTocMenuWidth + 'px';
+ } else {
+ document.getElementById('main-toc-menu').classList.remove('fixed', 'top-0', 'left-0');
+ }
+});
+
+// Page content
+/*
+ Focus effect on current section anchor when user scrolls.
+*/
+
tocItems.forEach((el, i) => {
let id = el.getAttribute("id").substring(5);
navSections[i] = document.getElementById(id);
@@ -42,7 +62,6 @@ window.addEventListener('scroll', () => {
}
}, false);
-// If JS enabled, deploy only the current doc menu
document.addEventListener("DOMContentLoaded", function() {
var menusTriggers = document.getElementsByClassName("deploySubMenu");
var activeDocPage = document.getElementsByClassName("activePage")[0];