Add a css loader on every async API call

TODO: maybe be able to select not to show it by arg?
This commit is contained in:
Bofh 2021-11-27 22:42:27 +01:00
parent ba6569ee0b
commit 5f219304a2
3 changed files with 55 additions and 1 deletions

View File

@ -94,6 +94,53 @@ main > div.content {
text-align: center;
}
/* Loader
*/
#loader {
display: flex;
position: fixed;
z-index: 100;
background: #ffffffa8;
width: 100vw;
height: 100vh;
}
.lds-ring {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
margin: auto;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 64px;
height: 64px;
margin: 8px;
border: 4px solid #a2a2a2;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #a2a2a2 transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
/* Shared
*/
.button {

View File

@ -4,7 +4,12 @@ const http = {
payload = payload || null;
callbk = callbk || null;
const oReq = new XMLHttpRequest();
oReq.addEventListener("load", function() { if (callbk) callbk(this.responseText) });
document.getElementById('loader').style = '';
oReq.addEventListener("load", function() {
document.getElementById('loader').style = 'display: none';
if (callbk)
callbk(this.responseText);
});
oReq.open(method, path);
oReq.setRequestHeader('Content-Type', 'application/json');
oReq.send(payload);

View File

@ -1,3 +1,5 @@
<div id="loader" style="display: none"><div class="lds-ring">
<div></div><div></div><div></div><div></div></div></div>
<header>
<div class="icon">
<a href="/">