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_items;
var lunr_index; var lunr_index;
var restoreSessionSettings;
function build_lunr(items) { function build_lunr(items) {
lunr_items = items; lunr_items = items;
lunr_index = lunr(function(){ lunr_index = lunr(function(){
...@@ -11,6 +12,8 @@ function build_lunr(items) { ...@@ -11,6 +12,8 @@ function build_lunr(items) {
this.add(items[i]); this.add(items[i]);
} }
}); });
restoreSessionSettings();
} }
function make_relative_url(url) { function make_relative_url(url) {
...@@ -147,7 +150,7 @@ function highlightCallback(span, cls, str) { ...@@ -147,7 +150,7 @@ function highlightCallback(span, cls, str) {
}; };
} }
let restoreSessionSettings = function() { restoreSessionSettings = function() {
if (typeof sessionStorage.searchValue != 'undefined') { if (typeof sessionStorage.searchValue != 'undefined') {
searchfield.value = sessionStorage.searchValue; searchfield.value = sessionStorage.searchValue;
searchfield.oninput(); searchfield.oninput();
...@@ -160,13 +163,12 @@ function highlightCallback(span, cls, str) { ...@@ -160,13 +163,12 @@ function highlightCallback(span, cls, str) {
if (typeof sessionStorage['scrollLeft-' + savedScrollDivs[i]] != 'undefined') if (typeof sessionStorage['scrollLeft-' + savedScrollDivs[i]] != 'undefined')
elem.scrollLeft = sessionStorage['scrollLeft-' + savedScrollDivs[i]]; elem.scrollLeft = sessionStorage['scrollLeft-' + savedScrollDivs[i]];
} }
};
/* Lunr index; afterwards restore session */ if (typeof sessionStorage['scrollTop-toc'] == 'undefined') {
fetch(make_relative_url('data/lunr-index.json')) var toc = document.getElementById('toc');
.then(function (response) { return response.json(); }) var active = toc.querySelector('.active');
.then(function (json) { if (active != null)
build_lunr(json); toc.scrollTop = active.offsetTop - 50;
restoreSessionSettings(); }
}); };
})(); })();
...@@ -29,7 +29,7 @@ import Clean.Doc.ModuleCollection.Index => qualified :: IndexItem{name} ...@@ -29,7 +29,7 @@ import Clean.Doc.ModuleCollection.Index => qualified :: IndexItem{name}
generateHTML :: !ModuleCollection -> WebSite generateHTML :: !ModuleCollection -> WebSite
generateHTML mcoll = 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)) map (\(fp,html) -> (fp,finalizeHTML fp html))
[ ("index.html", Text "") [ ("index.html", Text "")
: map moduleFile mcoll : map moduleFile mcoll
...@@ -47,6 +47,7 @@ where ...@@ -47,6 +47,7 @@ where
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/clean-doc-markup/clean-doc-markup.js")] [] , 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 "js/cleandoc.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/lunr.js/lunr.js")] [] , ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/lunr.js/lunr.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "js/lunr-index.js")] []
] ]
, BodyTag [] , BodyTag []
[ DivTag [IdAttr "container"] [ 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