rename cdmScrollToId to cdmMoveToId

prevent smooth scrolling when going directly to an article
This commit is contained in:
Andrew Dolgov 2020-05-09 08:16:12 +03:00
parent 2558fcbe21
commit a802649d53
3 changed files with 20 additions and 16 deletions

View File

@ -290,7 +290,11 @@ define(["dojo/_base/declare"], function (declare) {
dialog.show(); 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 ctr = $("headlines-frame");
const e = $("RROW-" + id); const e = $("RROW-" + id);
const is_expanded = App.getInitParam("cdm_expanded"); 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) || if (force || is_expanded || e.offsetTop + e.offsetHeight > (ctr.scrollTop + ctr.offsetHeight) ||
e.offsetTop < ctr.scrollTop) { e.offsetTop < ctr.scrollTop) {
if (immediate || event && event.repeat || !is_expanded) { if (noscroll || event && event.repeat || !is_expanded) {
ctr.addClassName("forbid-smooth-scroll"); ctr.addClassName("forbid-smooth-scroll");
window.clearTimeout(this._scroll_reset_timeout); window.clearTimeout(this._scroll_reset_timeout);

View File

@ -185,7 +185,7 @@ define(["dojo/_base/declare"], function (declare) {
Headlines.toggleUnread(id, 0); Headlines.toggleUnread(id, 0);
} else { } else {
Article.cdmScrollToId(id); Article.cdmMoveToId(id);
} }
} else if (in_body) { } else if (in_body) {
@ -333,7 +333,7 @@ define(["dojo/_base/declare"], function (declare) {
ft.setAttribute("data-article-id", id); ft.setAttribute("data-article-id", id);
ft.innerHTML = header.innerHTML; ft.innerHTML = header.innerHTML;
ft.select(".dijitCheckBox")[0].outerHTML = "<i class=\"material-icons icon-anchor\" onclick=\"Article.cdmScrollToId(" + id + ", true)\">expand_more</i>"; ft.select(".dijitCheckBox")[0].outerHTML = "<i class=\"material-icons icon-anchor\" onclick=\"Article.cdmMoveToId(" + id + ")\">expand_more</i>";
this.initFloatingMenu(); this.initFloatingMenu();
@ -415,7 +415,7 @@ define(["dojo/_base/declare"], function (declare) {
new_row.addClassName("active"); new_row.addClassName("active");
if (App.isCombinedMode()) if (App.isCombinedMode())
Article.cdmScrollToId(id, true, null, true); Article.cdmMoveToId(id, {noscroll: true});
else else
Article.view(id); Article.view(id);
} }
@ -884,11 +884,11 @@ define(["dojo/_base/declare"], function (declare) {
//const row = $("RROW-" + Article.getActive()); //const row = $("RROW-" + Article.getActive());
const ctr = $("headlines-frame"); const ctr = $("headlines-frame");
if (!noscroll) { if (noscroll) {
Article.scroll(ctr.offsetHeight / 2, event);
} else if (next_id) {
Article.setActive(next_id); 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) { } else if (next_id) {
@ -906,15 +906,15 @@ define(["dojo/_base/declare"], function (declare) {
//const prev_row = $("RROW-" + prev_id); //const prev_row = $("RROW-" + prev_id);
const ctr = $("headlines-frame"); const ctr = $("headlines-frame");
if (!noscroll) { if (noscroll) {
Article.scroll(-ctr.offsetHeight / 2, event);
} else {
if (row && Math.round(row.offsetTop) < Math.round(ctr.scrollTop)) { 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) { } else if (prev_id) {
Article.setActive(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) { } else if (prev_id) {

View File

@ -9,7 +9,7 @@ Plugins.Af_Readability = {
content.innerHTML = content.getAttribute(self.orig_attr_name); content.innerHTML = content.getAttribute(self.orig_attr_name);
content.removeAttribute(self.orig_attr_name); content.removeAttribute(self.orig_attr_name);
if (App.isCombinedMode()) Article.cdmScrollToId(id); if (App.isCombinedMode()) Article.cdmMoveToId(id);
return; return;
} }
@ -23,7 +23,7 @@ Plugins.Af_Readability = {
content.innerHTML = reply.content; content.innerHTML = reply.content;
Notify.close(); Notify.close();
if (App.isCombinedMode()) Article.cdmScrollToId(id); if (App.isCombinedMode()) Article.cdmMoveToId(id);
} else { } else {
Notify.error("Unable to fetch full text for this article"); Notify.error("Unable to fetch full text for this article");