aboutsummaryrefslogtreecommitdiff
path: root/templates/partials/doc/toc_script.html
diff options
context:
space:
mode:
authorsptaule <lecas83@gmail.com>2022-01-26 14:44:47 +0100
committersptaule <lecas83@gmail.com>2022-01-26 14:44:47 +0100
commite0977c983abff89ac3a9e37f616399dc0b6c61c7 (patch)
tree51aec127e129ad291063d745904bbe43d906a44d /templates/partials/doc/toc_script.html
parentee4d6a01e16ac53fa3e48340a47455281d5f6bc0 (diff)
downloadgaragehq.deuxfleurs.fr-e0977c983abff89ac3a9e37f616399dc0b6c61c7.tar.gz
garagehq.deuxfleurs.fr-e0977c983abff89ac3a9e37f616399dc0b6c61c7.zip
Fix doc links & added noJS support for the doc
Diffstat (limited to 'templates/partials/doc/toc_script.html')
-rw-r--r--templates/partials/doc/toc_script.html55
1 files changed, 55 insertions, 0 deletions
diff --git a/templates/partials/doc/toc_script.html b/templates/partials/doc/toc_script.html
new file mode 100644
index 0000000..a858c94
--- /dev/null
+++ b/templates/partials/doc/toc_script.html
@@ -0,0 +1,55 @@
+<script type="text/javascript">
+
+const menuBarHeight = document.querySelector("nav.navbar").clientHeight;
+const tocItems = document.querySelectorAll(".toc");
+const navSections = new Array(tocItems.length);
+
+tocItems.forEach((el, i) => {
+ let id = el.getAttribute("id").substring(5);
+ navSections[i] = document.getElementById(id);
+})
+
+function isVisible(tocIndex) {
+ const current = navSections[tocIndex];
+ const next = tocIndex < tocItems.length - 1 ? navSections[tocIndex + 1]
+ : document.querySelectorAll("section.section").item(1);
+
+ const c = current.getBoundingClientRect();
+ const n = next.getBoundingClientRect();
+ const h = (window.innerHeight || document.documentElement.clientHeight);
+
+ return (c.top <= h) && (n.top - menuBarHeight >= 0);
+}
+
+function activateIfVisible() {
+ for (b = true, i = 0; i < tocItems.length; i++) {
+ if (b && isVisible(i)) {
+ tocItems[i].classList.add('is-active');
+ b = false;
+ } else
+ tocItems[i].classList.remove('is-active');
+ }
+}
+
+var isTicking = null;
+window.addEventListener('scroll', () => {
+ if (!isTicking) {
+ window.requestAnimationFrame(() => {
+ activateIfVisible();
+ isTicking = false;
+ });
+ isTicking = true;
+ }
+}, 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];
+ for (var i = 0; i < menusTriggers.length; i++) {
+ menusTriggers[i].checked = true;
+ }
+ activeDocPage.parentElement.parentElement.previousElementSibling.previousElementSibling.checked = false;
+});
+
+</script> \ No newline at end of file