37 lines
1.0 KiB
Plaintext
37 lines
1.0 KiB
Plaintext
(function() {
|
|
'use strict';
|
|
|
|
window.utils = window.utils || {};
|
|
|
|
window.utils.alert = function(alertEl) {
|
|
var closeEl = document.createElement('DIV');
|
|
var dataDecay = alertEl.dataset.decay;
|
|
var autoDecay = 3;
|
|
if (dataDecay) {
|
|
autoDecay = parseInt(dataDecay, 10);
|
|
}
|
|
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 (autoDecay > 0 && !alertEl.matches('.alert-danger, .alert-warning')) {
|
|
window.setTimeout(function() {
|
|
alertEl.classList.add('alert--invisible');
|
|
}, autoDecay * 1000);
|
|
}
|
|
}
|
|
|
|
})();
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
// setup alerts
|
|
Array.from(document.querySelectorAll('.alert')).forEach(function(alertEl) {
|
|
window.utils.alert(alertEl);
|
|
});
|
|
});
|