GrassClipper/resources/js/authAlert.js

49 lines
1.1 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-05-04 04:06:01 +00:00
displayAuthAlert(message, type, cooldown, 'login')
2022-05-08 03:49:45 +00:00
debug.log('Login alert: ' + message)
2022-04-27 05:15:06 +00:00
}
2022-04-27 05:24:45 +00:00
async function displayRegisterAlert(message, type, cooldown = null) {
2022-05-04 04:06:01 +00:00
displayAuthAlert(message, type, cooldown, 'register')
2022-05-08 03:49:45 +00:00
debug.log('Register alert: ' + message)
2022-04-27 21:02:43 +00:00
}
2022-05-04 04:06:01 +00:00
function displayAuthAlert(message, type, cooldown, name) {
2022-05-03 05:48:03 +00:00
const elm = document.getElementById(`${name}Alert`)
const text = document.getElementById(`${name}AlertText`)
2022-04-27 05:15:06 +00:00
2022-05-03 05:48:03 +00:00
elm.style.removeProperty('display')
2022-05-03 05:48:03 +00:00
// Remove classification classes
elm.classList.remove('error')
elm.classList.remove('success')
elm.classList.remove('warn')
switch(type) {
case 'error':
elm.classList.add('error')
break
case 'success':
elm.classList.add('success')
break
case 'warn':
default:
elm.classList.add('warn')
break
}
text.innerText = message
clearTimeout(alertTimeout)
// Disappear after cooldown
alertTimeout = setTimeout(() => {
elm.style.display = 'none'
2022-05-08 03:49:45 +00:00
debug.log('Hiding auth alert')
2022-05-03 05:48:03 +00:00
}, cooldown || alertCooldown)
2022-04-27 05:15:06 +00:00
}