Explorar el Código

Add locker to mark_favorite action

Similar to c33b13809ef4e1941d3655479db8c5fcf5731013
See #423
Marien Fressinaud hace 12 años
padre
commit
69ce70be35
Se han modificado 1 ficheros con 17 adiciones y 5 borrados
  1. 17 5
      p/scripts/main.js

+ 17 - 5
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);
 	});
 }