Fixed formatting in toastHandler

This commit is contained in:
Leon Meier 2023-05-21 01:45:27 +02:00
parent a8b0374d5e
commit 37649ec98e

View File

@ -8,11 +8,11 @@ currentToasts = [];
* @param {Boolean} autoReload Should the page reload after the toast is hidden, default is true (for compatibility with old code) * @param {Boolean} autoReload Should the page reload after the toast is hidden, default is true (for compatibility with old code)
* @returns {String} The id of the created toast, format: toast-<number> * @returns {String} The id of the created toast, format: toast-<number>
*/ */
function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload = true){ function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload = true) {
const targetContainer = document.getElementById('toastMainController'); const targetContainer = document.getElementById('toastMainController');
const masterToast = document.getElementById('masterToast'); const masterToast = document.getElementById('masterToast');
const newToast = masterToast.cloneNode(true); const newToast = masterToast.cloneNode(true);
newToast.classList.add(colorSelector) newToast.classList.add(colorSelector);
newToast.id = `toast-${currentToasts.length}`; newToast.id = `toast-${currentToasts.length}`;
console.log(newToast.childNodes[1]); console.log(newToast.childNodes[1]);
newToast.childNodes[1].childNodes[1].innerHTML = message; newToast.childNodes[1].childNodes[1].innerHTML = message;
@ -21,7 +21,7 @@ function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload
$(newToast).toast('show'); $(newToast).toast('show');
setTimeout(() => { setTimeout(() => {
destroyToast(newToast.id); destroyToast(newToast.id);
if(autoReload){ if (autoReload) {
location.reload(); location.reload();
} }
}, autoHideTime); }, autoHideTime);
@ -32,7 +32,7 @@ function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload
* Generic function to destroy a toast * Generic function to destroy a toast
* @param {String} id The id of the toast to destroy * @param {String} id The id of the toast to destroy
*/ */
function destroyToast(id){ function destroyToast(id) {
const targetContainer = document.getElementById('toastMainController'); const targetContainer = document.getElementById('toastMainController');
const targetToast = document.getElementById(id); const targetToast = document.getElementById(id);
targetContainer.removeChild(targetToast); targetContainer.removeChild(targetToast);
@ -40,8 +40,8 @@ function destroyToast(id){
} }
// Moved here // Moved here
function normalizeToast(){ function normalizeToast() {
console.warn("Something is using the deprecated function normalizeToast(). Please use createNewToast() instead.") console.warn('Something is using the deprecated function normalizeToast(). Please use createNewToast() instead.');
$('#generalToast').removeClass('text-bg-primary'); $('#generalToast').removeClass('text-bg-primary');
$('#generalToast').removeClass('text-bg-success'); $('#generalToast').removeClass('text-bg-success');
$('#generalToast').removeClass('text-bg-danger'); $('#generalToast').removeClass('text-bg-danger');