From a802649d5397da0bdeaceddf3a9a38093053bcba Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 9 May 2020 08:16:12 +0300 Subject: [PATCH] rename cdmScrollToId to cdmMoveToId prevent smooth scrolling when going directly to an article --- js/Article.js | 8 ++++++-- js/Headlines.js | 24 ++++++++++++------------ plugins/af_readability/init.js | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/js/Article.js b/js/Article.js index 36c2aeff5..cfdd9be46 100644 --- a/js/Article.js +++ b/js/Article.js @@ -290,7 +290,11 @@ define(["dojo/_base/declare"], function (declare) { dialog.show(); }, - cdmScrollToId: function (id, force, event, immediate) { + cdmMoveToId: function (id, params) { + const force = params.force || true; + const event = params.event || null; + const noscroll = params.noscroll || false; + const ctr = $("headlines-frame"); const e = $("RROW-" + id); const is_expanded = App.getInitParam("cdm_expanded"); @@ -300,7 +304,7 @@ define(["dojo/_base/declare"], function (declare) { if (force || is_expanded || e.offsetTop + e.offsetHeight > (ctr.scrollTop + ctr.offsetHeight) || e.offsetTop < ctr.scrollTop) { - if (immediate || event && event.repeat || !is_expanded) { + if (noscroll || event && event.repeat || !is_expanded) { ctr.addClassName("forbid-smooth-scroll"); window.clearTimeout(this._scroll_reset_timeout); diff --git a/js/Headlines.js b/js/Headlines.js index 79eecd79f..83ac03bc8 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -185,7 +185,7 @@ define(["dojo/_base/declare"], function (declare) { Headlines.toggleUnread(id, 0); } else { - Article.cdmScrollToId(id); + Article.cdmMoveToId(id); } } else if (in_body) { @@ -333,7 +333,7 @@ define(["dojo/_base/declare"], function (declare) { ft.setAttribute("data-article-id", id); ft.innerHTML = header.innerHTML; - ft.select(".dijitCheckBox")[0].outerHTML = "expand_more"; + ft.select(".dijitCheckBox")[0].outerHTML = "expand_more"; this.initFloatingMenu(); @@ -415,7 +415,7 @@ define(["dojo/_base/declare"], function (declare) { new_row.addClassName("active"); if (App.isCombinedMode()) - Article.cdmScrollToId(id, true, null, true); + Article.cdmMoveToId(id, {noscroll: true}); else Article.view(id); } @@ -884,11 +884,11 @@ define(["dojo/_base/declare"], function (declare) { //const row = $("RROW-" + Article.getActive()); const ctr = $("headlines-frame"); - if (!noscroll) { - Article.scroll(ctr.offsetHeight / 2, event); - } else if (next_id) { + if (noscroll) { Article.setActive(next_id); - Article.cdmScrollToId(next_id, true, event); + Article.cdmMoveToId(next_id, { event: event, noscroll: noscroll }); + } else if (next_id) { + Article.scroll(ctr.offsetHeight / 2, event); } } else if (next_id) { @@ -906,15 +906,15 @@ define(["dojo/_base/declare"], function (declare) { //const prev_row = $("RROW-" + prev_id); const ctr = $("headlines-frame"); - if (!noscroll) { - Article.scroll(-ctr.offsetHeight / 2, event); - } else { + if (noscroll) { if (row && Math.round(row.offsetTop) < Math.round(ctr.scrollTop)) { - Article.cdmScrollToId(Article.getActive(), noscroll, event); + Article.cdmMoveToId(Article.getActive(), { force: noscroll, event: event }); } else if (prev_id) { Article.setActive(prev_id); - Article.cdmScrollToId(prev_id, noscroll, event); + Article.cdmMoveToId(prev_id, { force: noscroll, event: event, noscroll: noscroll }); } + } else { + Article.scroll(-ctr.offsetHeight / 2, event); } } else if (prev_id) { diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js index 644dff9fe..3155475cc 100644 --- a/plugins/af_readability/init.js +++ b/plugins/af_readability/init.js @@ -9,7 +9,7 @@ Plugins.Af_Readability = { content.innerHTML = content.getAttribute(self.orig_attr_name); content.removeAttribute(self.orig_attr_name); - if (App.isCombinedMode()) Article.cdmScrollToId(id); + if (App.isCombinedMode()) Article.cdmMoveToId(id); return; } @@ -23,7 +23,7 @@ Plugins.Af_Readability = { content.innerHTML = reply.content; Notify.close(); - if (App.isCombinedMode()) Article.cdmScrollToId(id); + if (App.isCombinedMode()) Article.cdmMoveToId(id); } else { Notify.error("Unable to fetch full text for this article");