diff --git a/webclient/src/js/components/toasts.js b/webclient/src/js/components/toasts.js index 777dde2..f5fea52 100644 --- a/webclient/src/js/components/toasts.js +++ b/webclient/src/js/components/toasts.js @@ -10,7 +10,11 @@ `; } -function init(toast) { +function init(toast, props) { + if(props?.alone) { + document.querySelectorAll(".toast").forEach(i => i.close()); + } + toast.close = function() { this.classList.add("a-hide"); setTimeout(() => { @@ -32,53 +36,82 @@ Screens.onSwitch((scr, alias) => { setTimeout(() => { - toast.close(); + toast?.close(); }, 10000); }); + toast.addEventListener("mouseover", e => toast.ishovered = true); + toast.addEventListener("mouseout", e => toast.ishovered = false); + + if(props?.lifetime) { + console.log(props); + const lifetimeInterval = setInterval(() => { + if(!toast.ishovered) { + toast.close(); + clearInterval(lifetimeInterval); + } + }, props?.lifetime); + } + return toast; } -function create(type, icon, title, text) { +function create(type, icon, title, text, props) { const div = document.createElement("div"); div.innerHTML = template(type, icon, title, text); - return init(div.childNodes[1]); + return init(div.childNodes[1], props); } -function createSuccess(title, text) { +function createSuccess(title, text, props) { + if(typeof props == "undefined") { + props = {}; + } + + if(typeof props.lifetime == "undefined") { + props.lifetime = 4000; + } + + if(typeof props.alone == "undefined") { + props.alone = true; + } + return create( "success", ``, title, - text + text, + props ); } -function createInfo(title, text) { +function createInfo(title, text, props) { return create( "info", ``, title, - text + text, + props ); } -function createWarning(title, text) { +function createWarning(title, text, props) { return create( "warning", ``, title, - text + text, + props ); } -function createError(title, text) { +function createError(title, text, props) { return create( "danger", ``, title, - text + text, + props ); }