From 69ce70be35c511921cf0bfe05f21c3ba44c0f17a Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 15 Feb 2014 14:57:18 +0100 Subject: Add locker to mark_favorite action Similar to c33b13809ef4e1941d3655479db8c5fcf5731013 See #423 --- p/scripts/main.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/p/scripts/main.js b/p/scripts/main.js index 44517eb6c..39b780bd7 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1,7 +1,6 @@ "use strict"; var $stream = null, - isCollapsed = true, - pending_feed = []; + isCollapsed = true; function is_normal_mode() { return $stream.hasClass('normal'); @@ -107,6 +106,7 @@ function incUnreadsFeed(article, feed_id, nb) { return isCurrentView; } +var pending_feeds = []; function mark_read(active, only_not_read) { if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) { @@ -120,13 +120,13 @@ function mark_read(active, only_not_read) { var feed_url = active.find(".website>a").attr("href"), feed_id = feed_url.substr(feed_url.lastIndexOf('f_')), - index_pending = pending_feed.indexOf(feed_id); + index_pending = pending_feeds.indexOf(feed_id); if (index_pending !== -1) { return false; } - pending_feed.push(feed_id); + pending_feeds.push(feed_id); $.ajax({ type: 'POST', @@ -146,7 +146,7 @@ function mark_read(active, only_not_read) { incUnreadsFeed(active, feed_id, inc); - pending_feed.splice(index_pending, 1); + pending_feeds.splice(index_pending, 1); }); } @@ -160,6 +160,16 @@ function mark_favorite(active) { return false; } + var feed_url = active.find(".website>a").attr("href"), + feed_id = feed_url.substr(feed_url.lastIndexOf('f_')), + index_pending = pending_feeds.indexOf(feed_id); + + if (index_pending !== -1) { + return false; + } + + pending_feeds.push(feed_id); + $.ajax({ type: 'POST', url: url, @@ -190,6 +200,8 @@ function mark_favorite(active) { elem.setAttribute('data-unread', numberFormat(feed_unreads + inc)); } } + + pending_feeds.splice(index_pending, 1); }); } -- cgit v1.2.3