From 27cbe3f4fd6cef2bef51b8c2c78deeb7642565d7 Mon Sep 17 00:00:00 2001 From: anarsec Date: Fri, 7 Jul 2023 02:07:42 +0000 Subject: [PATCH] improve toc js --- content/posts/e2ee/index.md | 2 +- themes/DeepThought/static/js/site.js | 19 ++++++++++++++++++- themes/DeepThought/templates/base.html | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/content/posts/e2ee/index.md b/content/posts/e2ee/index.md index 027810b..f3380e3 100644 --- a/content/posts/e2ee/index.md +++ b/content/posts/e2ee/index.md @@ -234,7 +234,7 @@ To install Element Desktop, Whonix is not guaranteed to have Tor Stream Isolatio * Open a Terminal in the new Template: **Applications menu → Template: whonix-ws-16-element: Xfce Terminal** * Run the commands in the [Element install guide](https://element.io/download#linux) to install Element Desktop in the Template. * Template qubes require a proxy for `wget`. Before running the command, create a configuration file at `~/.wgetrc` in the Template, with the contents: -``` +```bash use_proxy = on http_proxy = 127.0.0.1:8082 https_proxy = 127.0.0.1:8082 diff --git a/themes/DeepThought/static/js/site.js b/themes/DeepThought/static/js/site.js index 0bab18a..c28903e 100644 --- a/themes/DeepThought/static/js/site.js +++ b/themes/DeepThought/static/js/site.js @@ -20,11 +20,28 @@ return (c.top <= h) && (n.top - menuBarHeight >= 0); } + function highlightTocItem(tocIndex) { + const bottomGap = 50; + tocItems[tocIndex].classList.add('is-active'); + const bodyRect = document.body.getBoundingClientRect(); + const elemRect = tocItems[tocIndex].getBoundingClientRect(); + const menuRect = document.querySelector(".menu").getBoundingClientRect(); + const menuAbsTop = menuRect.top - bodyRect.top; + const elemAbsBottom = elemRect.bottom - bodyRect.top; + const h = (window.innerHeight || document.documentElement.clientHeight); + if(elemAbsBottom > menuAbsTop + h - 48 - bottomGap){ + document.querySelector(".menu").style = "position: sticky; top: " + (menuAbsTop - elemAbsBottom + h - bottomGap).toString() + "px"; + } + else{ + document.querySelector(".menu").style = "position: sticky; top: 48px;"; + } +} + function activateIfVisible() { let b = true; for (let i = 0; i < tocItems.length; i++) { if (b && isVisible(i)) { - tocItems[i].classList.add('is-active'); + highlightTocItem(i); b = false; } else tocItems[i].classList.remove('is-active'); diff --git a/themes/DeepThought/templates/base.html b/themes/DeepThought/templates/base.html index 65702b5..e6f5d48 100644 --- a/themes/DeepThought/templates/base.html +++ b/themes/DeepThought/templates/base.html @@ -5,7 +5,7 @@ - +