From 434ea0595ec9f46c824fea3ba7e00419a4066386 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 19 Apr 2021 12:59:16 +0200 Subject: [PATCH] Allow flash messages to appear a second time --- lib/assets/javascripts/flash.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/assets/javascripts/flash.js b/lib/assets/javascripts/flash.js index f4cead8f..3f217e4a 100644 --- a/lib/assets/javascripts/flash.js +++ b/lib/assets/javascripts/flash.js @@ -40,10 +40,16 @@ $( document ).on('turbolinks:load', function() { container.animation = setTimeout(hide, DURATION); } - button.on('click', function () { - clearTimeout(container.animation); - hide(); - }); + // This will be fired by Bootstrap automatically + container.on('close.bs.alert', function (e) { + // Did the user click on the on the button to close? + if (e.target instanceof Element || e.target instanceof HTMLElement) { + clearTimeout(container.animation); + hide(); + } + // We need to stop event propagation here. Otherwise, Bootstrap would remove the DOM element + e.preventDefault(); + }) }); };