aboutsummaryrefslogtreecommitdiff
path: root/templates/partials/doc/toc_script.html
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-31 11:54:22 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-31 11:54:22 +0100
commit937245b202c200e1405209c59893d459b2194d2f (patch)
tree38dc667fb81be27b3b21e5cfccbf36d5fbc8fefd /templates/partials/doc/toc_script.html
parent4dde9b0855ad8edf5eef72036ee788aeeb5cd775 (diff)
parente5beba07d6b9e102cc28c7474b9db0ae11ec3c79 (diff)
downloadgaragehq.deuxfleurs.fr-937245b202c200e1405209c59893d459b2194d2f.tar.gz
garagehq.deuxfleurs.fr-937245b202c200e1405209c59893d459b2194d2f.zip
Merge branch 'master' of git.deuxfleurs.fr:sptl/garage_website
Diffstat (limited to 'templates/partials/doc/toc_script.html')
-rw-r--r--templates/partials/doc/toc_script.html25
1 files changed, 23 insertions, 2 deletions
diff --git a/templates/partials/doc/toc_script.html b/templates/partials/doc/toc_script.html
index a858c94..1453a69 100644
--- a/templates/partials/doc/toc_script.html
+++ b/templates/partials/doc/toc_script.html
@@ -1,9 +1,31 @@
-<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.screen.width >= 1280) {
+ 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 +64,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];