diff options
author | Henk Verlinde <henk@ventizo.com> | 2022-02-02 12:54:55 +0300 |
---|---|---|
committer | Henk Verlinde <henk@ventizo.com> | 2022-02-02 12:54:55 +0300 |
commit | 17eb9a690257fdf3f72a947fc504251bc1484719 (patch) | |
tree | e1d06e3613348e522fccceb5ec5c5405c2bf66d8 | |
parent | 971894755e69d2a048aec514e492451a8385cc2a (diff) |
ux: add scroll position lock for default docs sidebar
-rw-r--r-- | assets/js/app.js | 14 | ||||
-rw-r--r-- | layouts/docs/single.html | 2 |
2 files changed, 15 insertions, 1 deletions
diff --git a/assets/js/app.js b/assets/js/app.js index e69de29..069b8c2 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -0,0 +1,14 @@ +// Adds scroll position lock for default docs sidebar + +if (document.querySelector('#sidebar-default') !== null) { + let sidebar = document.getElementById('sidebar-default'); + + let pos = sessionStorage.getItem('sidebar-scroll'); + if (pos !== null) { + sidebar.scrollTop = parseInt(pos, 10); + } + + window.addEventListener('beforeunload', () => { + sessionStorage.setItem('sidebar-scroll', sidebar.scrollTop); + }); +} diff --git a/layouts/docs/single.html b/layouts/docs/single.html index 1746d0a..d1aec30 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -1,7 +1,7 @@ {{ define "main" }} <div class="row flex-xl-nowrap"> <div class="col-lg-5 col-xl-4 docs-sidebar d-none d-lg-block"> - <nav class="docs-links" aria-label="Main navigation"> + <nav {{ if eq .Site.Params.menu.section.collapsibleSidebar false }}id="sidebar-default" {{ end }}class="docs-links" aria-label="Main navigation"> {{ partial "sidebar/docs-menu.html" . }} </nav> </div> |