save filter needle too

This commit is contained in:
ville rantanen
2017-07-01 20:31:18 +03:00
parent 1e8f310468
commit 12689db311

View File

@@ -70,6 +70,7 @@ function init() {
}
document.getElementById("open_blank_arrow").innerHTML=config.arrows[0];
document.getElementById("filter").focus();
filter_load();
hitList=search_hits(document.getElementById("filter").value);
print_results(hitList);
scroll_load();
@@ -127,6 +128,7 @@ function make_menu() {
function filter(ev) {
var needle=document.getElementById('filter').value;
document.cookie="filter="+needle;
hitList=search_hits(needle);
var c=hitList.length;
var lastHit=hitList[c-1];
@@ -285,15 +287,23 @@ function scroll_save() {
document.cookie = "position=" + window.scrollY + ";";
}
function scroll_load() {
var nameEQ = "position=";
var position=parseInt(get_cookie("position"));
window.scrollTo(0,position);
}
function filter_load() {
var needle=get_cookie("filter");
if (needle===null) { return }
document.getElementById("filter").value=needle;
}
function get_cookie(name) {
var nameEQ = name+"=";
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; }
if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); }
}
window.scrollTo(0,position);
return null
}
document.onkeyup=move_cursor;
document.onscroll=scroll_save;