From dea01f5972bbd11237e7958b151b6a9149aec362 Mon Sep 17 00:00:00 2001 From: Toks Date: Thu, 10 Oct 2013 21:09:20 -0400 Subject: [PATCH] Improve notice autohide behavior Formerly it would act strangely when multiple notices were displayed in succession. --- app/assets/javascripts/utility.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/utility.js b/app/assets/javascripts/utility.js index e0941f5ca..b2c28353a 100644 --- a/app/assets/javascripts/utility.js +++ b/app/assets/javascripts/utility.js @@ -21,17 +21,28 @@ $('html, body').animate({scrollTop: top}, 300, "linear", function() {Danbooru.scrolling = false;}); } + Danbooru.notice_timeout_id = undefined; + Danbooru.notice = function(msg, permanent) { $('#notice').addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast").children("span").html(msg); + + if (Danbooru.notice_timeout_id !== undefined) { + clearTimeout(Danbooru.notice_timeout_id) + } if (!permanent) { - setTimeout(function() { + Danbooru.notice_timeout_id = setTimeout(function() { $("#close-notice-link").click(); + Danbooru.notice_timeout_id = undefined; }, 6000); } } Danbooru.error = function(msg) { $('#notice').removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast").children("span").html(msg); + + if (Danbooru.notice_timeout_id !== undefined) { + clearTimeout(Danbooru.notice_timeout_id) + } } Danbooru.is_subset = function(array, subarray) {