feat: add scroll-lock as separate file

This commit is contained in:
Henk Verlinde 2022-03-30 15:05:00 +02:00
parent 20eb2a22fd
commit 40dc1b7489
3 changed files with 17 additions and 14 deletions

View File

@ -1,14 +0,0 @@
// 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);
});
}

14
assets/js/scroll-lock.js Normal file
View File

@ -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);
});
}

View File

@ -57,6 +57,9 @@
{{ $slice = $slice | append $katexConfig -}} {{ $slice = $slice | append $katexConfig -}}
{{ end -}} {{ end -}}
{{ $scrollLock := resources.Get "js/scroll-lock.js" | js.Build -}}
{{ $slice = $slice | append $scrollLock -}}
{{ $js := $slice | resources.Concat "main.js" -}} {{ $js := $slice | resources.Concat "main.js" -}}
{{ if eq (hugo.Environment) "development" -}} {{ if eq (hugo.Environment) "development" -}}