GrassClipper/resources/js/authAlert.js

45 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-04-27 05:15:06 +00:00
let alertTimeout, alertCooldown = 3000
2022-04-27 05:24:45 +00:00
async function displayLoginAlert(message, type, cooldown = null) {
2022-04-27 21:02:43 +00:00
displayAlert(message, type, cooldown, 'login')
2022-04-27 05:15:06 +00:00
}
2022-04-27 05:24:45 +00:00
async function displayRegisterAlert(message, type, cooldown = null) {
2022-04-27 21:02:43 +00:00
displayAlert(message, type, cooldown, 'register')
}
function displayAlert(message, type, cooldown, name) {
const elm = document.getElementById(`${name}Alert`);
const text = document.getElementById(`${name}AlertText`);
2022-04-27 05:15:06 +00:00
elm.style.removeProperty('display');
// Remove classification classes
elm.classList.remove('error');
elm.classList.remove('success');
elm.classList.remove('warn');
2022-04-27 05:15:06 +00:00
switch(type) {
case 'error':
elm.classList.add('error');
break;
2022-04-27 05:24:45 +00:00
case 'success':
elm.classList.add('success');
break;
2022-04-27 05:15:06 +00:00
case 'warn':
default:
elm.classList.add('warn');
break;
}
text.innerText = message;
2022-04-27 21:02:43 +00:00
clearTimeout(alertTimeout)
2022-04-27 05:24:45 +00:00
// Disappear after cooldown
2022-04-27 05:15:06 +00:00
alertTimeout = setTimeout(() => {
elm.style.display = 'none';
2022-04-27 05:24:45 +00:00
}, cooldown || alertCooldown)
2022-04-27 05:15:06 +00:00
}