diff --git a/js/Headlines.js b/js/Headlines.js index 354c8b18d..796c182e5 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -213,7 +213,7 @@ define(["dojo/_base/declare"], function (declare) { clearTimeout(this._headlines_scroll_timeout); this._headlines_scroll_timeout = window.setTimeout(function () { //console.log('done scrolling', event); - Headlines.scrollHandler(); + Headlines.scrollHandler(event); }, 50); } }, @@ -245,27 +245,39 @@ define(["dojo/_base/declare"], function (declare) { Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), offset: offset, append: true}); }, - scrollHandler: function () { + isChildVisible: function (elem, ctr) { + const ctop = ctr.scrollTop; + const cbottom = ctop + ctr.offsetHeight; + + const etop = elem.offsetTop; + const ebottom = etop + elem.offsetHeight; + + return etop >= ctop && ebottom <= cbottom || + etop < ctop && ebottom > ctop || ebottom > cbottom && etop < cbottom + + }, + scrollHandler: function (/*event*/) { try { Headlines.unpackVisible(); if (App.isCombinedMode()) { Headlines.updateFloatingTitle(); - // set topmost child in the buffer as active, but not if we're at the beginning (to prevent auto marking + const ctr = $("headlines-frame"); + + // set first visible child in the buffer as active, but not if we're at the beginning (to prevent auto marking // first article as read all the time) - if ($("headlines-frame").scrollTop != 0 && - App.getInitParam("cdm_expanded") && App.getInitParam("cdm_auto_catchup") == 1) { + if (ctr.scrollTop > 0 && App.getInitParam("cdm_expanded") /*&& App.getInitParam("cdm_auto_catchup") == 1*/) { const rows = $$("#headlines-frame > div[id*=RROW]"); for (let i = 0; i < rows.length; i++) { const row = rows[i]; - if ($("headlines-frame").scrollTop <= row.offsetTop && - row.offsetTop - $("headlines-frame").scrollTop < 100 && - row.getAttribute("data-article-id") != Article.getActive()) { + /*console.log(row.getAttribute("data-article-title"), row.offsetTop, row.offsetHeight, ctr.scrollTop, ctr.offsetHeight, + this.isChildVisible(row, ctr));*/ + if (this.isChildVisible(row, ctr)) { Article.setActive(row.getAttribute("data-article-id")); break; } @@ -443,7 +455,7 @@ define(["dojo/_base/declare"], function (declare) { const originally_from = Article.formatOriginallyFrom(hl); row = `