-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlobalFunctions.js
78 lines (74 loc) · 2.82 KB
/
GlobalFunctions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//Function used to make a rest call to verify which pins are expired. The expired pins are eliminated
export default async function checkUserPins(url){
console.log("Checking pins...");
var my_body = {
"playerId" : "user",
"type" : "remove",
"imageName" : "image"
}
try{
const my_url = url + "/manageImages/controlExpireDate"
const requestSpatialite = {
method:"post",
headers:{"Content-Type":"application/json"},
body: JSON.stringify(my_body),
};
const fetchdata = await fetch(my_url, requestSpatialite)
.then(response => response.json())
.then((new_response_data)=>{
return new_response_data;
}).catch((err)=>console.log(err))
return fetchdata
}catch(e){
//alert("Error......");
console.log(e)
}
}
//Check the theme saved in the localStorage and assign it to the webApp
export function getTheme(){
var theme = localStorage.getItem("theme");
var r = document.querySelector(':root');
switch(theme){
case "default": r.style.setProperty('--white','#222222');
r.style.setProperty('--black','white');
r.style.setProperty('--primaryColor', 'black'); //#ECC478
r.style.setProperty('--secondaryColor', '#ECC478');
r.style.setProperty('--inv','invert(1)');
break;
case "blackish":r.style.setProperty('--white','white');
r.style.setProperty('--black','black');
r.style.setProperty('--primaryColor', '#ECC478');
r.style.setProperty('--secondaryColor', '#6667AB');
r.style.setProperty('--inv','invert(0)');
break;
default: break;
}
}
//Check which language has been selected previously and apply it to the webApp
export function getLanguage(){
var language = localStorage.getItem("currentLanguage");
if(language == null || language==undefined || language == ""){
language = "English"
}
return language
}
//Apply the selected language
export function setLanguage(newLanguage){
localStorage.setItem("currentLanguage", newLanguage);
}
export function animateValue(obj, start, end, duration, isProgress) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
if(isProgress){
obj.value = Math.floor(progress * (end - start) + start);
}else{
obj.innerHTML = Math.floor(progress * (end - start) + start);
}
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}