From 3993198aa78a11e8f224c43ec0ac4588e7d8c402 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 10 Dec 2019 12:55:24 +0300 Subject: [PATCH] when moving next or previous and currently active article is entirely invisible, start moving from first visible one --- js/Headlines.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/js/Headlines.js b/js/Headlines.js index 47129c109..25244f195 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -256,6 +256,18 @@ define(["dojo/_base/declare"], function (declare) { etop < ctop && ebottom > ctop || ebottom > cbottom && etop < cbottom }, + firstVisible: function() { + const rows = $$("#headlines-frame > div[id*=RROW]"); + const ctr = $("headlines-frame"); + + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + + if (this.isChildVisible(row, ctr)) { + return row.getAttribute("data-article-id"); + } + } + }, scrollHandler: function (/*event*/) { try { Headlines.unpackVisible(); @@ -830,13 +842,15 @@ define(["dojo/_base/declare"], function (declare) { let prev_id = false; let next_id = false; - if (!$('RROW-' + Article.getActive())) { + const active_row = $("RROW-" + Article.getActive()); + + if (!active_row) { Article.setActive(0); } - if (!Article.getActive()) { - next_id = rows[0]; - prev_id = rows[rows.length - 1] + if (!Article.getActive() || (active_row && !Headlines.isChildVisible(active_row, $("headlines-frame")))) { + next_id = Headlines.firstVisible(); + prev_id = next_id; } else { for (let i = 0; i < rows.length; i++) { if (rows[i] == Article.getActive()) { @@ -889,7 +903,7 @@ define(["dojo/_base/declare"], function (declare) { if (!noscroll) { Article.scroll(-ctr.offsetHeight / 2, event); } else { - if (row.offsetTop < ctr.scrollTop) { + if (row && row.offsetTop < ctr.scrollTop) { Article.cdmScrollToId(Article.getActive(), noscroll, event); } else if (prev_id) { Article.setActive(prev_id);