Flask-Project-Template/src/core/static/js/ui-logic.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-12-30 07:14:31 +00:00
// Message handler
const displayMessage = (message, type, timeout, msgWindow = "page-alert-zone") => {
let alertField = document.getElementById(msgWindow);
let divElm = document.createElement("DIV");
let btnElm = document.createElement("BUTTON");
let spnElm = document.createElement("SPAN");
let textElm = document.createTextNode(message);
divElm.setAttribute("class", "alert alert-" + type);
divElm.setAttribute("role", "alert");
divElm.appendChild(textElm);
btnElm.type = "button";
textElm = document.createTextNode("X");
btnElm.setAttribute("class", "close");
btnElm.setAttribute("data-dismiss", "alert");
btnElm.setAttribute("aria-label", "close");
spnElm.setAttribute("aria-hidden", "true");
spnElm.appendChild(textElm);
btnElm.appendChild(spnElm);
divElm.appendChild(btnElm);
alertField.appendChild(divElm);
if (timeout > 0) {
setTimeout(function () {
clearChildNodes(alertField);
}, timeout * 1000);
}
}
const clearChildNodes = (parent) => {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}