From d9fe14a0123eb90008a1be4b6ab9bb21b42f3776 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 15:09:53 +0300 Subject: [PATCH] use template strings in a bunch of places instead of id concatenation --- js/App.js | 2 +- js/Article.js | 8 ++++---- js/Headlines.js | 26 +++++++++++++------------- js/PrefLabelTree.js | 4 +--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/js/App.js b/js/App.js index 544057101..764003ca9 100644 --- a/js/App.js +++ b/js/App.js @@ -1091,7 +1091,7 @@ const App = { this.hotkey_actions["select_article_cursor"] = () => { const id = Article.getUnderPointer(); if (id) { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) row.toggleClassName("Selected"); diff --git a/js/Article.js b/js/Article.js index 4cd4d3237..4f3a162de 100644 --- a/js/Article.js +++ b/js/Article.js @@ -37,7 +37,7 @@ const Article = { if (!isNaN(parseInt(score))) { ids.forEach((id) => { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) { row.setAttribute("data-score", score); @@ -94,7 +94,7 @@ const Article = { w.location = url; }, cdmUnsetActive: function (event) { - const row = App.byId("RROW-" + Article.getActive()); + const row = App.byId(`RROW-${Article.getActive()}`); if (row) { row.removeClassName("active"); @@ -381,7 +381,7 @@ const Article = { const force_to_top = params.force_to_top || false; const ctr = App.byId("headlines-frame"); - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (!row || !ctr) return; @@ -398,7 +398,7 @@ const Article = { Article.pack(row); }); - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) { Article.unpack(row); diff --git a/js/Headlines.js b/js/Headlines.js index 036c923a8..2effc9192 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -211,7 +211,7 @@ const Headlines = { Headlines.select('none'); - const scroll_position_A = App.byId("RROW-" + id).offsetTop - App.byId("headlines-frame").scrollTop; + const scroll_position_A = App.byId(`RROW-${id}`).offsetTop - App.byId("headlines-frame").scrollTop; Article.setActive(id); @@ -222,7 +222,7 @@ const Headlines = { Headlines.toggleUnread(id, 0); } else { - const scroll_position_B = App.byId("RROW-" + id).offsetTop - App.byId("headlines-frame").scrollTop; + const scroll_position_B = App.byId(`RROW-${id}`).offsetTop - App.byId("headlines-frame").scrollTop; // this would only work if there's enough space App.byId("headlines-frame").scrollTop -= scroll_position_A-scroll_position_B; @@ -824,7 +824,7 @@ const Headlines = { } ids.forEach((id) => { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) { switch (cmode) { @@ -865,14 +865,14 @@ const Headlines = { }); }, toggleMark: function (id) { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) row.toggleClassName("marked"); }, togglePub: function (id) { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) row.toggleClassName("published"); @@ -886,7 +886,7 @@ const Headlines = { let next_id = false; let current_id = Article.getActive(); - if (!Headlines.isChildVisible(App.byId("RROW-" + current_id))) { + if (!Headlines.isChildVisible(App.byId(`RROW-${current_id}`))) { console.log('active article is obscured, resetting to first visible...'); current_id = Headlines.firstVisible(); prev_id = current_id; @@ -925,7 +925,7 @@ const Headlines = { } } else if (App.isCombinedMode()) { // try to show hsp if no next article exists, in case there's useful information like first_id_changed etc - const row = App.byId("RROW-" + current_id); + const row = App.byId(`RROW-${current_id}`); const ctr = App.byId("headlines-frame"); if (row) { @@ -945,7 +945,7 @@ const Headlines = { if (prev_id || current_id) { if (App.isCombinedMode()) { window.requestAnimationFrame(() => { - const row = App.byId("RROW-" + current_id); + const row = App.byId(`RROW-${current_id}`); const ctr = App.byId("headlines-frame"); const delta_px = Math.round(row.offsetTop) - Math.round(ctr.scrollTop); @@ -977,7 +977,7 @@ const Headlines = { } }, toggleUnread: function (id, cmode) { - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (row) { if (typeof cmode == "undefined") cmode = 2; @@ -1203,7 +1203,7 @@ const Headlines = { if (!below) { for (let i = 0; i < visible_ids.length; i++) { if (visible_ids[i] != id) { - const e = App.byId("RROW-" + visible_ids[i]); + const e = App.byId(`RROW-${visible_ids[i]}`); if (e && e.hasClassName("Unread")) { ids_to_mark.push(visible_ids[i]); @@ -1215,7 +1215,7 @@ const Headlines = { } else { for (let i = visible_ids.length - 1; i >= 0; i--) { if (visible_ids[i] != id) { - const e = App.byId("RROW-" + visible_ids[i]); + const e = App.byId(`RROW-${visible_ids[i]}`); if (e && e.hasClassName("Unread")) { ids_to_mark.push(visible_ids[i]); @@ -1234,7 +1234,7 @@ const Headlines = { if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { for (let i = 0; i < ids_to_mark.length; i++) { - const e = App.byId("RROW-" + ids_to_mark[i]); + const e = App.byId(`RROW-${ids_to_mark[i]}`); e.removeClassName("Unread"); } } @@ -1256,7 +1256,7 @@ const Headlines = { }, scrollToArticleId: function (id) { const container = App.byId("headlines-frame"); - const row = App.byId("RROW-" + id); + const row = App.byId(`RROW-${id}`); if (!container || !row) return; diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 627b2cfbe..2b78927c2 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -63,8 +63,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f editLabel: function(id) { xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { - console.log(reply); - const fg_color = reply['fg_color']; const bg_color = reply['bg_color'] ? reply['bg_color'] : '#fff7d5'; @@ -87,7 +85,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f color = bg; } - const e = App.byId("icon-label-" + id); + const e = App.byId(`icon-label-${id}`); if (e) { if (bg) e.style.color = bg;