From d2d2cb7e7dd25f8257f467806da6843aca95a9cb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 6 Dec 2018 14:23:45 +0300 Subject: rework scoring display, JS processing and icons --- js/Article.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/Article.js b/js/Article.js index 507560ee4..46769223e 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"]); } }); } -- cgit v1.2.3