32 lines
878 B
Plaintext
32 lines
878 B
Plaintext
(function() {
|
|
'use strict';
|
|
|
|
window.utils = window.utils || {};
|
|
|
|
window.utils.alert = function(alertEl) {
|
|
var closeEl = document.createElement('DIV');
|
|
closeEl.classList.add('alert__close');
|
|
closeEl.innerText = #{String (messageRender MsgCloseAlert)};
|
|
closeEl.addEventListener('click', function(event) {
|
|
alertEl.classList.add('alert--invisible');
|
|
});
|
|
alertEl.insertBefore(closeEl, alertEl.children[0]);
|
|
|
|
// auto-hide info and success-alerts after 3 seconds
|
|
if (!alertEl.matches('.alert-danger, .alert-warning')) {
|
|
window.setTimeout(function() {
|
|
alertEl.classList.add('alert--invisible');
|
|
}, 3000);
|
|
}
|
|
}
|
|
|
|
})();
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
// setup alerts
|
|
Array.from(document.querySelectorAll('.alert')).forEach(function(alertEl) {
|
|
window.utils.alert(alertEl);
|
|
});
|
|
});
|