From 1277d32161df2a93da3ac7831a84fec2faf2ed12 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Sat, 11 Jan 2014 11:33:51 -0700 Subject: [PATCH] The previous behavior was causing multiple notifications on if you switched between boards too quickly --- builds/4chan-X.user.js | 10 +++++++--- builds/crx/script.js | 10 +++++++--- src/General/Index.coffee | 6 ++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index cb9968b6a..c93aebf31 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -2501,7 +2501,7 @@ } now = Date.now(); $.ready(function() { - return setTimeout((function() { + return Index.nTimeout = setTimeout((function() { if (Index.req && !Index.notice) { return Index.notice = new Notice('info', 'Refreshing index...', 2); } @@ -2522,9 +2522,13 @@ return $.addClass(Index.button, 'fa-spin'); }, load: function(e, pageNum) { - var err, notice, req, timeEl; + var err, nTimeout, notice, req, timeEl; $.rmClass(Index.button, 'fa-spin'); - req = Index.req, notice = Index.notice; + req = Index.req, notice = Index.notice, nTimeout = Index.nTimeout; + if (nTimeout) { + clearTimeout(nTimeout); + } + delete Index.nTimeout; delete Index.req; delete Index.notice; if (e.type === 'abort') { diff --git a/builds/crx/script.js b/builds/crx/script.js index db29c4ddd..85c885e96 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -2511,7 +2511,7 @@ } now = Date.now(); $.ready(function() { - return setTimeout((function() { + return Index.nTimeout = setTimeout((function() { if (Index.req && !Index.notice) { return Index.notice = new Notice('info', 'Refreshing index...', 2); } @@ -2532,9 +2532,13 @@ return $.addClass(Index.button, 'fa-spin'); }, load: function(e, pageNum) { - var err, notice, req, timeEl; + var err, nTimeout, notice, req, timeEl; $.rmClass(Index.button, 'fa-spin'); - req = Index.req, notice = Index.notice; + req = Index.req, notice = Index.notice, nTimeout = Index.nTimeout; + if (nTimeout) { + clearTimeout(nTimeout); + } + delete Index.nTimeout; delete Index.req; delete Index.notice; if (e.type === 'abort') { diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 611b2fb70..8a4a51da8 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -236,7 +236,7 @@ Index = # This notice only displays if Index Refresh is taking too long now = Date.now() $.ready -> - setTimeout (-> + Index.nTimeout = setTimeout (-> if Index.req and !Index.notice Index.notice = new Notice 'info', 'Refreshing index...', 2 ), 3 * $.SECOND - (Date.now() - now) @@ -252,7 +252,9 @@ Index = load: (e, pageNum) -> $.rmClass Index.button, 'fa-spin' - {req, notice} = Index + {req, notice, nTimeout} = Index + clearTimeout nTimeout if nTimeout + delete Index.nTimeout delete Index.req delete Index.notice