From 71c3cc7837dc80e5e3227cc00463fc73c97e7856 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 27 Apr 2022 14:02:43 -0700 Subject: [PATCH] clean alert functions --- resources/js/authAlert.js | 42 +++++++++------------------------------ 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/resources/js/authAlert.js b/resources/js/authAlert.js index fa2bed0..c6b806e 100644 --- a/resources/js/authAlert.js +++ b/resources/js/authAlert.js @@ -1,42 +1,16 @@ let alertTimeout, alertCooldown = 3000 async function displayLoginAlert(message, type, cooldown = null) { - const elm = document.getElementById('loginAlert'); - const text = document.getElementById('loginAlertText'); - - elm.style.removeProperty('display'); - - // 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; - - // Disappear after cooldown - alertTimeout = setTimeout(() => { - elm.style.display = 'none'; - }, cooldown || alertCooldown) + displayAlert(message, type, cooldown, 'login') } async function displayRegisterAlert(message, type, cooldown = null) { - const elm = document.getElementById('registerAlert'); - const text = document.getElementById('registerAlertText'); + displayAlert(message, type, cooldown, 'register') +} + +function displayAlert(message, type, cooldown, name) { + const elm = document.getElementById(`${name}Alert`); + const text = document.getElementById(`${name}AlertText`); elm.style.removeProperty('display'); @@ -62,6 +36,8 @@ async function displayRegisterAlert(message, type, cooldown = null) { text.innerText = message; + clearTimeout(alertTimeout) + // Disappear after cooldown alertTimeout = setTimeout(() => { elm.style.display = 'none';