Преглед изворни кода

Scroll as read for Global view + throttle event

https://github.com/FreshRSS/FreshRSS/issues/1317
https://github.com/FreshRSS/FreshRSS/pull/1309
Alexandre Alapetite пре 9 година
родитељ
комит
ce14841cc0
1 измењених фајлова са 12 додато и 16 уклоњено
  1. 12 16
      p/scripts/main.js

+ 12 - 16
p/scripts/main.js

@@ -449,26 +449,22 @@ function auto_share(key) {
 	}
 	}
 }
 }
 
 
-function inMarkViewport(flux, box_to_follow) {
-	var bottom = flux.offset().top + flux.height(),
-		windowTop = box_to_follow.scrollTop();
-	return bottom < windowTop + 40;
-}
-
 function init_posts() {
 function init_posts() {
-	var box_to_follow = $(window);
-	if (context.current_view === 'global') {
-		box_to_follow = $("#panel");
-	}
+	var box_to_follow = context.current_view === 'global' ? $("#panel") : $(window);
 
 
 	if (context.auto_mark_scroll) {
 	if (context.auto_mark_scroll) {
+		var lastScroll = 0;	//Throttle
 		box_to_follow.scroll(function () {
 		box_to_follow.scroll(function () {
-			$('.not_read:visible').each(function () {
-				var $this = $(this);
-				if (inMarkViewport($this, box_to_follow)) {
-					mark_read($this, true);
-				}
-			});
+			if (lastScroll + 500 < Date.now()) {
+				lastScroll = Date.now();
+				$('.not_read:visible').each(function () {
+					var $this = $(this),
+						minTop = (context.current_view === 'global') ? box_to_follow.offset().top : box_to_follow.scrollTop();
+					if ($this.offset().top + $this.height() < minTop + 40) {
+						mark_read($this, true);
+					}
+				});
+			}
 		});
 		});
 	}
 	}