summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-10-16 15:11:38 +0200
committerGravatar GitHub <noreply@github.com> 2016-10-16 15:11:38 +0200
commit1f9f9ce972050f95be6176338aa9e15406c36553 (patch)
tree2664a3b3d330b1655f42b5154098801babfd5628
parent8db0249e17bc51bb293b112afbb4da1e436f14cc (diff)
parenteb88fee64bccfacbb8b1f5d84ba833d3a8286aa0 (diff)
Merge pull request #1324 from Alkarex/global-view-scroll
Global view scroll
-rw-r--r--p/scripts/global_view.js1
-rw-r--r--p/scripts/main.js34
2 files changed, 21 insertions, 14 deletions
diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js
index f1b9c8ad4..de0b9cb9f 100644
--- a/p/scripts/global_view.js
+++ b/p/scripts/global_view.js
@@ -26,6 +26,7 @@ function load_panel(link) {
// Sans ça, si l'on scroll en lisant une catégorie par exemple,
// en en ouvrant une autre ensuite, on se retrouve au même point de scroll
$("#panel").scrollTop(0);
+ $(window).scrollTop(0);
$('#panel').on('click', '#nav_menu_read_all button, #bigMarkAsRead', function () {
console.log($(this).attr("formaction"));
diff --git a/p/scripts/main.js b/p/scripts/main.js
index b3531e884..47d651d5b 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -449,26 +449,32 @@ 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 scrollAsRead(box_to_follow) {
+ var minTop = 40 + (context.current_view === 'global' ? box_to_follow.offset().top : box_to_follow.scrollTop());
+ $('.not_read:visible').each(function () {
+ var $this = $(this);
+ if ($this.offset().top + $this.height() < minTop) {
+ mark_read($this, true);
+ }
+ });
}
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) {
+ var lastScroll = 0, //Throttle
+ timerId = 0;
box_to_follow.scroll(function () {
- $('.not_read:visible').each(function () {
- var $this = $(this);
- if (inMarkViewport($this, box_to_follow)) {
- mark_read($this, true);
- }
- });
+ window.clearTimeout(timerId);
+ if (lastScroll + 500 < Date.now()) {
+ lastScroll = Date.now();
+ scrollAsRead(box_to_follow);
+ } else {
+ timerId = window.setTimeout(function() {
+ scrollAsRead(box_to_follow);
+ }, 500);
+ }
});
}