diff options
Diffstat (limited to 'js/Article.js')
-rw-r--r-- | js/Article.js | 142 |
1 files changed, 85 insertions, 57 deletions
diff --git a/js/Article.js b/js/Article.js index 507560ee4..c3b6766c8 100644 --- a/js/Article.js +++ b/js/Article.js @@ -22,13 +22,22 @@ define(["dojo/_base/declare"], function (declare) { reply.id.each((id) => { const row = $("RROW-" + id); + row.removeClassName("score-low"); + row.removeClassName("score-high"); + row.removeClassName("score-half-low"); + row.removeClassName("score-half-high"); + row.removeClassName("score-neutral"); + + row.addClassName(reply["score_class"]); + + if (row) { - const pic = row.getElementsByClassName("score-pic")[0]; + const pic = row.select(".icon-score")[0]; if (pic) { - pic.src = pic.src.replace(/score_.*?\.png/, - reply["score_pic"]); - pic.setAttribute("score", reply["score"]); + pic.innerHTML = reply["score_pic"]; + pic.setAttribute("data-score", reply["score"]); + pic.setAttribute("title", reply["score"]); } } }); @@ -41,18 +50,27 @@ define(["dojo/_base/declare"], function (declare) { } }, setScore: function (id, pic) { - const score = pic.getAttribute("score"); + const row = pic.up("div[id*=RROW]"); + const score = pic.getAttribute("data-score"); const new_score = prompt(__("Please enter new score for this article:"), score); - if (new_score != undefined) { + if (row && new_score != undefined) { const query = {op: "article", method: "setScore", id: id, score: new_score}; xhrJson("backend.php", query, (reply) => { if (reply) { - pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); - pic.setAttribute("score", new_score); + pic.innerHTML = reply["score_pic"]; + pic.setAttribute("data-score", new_score); pic.setAttribute("title", new_score); + + row.removeClassName("score-low"); + row.removeClassName("score-high"); + row.removeClassName("score-half-low"); + row.removeClassName("score-half-high"); + row.removeClassName("score-neutral"); + + row.addClassName(reply["score_class"]); } }); } @@ -91,10 +109,13 @@ define(["dojo/_base/declare"], function (declare) { }, openInNewWindow: function (id) { const w = window.open(""); - w.opener = null; - w.location = "backend.php?op=article&method=redirect&id=" + id; - Headlines.toggleUnread(id, 0); + if (w) { + w.opener = null; + w.location = "backend.php?op=article&method=redirect&id=" + id; + + Headlines.toggleUnread(id, 0); + } }, render: function (article) { App.cleanupMemory("content-insert"); @@ -119,58 +140,65 @@ define(["dojo/_base/declare"], function (declare) { } catch (e) { } }, - view: function (id, noexpand) { - this.setActive(id); - - if (!noexpand) { - console.log("loading article", id); - - const cids = []; + formatComments: function(hl) { + let comments = ""; - /* only request uncached articles */ + if (hl.comments) { + let comments_msg = __("comments"); - this.getRelativeIds(id).each((n) => { - if (!ArticleCache.get(n)) - cids.push(n); - }); - - const cached_article = ArticleCache.get(id); - - if (cached_article) { - console.log('rendering cached', id); - this.render(cached_article); - return false; + if (hl.num_comments > 0) { + comments_msg = hl.num_comments + " " + ngettext("comment", "comments", hl.num_comments) } - xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => { - try { - const reply = App.handleRpcJson(transport); - - if (reply) { - - reply.each(function (article) { - if (Article.getActive() == article['id']) { - Article.render(article['content']); - } - ArticleCache.set(article['id'], article['content']); - }); - - } else { - console.error("Invalid object received: " + transport.responseText); - - Article.render("<div class='whiteBox'>" + - __('Could not display article (invalid object received - see error console for details)') + "</div>"); - } - - //const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; - //request_counters(unread_in_buffer == 0); + comments = `<a href="${hl.comments}">(${comments_msg})</a>`; + } - Notify.close(); + return comments; + }, + formatOriginallyFrom: function(hl) { + return hl.orig_feed ? `<span> + ${__('Originally from:')} <a target="_blank" rel="noopener noreferrer" href="${hl.orig_feed[1]}">${hl.orig_feed[0]}</a> + </span>` : ""; + }, + view: function (id, noexpand) { + this.setActive(id); - } catch (e) { - App.Error.report(e); - } - }) + if (!noexpand) { + const hl = Headlines.objectById(id); + + if (hl) { + + const comments = this.formatComments(hl); + const originally_from = this.formatOriginallyFrom(hl); + + const article = `<div class="post post-${hl.id}"> + <div class="header"> + <div class="row"> + <div class="title"><a target="_blank" rel="noopener noreferrer" title="${hl.title}" href="${hl.link}">${hl.title}</a></div> + <div class="date">${hl.updated_long}</div> + </div> + <div class="row"> + <div class="buttons left">${hl.buttons_left}</div> + <div class="comments">${comments}</div> + <div class="author">${hl.author}</div> + <i class="material-icons">label_outline</i> + <span id="ATSTR-${hl.id}">${hl.tags_str}</span> + <a title="${__("Edit tags for this article")}" href="#" + onclick="Article.editTags(${hl.id})">(+)</a> + <div class="buttons right">${hl.buttons}</div> + </div> + </div> + <div id="POSTNOTE-${hl.id}">${hl.note}</div> + <div class="content" lang="${hl.lang ? hl.lang : 'en'}"> + ${originally_from} + ${hl.content} + ${hl.enclosures} + </div> + </div>`; + + Headlines.toggleUnread(id, 0); + this.render(article); + } } return false; |