document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll('.customhtml-alert').forEach(function (alertEl) { var timeout = parseInt(alertEl.getAttribute('data-timeout'), 10) || 0; var timer = null; var dismiss = function () { alertEl.classList.add('customhtml-alert-collapsing'); }; if (timeout > 0) { timer = setTimeout(dismiss, timeout * 1000); } var closeButton = alertEl.querySelector('.customhtml-alert-close'); if (closeButton) { closeButton.addEventListener('click', function () { if (timer) { clearTimeout(timer); } dismiss(); }); } }); });