diff options
author | sptaule <lecas83@gmail.com> | 2022-01-27 18:10:37 +0100 |
---|---|---|
committer | sptaule <lecas83@gmail.com> | 2022-01-27 18:10:37 +0100 |
commit | 1da8b90340235753b935a880d797cb796700d151 (patch) | |
tree | e6c98c0999eb3b58e3ebfd72b88c4379a8fa51d0 /templates/partials/doc/toc_script.html | |
parent | a8d6c4635cf4e49320ebee8ee6f348769b65ffa8 (diff) | |
download | garagehq.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.html | 23 |
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]; |