husstanden/static/js/alerts.js
2019-03-02 23:38:59 +01:00

20 lines
780 B
JavaScript

function _findAlertDom(caller) {
let selectedDOM = caller;
do {
if (selectedDOM.classList.contains("alert-section")){
return selectedDOM;
}
selectedDOM = selectedDOM.parentElement;
} while (selectedDOM != null);
throw Error("Missing alert-section class for self/parent(s)");
}
function alertAbove(caller, t, s) {
let dom = _findAlertDom(caller);
dom.outerHTML = `<div class="alert alert-${t} fade in show" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>${s}</div>` + dom.outerHTML;
}
function alertUnder(caller, t, s) {
let dom = _findAlertDom(caller);
dom.outerHTML += `<div class="alert alert-${t} fade in show" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>${s}</div>`;
}