save scroll state

This commit is contained in:
ville rantanen
2017-07-01 13:55:24 +03:00
parent f0cd627c29
commit 1e8f310468

View File

@@ -72,6 +72,7 @@ function init() {
document.getElementById("filter").focus();
hitList=search_hits(document.getElementById("filter").value);
print_results(hitList);
scroll_load();
}
function narrow_window() {
return window.innerWidth < config.narrow;
@@ -280,7 +281,22 @@ function toggle_blank() {
}
arrow.innerHTML=arrowChar;
}
function scroll_save() {
document.cookie = "position=" + window.scrollY + ";";
}
function scroll_load() {
var nameEQ = "position=";
var ca = document.cookie.split(';');
position=0;
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) { position=parseInt(c.substring(nameEQ.length,c.length)); break; }
}
window.scrollTo(0,position);
}
document.onkeyup=move_cursor;
document.onscroll=scroll_save;
var linkReg=/([^\[]*)\[([^\]]+)\]\(([^\)]+)\)(.*)/;
var linkPlain=/(.*)(http[^\s]+)(.*)/;
var linkList=[];