use template strings in a bunch of places instead of id concatenation

This commit is contained in:
Andrew Dolgov 2021-02-19 15:09:53 +03:00
parent 131f34648d
commit d9fe14a012
4 changed files with 19 additions and 21 deletions

View File

@ -1091,7 +1091,7 @@ const App = {
this.hotkey_actions["select_article_cursor"] = () => { this.hotkey_actions["select_article_cursor"] = () => {
const id = Article.getUnderPointer(); const id = Article.getUnderPointer();
if (id) { if (id) {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) if (row)
row.toggleClassName("Selected"); row.toggleClassName("Selected");

View File

@ -37,7 +37,7 @@ const Article = {
if (!isNaN(parseInt(score))) { if (!isNaN(parseInt(score))) {
ids.forEach((id) => { ids.forEach((id) => {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) { if (row) {
row.setAttribute("data-score", score); row.setAttribute("data-score", score);
@ -94,7 +94,7 @@ const Article = {
w.location = url; w.location = url;
}, },
cdmUnsetActive: function (event) { cdmUnsetActive: function (event) {
const row = App.byId("RROW-" + Article.getActive()); const row = App.byId(`RROW-${Article.getActive()}`);
if (row) { if (row) {
row.removeClassName("active"); row.removeClassName("active");
@ -381,7 +381,7 @@ const Article = {
const force_to_top = params.force_to_top || false; const force_to_top = params.force_to_top || false;
const ctr = App.byId("headlines-frame"); const ctr = App.byId("headlines-frame");
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (!row || !ctr) return; if (!row || !ctr) return;
@ -398,7 +398,7 @@ const Article = {
Article.pack(row); Article.pack(row);
}); });
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) { if (row) {
Article.unpack(row); Article.unpack(row);

View File

@ -211,7 +211,7 @@ const Headlines = {
Headlines.select('none'); 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); Article.setActive(id);
@ -222,7 +222,7 @@ const Headlines = {
Headlines.toggleUnread(id, 0); Headlines.toggleUnread(id, 0);
} else { } 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 // this would only work if there's enough space
App.byId("headlines-frame").scrollTop -= scroll_position_A-scroll_position_B; App.byId("headlines-frame").scrollTop -= scroll_position_A-scroll_position_B;
@ -824,7 +824,7 @@ const Headlines = {
} }
ids.forEach((id) => { ids.forEach((id) => {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) { if (row) {
switch (cmode) { switch (cmode) {
@ -865,14 +865,14 @@ const Headlines = {
}); });
}, },
toggleMark: function (id) { toggleMark: function (id) {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) if (row)
row.toggleClassName("marked"); row.toggleClassName("marked");
}, },
togglePub: function (id) { togglePub: function (id) {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) if (row)
row.toggleClassName("published"); row.toggleClassName("published");
@ -886,7 +886,7 @@ const Headlines = {
let next_id = false; let next_id = false;
let current_id = Article.getActive(); 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...'); console.log('active article is obscured, resetting to first visible...');
current_id = Headlines.firstVisible(); current_id = Headlines.firstVisible();
prev_id = current_id; prev_id = current_id;
@ -925,7 +925,7 @@ const Headlines = {
} }
} else if (App.isCombinedMode()) { } else if (App.isCombinedMode()) {
// try to show hsp if no next article exists, in case there's useful information like first_id_changed etc // 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"); const ctr = App.byId("headlines-frame");
if (row) { if (row) {
@ -945,7 +945,7 @@ const Headlines = {
if (prev_id || current_id) { if (prev_id || current_id) {
if (App.isCombinedMode()) { if (App.isCombinedMode()) {
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
const row = App.byId("RROW-" + current_id); const row = App.byId(`RROW-${current_id}`);
const ctr = App.byId("headlines-frame"); const ctr = App.byId("headlines-frame");
const delta_px = Math.round(row.offsetTop) - Math.round(ctr.scrollTop); const delta_px = Math.round(row.offsetTop) - Math.round(ctr.scrollTop);
@ -977,7 +977,7 @@ const Headlines = {
} }
}, },
toggleUnread: function (id, cmode) { toggleUnread: function (id, cmode) {
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (row) { if (row) {
if (typeof cmode == "undefined") cmode = 2; if (typeof cmode == "undefined") cmode = 2;
@ -1203,7 +1203,7 @@ const Headlines = {
if (!below) { if (!below) {
for (let i = 0; i < visible_ids.length; i++) { for (let i = 0; i < visible_ids.length; i++) {
if (visible_ids[i] != id) { 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")) { if (e && e.hasClassName("Unread")) {
ids_to_mark.push(visible_ids[i]); ids_to_mark.push(visible_ids[i]);
@ -1215,7 +1215,7 @@ const Headlines = {
} else { } else {
for (let i = visible_ids.length - 1; i >= 0; i--) { for (let i = visible_ids.length - 1; i >= 0; i--) {
if (visible_ids[i] != id) { 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")) { if (e && e.hasClassName("Unread")) {
ids_to_mark.push(visible_ids[i]); ids_to_mark.push(visible_ids[i]);
@ -1234,7 +1234,7 @@ const Headlines = {
if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
for (let i = 0; i < ids_to_mark.length; i++) { 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"); e.removeClassName("Unread");
} }
} }
@ -1256,7 +1256,7 @@ const Headlines = {
}, },
scrollToArticleId: function (id) { scrollToArticleId: function (id) {
const container = App.byId("headlines-frame"); const container = App.byId("headlines-frame");
const row = App.byId("RROW-" + id); const row = App.byId(`RROW-${id}`);
if (!container || !row) return; if (!container || !row) return;

View File

@ -63,8 +63,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f
editLabel: function(id) { editLabel: function(id) {
xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => {
console.log(reply);
const fg_color = reply['fg_color']; const fg_color = reply['fg_color'];
const bg_color = reply['bg_color'] ? reply['bg_color'] : '#fff7d5'; 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; color = bg;
} }
const e = App.byId("icon-label-" + id); const e = App.byId(`icon-label-${id}`);
if (e) { if (e) {
if (bg) e.style.color = bg; if (bg) e.style.color = bg;