mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Range selections are now saved in cookies
This commit is contained in:
@@ -1,27 +1,57 @@
|
||||
apikeycorrect = false;
|
||||
|
||||
function insertAPIKeyFromCookie() {
|
||||
cookies = decodeURIComponent(document.cookie).split(';');
|
||||
for(var i = 0; i <cookies.length; i++) {
|
||||
cookies[i] = cookies[i].trim()
|
||||
if (cookies[i].startsWith("apikey=")) {
|
||||
document.getElementById("apikey").value = cookies[i].replace("apikey=","")
|
||||
checkAPIkey()
|
||||
}
|
||||
var cookies = {};
|
||||
|
||||
function getCookies() {
|
||||
cookiestrings = decodeURIComponent(document.cookie).split(';');
|
||||
for(var i = 0; i <cookiestrings.length; i++) {
|
||||
cookiestrings[i] = cookiestrings[i].trim();
|
||||
[key,value] = cookiestrings[i].split("=");
|
||||
cookies[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// always on document load, but call specifically when needed early
|
||||
document.addEventListener("load",getCookies);
|
||||
|
||||
function setCookie(key,val) {
|
||||
cookies[key] = val;
|
||||
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(val);
|
||||
}
|
||||
function saveCookies() {
|
||||
for (var c in cookies) {
|
||||
document.cookie = encodeURIComponent(c) + "=" + encodeURIComponent(cookies[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// RANGE SELECTORS
|
||||
|
||||
// in rangeselect.js
|
||||
|
||||
|
||||
/// API KEY
|
||||
|
||||
|
||||
|
||||
function insertAPIKeyFromCookie() {
|
||||
getCookies();
|
||||
key = cookies["apikey"];
|
||||
document.getElementById("apikey").value = key;
|
||||
checkAPIkey()
|
||||
}
|
||||
|
||||
function saveAPIkey() {
|
||||
key = document.getElementById("apikey").value
|
||||
document.cookie = "apikey=" + encodeURIComponent(key)
|
||||
key = APIkey()
|
||||
setCookie("apikey",key)
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkAPIkey() {
|
||||
saveAPIkey()
|
||||
url = "/api/test?key=" + document.getElementById("apikey").value
|
||||
|
||||
url = "/api/test?key=" + APIkey()
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && (this.status == 204 || this.status == 205)) {
|
||||
@@ -41,6 +71,9 @@ function checkAPIkey() {
|
||||
document.getElementById("apikey").style.backgroundColor = "red"
|
||||
apikeycorrect = false
|
||||
}
|
||||
if (apikeycorrect) {
|
||||
saveAPIkey();
|
||||
}
|
||||
}
|
||||
|
||||
function APIkey() {
|
||||
|
||||
@@ -25,4 +25,21 @@ function showRange(identifier,unit) {
|
||||
for (var i=0;i<reactivate.length;i++) {
|
||||
reactivate[i].setAttribute("style","opacity:0.5;")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function showRangeManual(identifier,unit) {
|
||||
showRange(identifier,unit);
|
||||
setCookie("rangeselect_" + identifier,unit);
|
||||
}
|
||||
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded',function() {
|
||||
getCookies();
|
||||
for (c in cookies) {
|
||||
if (c.startsWith("rangeselect_")) {
|
||||
showRange(c.slice(12),cookies[c]);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user