Verified Commit 606012d9 authored by Camil Staps's avatar Camil Staps 🚀

Keep sidebar information in sessionStorage (#4)

parent 2c85b1f5
Pipeline #14660 failed with stage
in 54 seconds
......@@ -80,7 +80,7 @@ function highlightCallback(span, cls, str) {
/* Open collapsable of hashtag in url */
window.onhashchange = function () {
if (window.location.hash.substring(0,1) == '#') {
let id = window.location.hash.substring(1);
let id = decodeURIComponent(window.location.hash.substring(1));
let elem = document.getElementById(id);
if (elem.classList.contains('collapsable')) {
elem.collapsableOpen();
......@@ -103,7 +103,7 @@ function highlightCallback(span, cls, str) {
});
}
/* search field */
/* Search field */
let searchfield = document.getElementById('search-field');
let searchresults = document.getElementById('search-results').querySelector('ul');
let searchcloogle = document.getElementById('search-cloogle');
......@@ -111,6 +111,8 @@ function highlightCallback(span, cls, str) {
searchresults.innerHTML = '';
searchcloogle.innerHTML = '';
sessionStorage.searchValue = this.value;
if (this.value == '')
return;
......@@ -135,4 +137,36 @@ function highlightCallback(span, cls, str) {
searchresults.appendChild(li);
}
};
let savedScrollDivs = ['toc', 'search'];
for (let i in savedScrollDivs) {
let elem = document.getElementById(savedScrollDivs[i]);
elem.onscroll = function() {
sessionStorage['scrollTop-' + savedScrollDivs[i]] = this.scrollTop;
sessionStorage['scrollLeft-' + savedScrollDivs[i]] = this.scrollLeft;
};
}
let restoreSessionSettings = function() {
if (typeof sessionStorage.searchValue != 'undefined') {
searchfield.value = sessionStorage.searchValue;
searchfield.oninput();
}
for (let i in savedScrollDivs) {
let elem = document.getElementById(savedScrollDivs[i]);
if (typeof sessionStorage['scrollTop-' + savedScrollDivs[i]] != 'undefined')
elem.scrollTop = sessionStorage['scrollTop-' + savedScrollDivs[i]];
if (typeof sessionStorage['scrollLeft-' + savedScrollDivs[i]] != 'undefined')
elem.scrollLeft = sessionStorage['scrollLeft-' + savedScrollDivs[i]];
}
};
/* Lunr index; afterwards restore session */
fetch(make_relative_url('data/lunr-index.json'))
.then(function (response) { return response.json(); })
.then(function (json) {
build_lunr(json);
restoreSessionSettings();
});
})();
......@@ -29,7 +29,7 @@ import Clean.Doc.ModuleCollection.Index => qualified :: IndexItem{name}
generateHTML :: !ModuleCollection -> WebSite
generateHTML mcoll =
[("js/lunr-index.js", "build_lunr(" +++ (toString $ toJSON $ indexModuleCollection mcoll) +++ ");")] ++
[("data/lunr-index.json", toString $ toJSON $ indexModuleCollection mcoll)] ++
map (\(fp,html) -> (fp,finalizeHTML fp html))
[ ("index.html", Text "")
: map moduleFile mcoll
......@@ -47,7 +47,6 @@ where
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/clean-doc-markup/clean-doc-markup.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "js/cleandoc.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/lunr.js/lunr.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "js/lunr-index.js")] []
]
, BodyTag []
[ DivTag [IdAttr "container"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment