mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Updated javascript
This commit is contained in:
parent
9b7bc5e38e
commit
f540862881
@ -1,53 +1,12 @@
|
|||||||
apikeycorrect = false;
|
apikeycorrect = false;
|
||||||
|
|
||||||
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,session=true) {
|
|
||||||
cookies[key] = val;
|
|
||||||
if (!session) {
|
|
||||||
var d = new Date();
|
|
||||||
d.setTime(d.getTime() + (500*24*60*60*1000));
|
|
||||||
expirestr = "expires=" + d.toUTCString();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
expirestr = ""
|
|
||||||
}
|
|
||||||
document.cookie = encodeURIComponent(key) + "=" + encodeURIComponent(val) + ";" + expirestr;
|
|
||||||
}
|
|
||||||
function saveCookies() {
|
|
||||||
for (var c in cookies) {
|
|
||||||
document.cookie = encodeURIComponent(c) + "=" + encodeURIComponent(cookies[c]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// RANGE SELECTORS
|
|
||||||
|
|
||||||
// in rangeselect.js
|
|
||||||
|
|
||||||
|
|
||||||
/// API KEY
|
/// API KEY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function insertAPIKeyFromCookie() {
|
function insertAPIKeyFromCookie() {
|
||||||
element = document.getElementById("apikey")
|
element = document.getElementById("apikey")
|
||||||
if (element != null && element != undefined) {
|
if (element != null && element != undefined) {
|
||||||
getCookies();
|
var key = neo.getCookie("apikey");
|
||||||
key = cookies["apikey"];
|
|
||||||
if (key != null && key != undefined) {
|
if (key != null && key != undefined) {
|
||||||
element.value = key;
|
element.value = key;
|
||||||
checkAPIkey();
|
checkAPIkey();
|
||||||
@ -62,7 +21,7 @@ window.addEventListener("load",insertAPIKeyFromCookie);
|
|||||||
|
|
||||||
function saveAPIkey() {
|
function saveAPIkey() {
|
||||||
key = APIkey();
|
key = APIkey();
|
||||||
setCookie("apikey",key,false);
|
neo.setCookie("apikey",key,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,16 +38,16 @@ function showRange(identifier,unit) {
|
|||||||
|
|
||||||
function showRangeManual(identifier,unit) {
|
function showRangeManual(identifier,unit) {
|
||||||
showRange(identifier,unit);
|
showRange(identifier,unit);
|
||||||
setCookie("rangeselect_" + identifier,unit);
|
neo.setCookie("rangeselect_" + identifier,unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded',function() {
|
document.addEventListener('DOMContentLoaded',function() {
|
||||||
getCookies();
|
for (let type of ["topartists","toptracks","pulse"]) {
|
||||||
for (c in cookies) {
|
var val = neo.getCookie("rangeselect_" + type);
|
||||||
if (c.startsWith("rangeselect_")) {
|
if (val != undefined) {
|
||||||
showRange(c.slice(12),cookies[c]);
|
showRange(type,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user