function for saving cookies

This commit is contained in:
ville rantanen
2017-07-17 12:49:48 +03:00
parent 8edb710ec9
commit 534d860f9f

View File

@@ -128,7 +128,7 @@ function make_menu() {
function filter(ev) {
var needle=document.getElementById('filter').value;
document.cookie="filter="+needle;
set_cookie("filter", needle);
hitList=search_hits(needle);
var c=hitList.length;
var lastHit=hitList[c-1];
@@ -217,6 +217,7 @@ function print_results(hitList) {
doc.innerHTML="";
var tbl=document.createElement("table");
var tbody=document.createElement("tbody");
var tr=document.createElement("tr");
var print_cat=0;
for (cat=0; cat<cats.length; cat++) {
if (cats[cat].count>0) {
@@ -309,7 +310,7 @@ function toggle_blank() {
arrow.innerHTML=arrowChar;
}
function scroll_save() {
document.cookie = "position=" + window.scrollY + "; path=" + window.location.pathname;
set_cookie("position", window.scrollY);
}
function scroll_load() {
var position=parseInt(get_cookie("position"));
@@ -322,14 +323,17 @@ function filter_load() {
}
function get_cookie(name) {
var nameEQ = name+"=";
var ca = document.cookie.split(';');
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length,c.length); }
}
return null
}
function set_cookie(name,value) {
document.cookie = name + "=" + value.toString() + "; path=" + window.location.pathname + ";";
}
document.onkeyup=keyboard_entry;
document.onkeydown=keyboard_control;
document.onscroll=scroll_save;