Alert script

This commit is contained in:
Emily 2019-03-02 23:38:59 +01:00
parent 87b6b53e18
commit b23e6e0d9c
2 changed files with 21 additions and 0 deletions

20
static/js/alerts.js Normal file
View File

@ -0,0 +1,20 @@
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>`;
}

View File

@ -17,5 +17,6 @@
<script src="{{ url_for('static', filename='const/js/jquery-3.3.1.slim.min.js') }}"></script>
<script src="{{ url_for('static', filename='const/js/popper.min.js') }}"></script>
<script src="{{ url_for('static', filename='const/js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/alerts.js') }}"></script>
</body>
</html>