diff options
Diffstat (limited to 'js/Article.js')
-rw-r--r-- | js/Article.js | 103 |
1 files changed, 44 insertions, 59 deletions
diff --git a/js/Article.js b/js/Article.js index 50447c2a1..3056dd666 100644 --- a/js/Article.js +++ b/js/Article.js @@ -139,7 +139,7 @@ define(["dojo/_base/declare"], function (declare) { c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); - Headlines.correctHeadlinesOffset(Article.getActive()); + //Headlines.correctHeadlinesOffset(Article.getActive()); try { c.focus(); @@ -149,14 +149,14 @@ define(["dojo/_base/declare"], function (declare) { formatComments: function(hl) { let comments = ""; - if (hl.comments) { + if (hl.comments || hl.num_comments > 0) { let comments_msg = __("comments"); if (hl.num_comments > 0) { comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments) } - comments = `<a href="${escapeHtml(hl.comments)}">(${comments_msg})</a>`; + comments = `<a href="${escapeHtml(hl.comments ? hl.comments : hl.link)}">(${comments_msg})</a>`; } return comments; @@ -178,15 +178,29 @@ define(["dojo/_base/declare"], function (declare) { if (container.textContent.length == 0) container.innerHTML += " "; + // in expandable mode, save content for later, so that we can pack unfocused rows back + if (App.isCombinedMode() && $("main").hasClassName("expandable")) + row.setAttribute("data-content-original", row.getAttribute("data-content")); + row.removeAttribute("data-content"); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); } }, - view: function (id, noexpand) { + pack: function(row) { + if (row.hasAttribute("data-content-original")) { + console.log("packing", row.id); + row.setAttribute("data-content", row.getAttribute("data-content-original")); + row.removeAttribute("data-content-original"); + + row.querySelector(".content-inner").innerHTML = " "; + } + }, + view: function (id, no_expand) { this.setActive(id); + Headlines.scrollToArticleId(id); - if (!noexpand) { + if (!no_expand) { const hl = Headlines.objectById(id); if (hl) { @@ -277,49 +291,39 @@ define(["dojo/_base/declare"], function (declare) { dialog.show(); }, - cdmScrollToId: function (id, force, event) { - const ctr = $("headlines-frame"); - const e = $("RROW-" + id); - const is_expanded = App.getInitParam("cdm_expanded"); - - if (!e || !ctr) return; + cdmMoveToId: function (id, params) { + params = params || {}; - if (force || is_expanded || e.offsetTop + e.offsetHeight > (ctr.scrollTop + ctr.offsetHeight) || - e.offsetTop < ctr.scrollTop) { + const force_to_top = params.force_to_top || false; - if (event && event.repeat || !is_expanded) { - ctr.addClassName("forbid-smooth-scroll"); - window.clearTimeout(this._scroll_reset_timeout); - - this._scroll_reset_timeout = window.setTimeout(() => { - if (ctr) ctr.removeClassName("forbid-smooth-scroll"); - }, 250) - - } else { - ctr.removeClassName("forbid-smooth-scroll"); - } + const ctr = $("headlines-frame"); + const row = $("RROW-" + id); - ctr.scrollTop = e.offsetTop; + if (!row || !ctr) return; - Element.hide("floatingTitle"); + if (force_to_top || !App.Scrollable.fitsInContainer(row, ctr)) { + ctr.scrollTop = row.offsetTop; } }, setActive: function (id) { - console.log("setActive", id); + if (id != Article.getActive()) { + console.log("setActive", id, "was", Article.getActive()); - $$("div[id*=RROW][class*=active]").each((e) => { - e.removeClassName("active"); - }); + $$("div[id*=RROW][class*=active]").each((row) => { + row.removeClassName("active"); + Article.pack(row); + }); - const row = $("RROW-" + id); + const row = $("RROW-" + id); - if (row) { - Article.unpack(row); + if (row) { + Article.unpack(row); - row.removeClassName("Unread"); - row.addClassName("active"); + row.removeClassName("Unread"); + row.addClassName("active"); - PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id")); + PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id")); + } } }, getActive: function () { @@ -330,30 +334,11 @@ define(["dojo/_base/declare"], function (declare) { else return 0; }, - scrollByPages: function (page_offset, event) { - const elem = App.isCombinedMode() ? $("headlines-frame") : $("content-insert"); - - const offset = elem.offsetHeight * page_offset * 0.99; - - this.scroll(offset, event); + scrollByPages: function (page_offset) { + App.Scrollable.scrollByPages($("content-insert"), page_offset); }, - scroll: function (offset, event) { - - const elem = App.isCombinedMode() ? $("headlines-frame") : $("content-insert"); - - if (event && event.repeat) { - elem.addClassName("forbid-smooth-scroll"); - window.clearTimeout(this._scroll_reset_timeout); - - this._scroll_reset_timeout = window.setTimeout(() => { - if (elem) elem.removeClassName("forbid-smooth-scroll"); - }, 250) - - } else { - elem.removeClassName("forbid-smooth-scroll"); - } - - elem.scrollTop += offset; + scroll: function (offset) { + App.Scrollable.scroll($("content-insert"), offset); }, mouseIn: function (id) { this.post_under_pointer = id; |