diff --git a/classes/article.php b/classes/article.php index 4dbf2ca3a..22f35b509 100755 --- a/classes/article.php +++ b/classes/article.php @@ -254,10 +254,7 @@ class Article extends Handler_Protected { $sth->execute(array_merge([$score], $ids, [$_SESSION['uid']])); - print json_encode(array("id" => $ids, - "score" => (int)$score, - "score_class" => get_score_class($score), - "score_pic" => get_score_pic($score))); + print json_encode(["id" => $ids, "score" => (int)$score]); } function getScore() { @@ -269,9 +266,7 @@ class Article extends Handler_Protected { $score = $row['score']; - print json_encode(array("id" => $id, - "score" => (int)$score, - "score_pic" => get_score_pic($score))); + print json_encode(["id" => $id, "score" => (int)$score]); } diff --git a/classes/feeds.php b/classes/feeds.php index a79a1ebd2..68cf52f12 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -344,9 +344,6 @@ class Feeds extends Handler_Protected { $score = $line["score"]; - $line["score_pic"] = get_score_pic($score); - $line["score_class"] = get_score_class($score); - if ($line["tag_cache"]) $tags = explode(",", $line["tag_cache"]); else diff --git a/include/functions.php b/include/functions.php index 20c1919a8..f44d91a15 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1977,34 +1977,6 @@ return $filters; } - function get_score_pic($score) { - if ($score > 500) { - return "trending_up"; - } else if ($score > 0) { - return "trending_up"; - } else if ($score < 0) { - return "trending_down"; - } else { - return "trending_neutral"; - } - } - - function get_score_class($score) { - if ($score > 500) { - $score_class = "score-high"; - } else if ($score > 0) { - $score_class = "score-half-high"; - } else if ($score < -100) { - $score_class = "score-low"; - } else if ($score < 0) { - $score_class = "score-half-low"; - } else { - $score_class = "score-neutral"; - } - - return $score_class; - } - function init_plugins() { PluginHost::getInstance()->load(PLUGINS, PluginHost::KIND_ALL); diff --git a/js/Article.js b/js/Article.js index 3f595ff29..cfba3804b 100644 --- a/js/Article.js +++ b/js/Article.js @@ -2,6 +2,30 @@ /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { Article = { + getScoreClass: function (score) { + if (score > 500) { + return "score-high"; + } else if (score > 0) { + return "score-half-high"; + } else if (score < -100) { + return "score-low"; + } else if (score < 0) { + return "score-half-low"; + } else { + return "score-neutral"; + } + }, + getScorePic: function (score) { + if (score > 500) { + return "trending_up"; + } else if (score > 0) { + return "trending_up"; + } else if (score < 0) { + return "trending_down"; + } else { + return "trending_neutral"; + } + }, selectionSetScore: function () { const ids = Headlines.getSelected(); @@ -21,23 +45,20 @@ 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"]); + ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"] + .each(function(scl) { + row.removeClassName(scl); + }); + row.addClassName(Article.getScoreClass(reply['score'])); if (row) { + row.setAttribute("data-score", reply["score"]); + const pic = row.select(".icon-score")[0]; - if (pic) { - pic.innerHTML = reply["score_pic"]; - pic.setAttribute("data-score", reply["score"]); - pic.setAttribute("title", reply["score"]); - } + pic.innerHTML = reply["score_pic"]; + pic.setAttribute("title", reply["score"]); } }); } @@ -50,7 +71,7 @@ define(["dojo/_base/declare"], function (declare) { }, setScore: function (id, pic) { const row = pic.up("div[id*=RROW]"); - const score = pic.getAttribute("data-score"); + const score = row.getAttribute("data-score"); const new_score = prompt(__("Please enter new score for this article:"), score); @@ -60,16 +81,14 @@ define(["dojo/_base/declare"], function (declare) { xhrJson("backend.php", query, (reply) => { if (reply) { pic.innerHTML = reply["score_pic"]; - pic.setAttribute("data-score", new_score); - pic.setAttribute("title", new_score); + row.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"); + ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"] + .each(function(scl) { + row.removeClassName(scl); + }); - row.addClassName(reply["score_class"]); + row.addClassName(Article.getScoreClass(reply['score'])); } }); } diff --git a/js/Headlines.js b/js/Headlines.js index 1db858bb7..64b3bd69d 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -400,8 +400,9 @@ define(["dojo/_base/declare"], function (declare) { const comments = Article.formatComments(hl); const originally_from = Article.formatOriginallyFrom(hl); - row = `
+ row = `
@@ -426,8 +427,7 @@ define(["dojo/_base/declare"], function (declare) { ${hl.updated}
- ${hl.score_pic} + ${Article.getScorePic(hl.score)} ${hl.feed_icon} @@ -464,8 +464,8 @@ define(["dojo/_base/declare"], function (declare) { } else { - row = `
+ row = `
star @@ -485,8 +485,7 @@ define(["dojo/_base/declare"], function (declare) { ${hl.updated}
- ${hl.score_pic} + ${Article.getScorePic(hl.score)} ${hl.feed_icon}