Verified Commit 2aac5f28 authored by Camil Staps's avatar Camil Staps 🚀

Remove fetch API (in Chrome this is not allowed on file:// urls)

parent 606012d9
var lunr_items;
var lunr_index;
var restoreSessionSettings;
function build_lunr(items) {
lunr_items = items;
lunr_index = lunr(function(){
......@@ -11,6 +12,8 @@ function build_lunr(items) {
this.add(items[i]);
}
});
restoreSessionSettings();
}
function make_relative_url(url) {
......@@ -147,7 +150,7 @@ function highlightCallback(span, cls, str) {
};
}
let restoreSessionSettings = function() {
restoreSessionSettings = function() {
if (typeof sessionStorage.searchValue != 'undefined') {
searchfield.value = sessionStorage.searchValue;
searchfield.oninput();
......@@ -160,13 +163,12 @@ function highlightCallback(span, cls, str) {
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();
});
if (typeof sessionStorage['scrollTop-toc'] == 'undefined') {
var toc = document.getElementById('toc');
var active = toc.querySelector('.active');
if (active != null)
toc.scrollTop = active.offsetTop - 50;
}
};
})();
......@@ -29,7 +29,7 @@ import Clean.Doc.ModuleCollection.Index => qualified :: IndexItem{name}
generateHTML :: !ModuleCollection -> WebSite
generateHTML mcoll =
[("data/lunr-index.json", toString $ toJSON $ indexModuleCollection mcoll)] ++
[("js/lunr-index.js", "build_lunr(" +++ (toString $ toJSON $ indexModuleCollection mcoll) +++ ");")] ++
map (\(fp,html) -> (fp,finalizeHTML fp html))
[ ("index.html", Text "")
: map moduleFile mcoll
......@@ -47,6 +47,7 @@ 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