From: Andrew Dolgov Date: Thu, 29 Nov 2018 17:07:23 +0000 (+0300) Subject: eslint-related fixes X-Git-Tag: 18.12~35 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=424e28db6b706270c235a1ae089a880accbeb000;p=tt-rss.git eslint-related fixes --- diff --git a/js/feedlist.js b/js/feedlist.js index 628b9123..8c5cb73e 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -15,12 +15,12 @@ function resetCounterCache() { function loadMoreHeadlines() { console.log("loadMoreHeadlines"); - var offset = 0; + let offset = 0; - var view_mode = document.forms["main_toolbar_form"].view_mode.value; - var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; - var num_all = $$("#headlines-frame > div[id*=RROW]").length; - var num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat()); + const view_mode = document.forms["main_toolbar_form"].view_mode.value; + const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; + const num_all = $$("#headlines-frame > div[id*=RROW]").length; + const num_unread = getFeedUnread(getActiveFeedId(), activeFeedIsCat()); // TODO implement marked & published @@ -48,7 +48,7 @@ function loadMoreHeadlines() { } function cleanup_memory(root) { - var dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); + const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); dijits.each(function (d) { dojo.destroy(d.domNode); @@ -60,14 +60,14 @@ function cleanup_memory(root) { } function viewfeed(params) { - var feed = params.feed; - var is_cat = params.is_cat; - var offset = params.offset; - var background = params.background; - var infscroll_req = params.infscroll_req; - var can_wait = params.can_wait; - var viewfeed_debug = params.viewfeed_debug; - var method = params.method; + const feed = params.feed; + let is_cat = params.is_cat; + let offset = params.offset; + let background = params.background; + let infscroll_req = params.infscroll_req; + const can_wait = params.can_wait; + const viewfeed_debug = params.viewfeed_debug; + const method = params.method; if (is_cat == undefined) is_cat = false; @@ -96,7 +96,7 @@ function viewfeed(params) { } if (infscroll_req) { - var timestamp = get_timestamp(); + const timestamp = get_timestamp(); if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { //console.log("infscroll request in progress, aborting"); @@ -109,9 +109,9 @@ function viewfeed(params) { Form.enable("main_toolbar_form"); - var toolbar_query = Form.serialize("main_toolbar_form"); + const toolbar_query = Form.serialize("main_toolbar_form"); - var query = "?op=feeds&method=view&feed=" + param_escape(feed) + "&" + + let query = "?op=feeds&method=view&feed=" + param_escape(feed) + "&" + toolbar_query; if (method) query += "&m=" + param_escape(method); @@ -135,11 +135,9 @@ function viewfeed(params) { if (vgroup_last_feed) { query = query + "&vgrlf=" + param_escape(vgroup_last_feed); } - } else { - if (!is_cat && feed == getActiveFeedId() && !params.method) { + } else if (!is_cat && feed == getActiveFeedId() && !params.method) { query = query + "&m=ForceUpdate"; } - } Form.enable("main_toolbar_form"); @@ -163,7 +161,7 @@ function viewfeed(params) { window.open("backend.php" + query + "&debug=1&csrf_token=" + getInitParam("csrf_token")); } - var timeout_ms = can_wait ? 250 : 0; + const timeout_ms = can_wait ? 250 : 0; _viewfeed_timeout = setTimeout(function() { new Ajax.Request("backend.php", { @@ -200,7 +198,7 @@ function feedlist_init() { if (getInitParam("is_default_pw")) { console.warn("user password is at default value"); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ title: __("Your password is at default value"), href: "backend.php?op=dlg&method=defaultpasswordwarning", id: 'infoBox', @@ -229,15 +227,15 @@ function feedlist_init() { function request_counters(force) { - var date = new Date(); - var timestamp = Math.round(date.getTime() / 1000); + const date = new Date(); + const timestamp = Math.round(date.getTime() / 1000); if (force || timestamp - counters_last_request > 5) { console.log("scheduling request of counters..."); counters_last_request = timestamp; - var query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); + let query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); if (!force) query = query + "&last_article_id=" + getInitParam("last_article_id"); @@ -260,8 +258,8 @@ function request_counters(force) { // http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html function counter_is_equal(a, b) { // Create arrays of property names - var aProps = Object.getOwnPropertyNames(a); - var bProps = Object.getOwnPropertyNames(b); + const aProps = Object.getOwnPropertyNames(a); + const bProps = Object.getOwnPropertyNames(b); // If number of properties is different, // objects are not equivalent @@ -269,8 +267,8 @@ function counter_is_equal(a, b) { return false; } - for (var i = 0; i < aProps.length; i++) { - var propName = aProps[i]; + for (let i = 0; i < aProps.length; i++) { + const propName = aProps[i]; // If values of same property are not equal, // objects are not equivalent @@ -286,19 +284,19 @@ function counter_is_equal(a, b) { function parse_counters(elems) { - for (var l = 0; l < elems.length; l++) { + for (let l = 0; l < elems.length; l++) { if (_counters_prev[l] && counter_is_equal(elems[l], _counters_prev[l])) { continue; } - var id = elems[l].id; - var kind = elems[l].kind; - var ctr = parseInt(elems[l].counter); - var error = elems[l].error; - var has_img = elems[l].has_img; - var updated = elems[l].updated; - var auxctr = parseInt(elems[l].auxcounter); + const id = elems[l].id; + const kind = elems[l].kind; + const ctr = parseInt(elems[l].counter); + const error = elems[l].error; + const has_img = elems[l].has_img; + const updated = elems[l].updated; + const auxctr = parseInt(elems[l].auxcounter); if (id == "global-unread") { global_unread = ctr; @@ -340,7 +338,7 @@ function parse_counters(elems) { function getFeedUnread(feed, is_cat) { try { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.getFeedUnread(feed, is_cat); @@ -354,7 +352,7 @@ function getFeedUnread(feed, is_cat) { function getFeedCategory(feed) { try { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.getFeedCategory(feed); @@ -367,7 +365,7 @@ function getFeedCategory(feed) { } function hideOrShowFeeds(hide) { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree) return tree.hideRead(hide, getInitParam("hide_read_shows_special")); @@ -377,7 +375,7 @@ function getFeedName(feed, is_cat) { if (isNaN(feed)) return feed; // it's a tag - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.getFeedValue(feed, is_cat, 'name'); @@ -385,7 +383,7 @@ function getFeedName(feed, is_cat) { function getFeedValue(feed, is_cat, key) { try { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.getFeedValue(feed, is_cat, key); @@ -397,7 +395,7 @@ function getFeedValue(feed, is_cat, key) { } function setFeedUnread(feed, is_cat, unread) { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.setFeedUnread(feed, is_cat, unread); @@ -405,7 +403,7 @@ function setFeedUnread(feed, is_cat, unread) { function setFeedValue(feed, is_cat, key, value) { try { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree && tree.model) return tree.model.setFeedValue(feed, is_cat, key, value); @@ -416,19 +414,19 @@ function setFeedValue(feed, is_cat, key, value) { } function selectFeed(feed, is_cat) { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree) return tree.selectFeed(feed, is_cat); } function setFeedIcon(feed, is_cat, src) { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree) return tree.setFeedIcon(feed, is_cat, src); } function setFeedExpandoIcon(feed, is_cat, src) { - var tree = dijit.byId("feedTree"); + const tree = dijit.byId("feedTree"); if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); @@ -436,8 +434,8 @@ function setFeedExpandoIcon(feed, is_cat, src) { } function getNextUnreadFeed(feed, is_cat) { - var tree = dijit.byId("feedTree"); - var nuf = tree.model.getNextUnreadFeed(feed, is_cat); + const tree = dijit.byId("feedTree"); + const nuf = tree.model.getNextUnreadFeed(feed, is_cat); if (nuf) return tree.model.store.getValue(nuf, 'bare_id'); @@ -448,13 +446,13 @@ function catchupCurrentFeed(mode) { } function catchupFeedInGroup(id) { - var title = getFeedName(id); + const title = getFeedName(id); - var str = __("Mark all articles in %s as read?").replace("%s", title); + const str = __("Mark all articles in %s as read?").replace("%s", title); if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - var rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='"+id+"']"); + const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='"+id+"']"); if (rows.length > 0) { @@ -467,9 +465,9 @@ function catchupFeedInGroup(id) { }); - var feedTitles = $$("#headlines-frame > div[class='cdmFeedTitle']"); + const feedTitles = $$("#headlines-frame > div[class='cdmFeedTitle']"); - for (var i = 0; i < feedTitles.length; i++) { + for (let i = 0; i < feedTitles.length; i++) { if (feedTitles[i].getAttribute("data-feed-id") == id) { if (i < feedTitles.length - 1) { @@ -483,7 +481,7 @@ function catchupFeedInGroup(id) { updateFloatingTitle(true); } - var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + + const catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + id + "&is_cat=false"; console.log(catchup_query); @@ -504,7 +502,7 @@ function catchupFeedInGroup(id) { function catchupFeed(feed, is_cat, mode) { if (is_cat == undefined) is_cat = false; - var str = false; + let str = false; switch (mode) { case "1day": @@ -520,8 +518,8 @@ function catchupFeed(feed, is_cat, mode) { str = __("Mark %w in %s as read?"); } - var mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); - var fn = getFeedName(feed, is_cat); + const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); + const fn = getFeedName(feed, is_cat); str = str.replace("%s", fn) .replace("%w", mark_what); @@ -530,7 +528,7 @@ function catchupFeed(feed, is_cat, mode) { return; } - var catchup_query = {op: 'rpc', method: 'catchupFeed', feed_id: feed, + const catchup_query = {op: 'rpc', method: 'catchupFeed', feed_id: feed, is_cat: is_cat, mode: mode, search_query: last_search_query[0], search_lang: last_search_query[1]}; @@ -543,19 +541,17 @@ function catchupFeed(feed, is_cat, mode) { onComplete: function(transport) { handle_rpc_json(transport); - var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; + const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { - var nuf = getNextUnreadFeed(feed, is_cat); + const nuf = getNextUnreadFeed(feed, is_cat); if (nuf) { viewfeed({feed: nuf, is_cat: is_cat}); } - } else { - if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { + } else if (feed == getActiveFeedId() && is_cat == activeFeedIsCat()) { viewCurrentFeed(); } - } notify(""); } }); @@ -563,7 +559,7 @@ function catchupFeed(feed, is_cat, mode) { } function decrementFeedCounter(feed, is_cat) { - var ctr = getFeedUnread(feed, is_cat); + let ctr = getFeedUnread(feed, is_cat); if (ctr > 0) { setFeedUnread(feed, is_cat, ctr - 1); @@ -571,7 +567,7 @@ function decrementFeedCounter(feed, is_cat) { updateTitle(); if (!is_cat) { - var cat = parseInt(getFeedCategory(feed)); + const cat = parseInt(getFeedCategory(feed)); if (!isNaN(cat)) { ctr = getFeedUnread(cat, true); diff --git a/js/functions.js b/js/functions.js index 70842925..9028482f 100755 --- a/js/functions.js +++ b/js/functions.js @@ -25,12 +25,11 @@ Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( /* add method to remove element from array */ Array.prototype.remove = function(s) { - for (var i=0; i < this.length; i++) { + for (let i=0; i < this.length; i++) { if (s == this[i]) this.splice(i, 1); } }; - function report_error(message, filename, lineno, colno, error) { exception_error(error, null, filename, lineno); } @@ -42,7 +41,7 @@ function exception_error(e, e_compat, filename, lineno, colno) { try { console.error(e); - var msg = e.toString(); + const msg = e.toString(); try { new Ajax.Request("backend.php", { @@ -58,7 +57,7 @@ function exception_error(e, e_compat, filename, lineno, colno) { console.error("Exception while trying to log the error.", e); } - var content = "

" + msg + "

"; + let content = "

" + msg + "

"; if (e.stack) { content += "
Stack trace:
" + @@ -77,7 +76,7 @@ function exception_error(e, e_compat, filename, lineno, colno) { if (dijit.byId("exceptionDlg")) dijit.byId("exceptionDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "exceptionDlg", title: "Unhandled exception", style: "width: 600px", @@ -101,7 +100,7 @@ function param_escape(arg) { function notify_real(msg, no_hide, n_type) { - var n = $("notify"); + const n = $("notify"); if (!n) return; @@ -183,7 +182,7 @@ function notify_info(msg, no_hide) { function setCookie(name, value, lifetime, path, domain, secure) { - var d = false; + let d = false; if (lifetime) { d = new Date(); @@ -216,9 +215,9 @@ function delCookie(name, path, domain) { function getCookie(name) { - var dc = document.cookie; - var prefix = name + "="; - var begin = dc.indexOf("; " + prefix); + const dc = document.cookie; + const prefix = name + "="; + let begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; @@ -226,7 +225,7 @@ function getCookie(name) { else { begin += 2; } - var end = document.cookie.indexOf(";", begin); + let end = document.cookie.indexOf(";", begin); if (end == -1) { end = dc.length; } @@ -246,13 +245,13 @@ function gotoMain() { } function toggleSelectRowById(sender, id) { - var row = $(id); + const row = $(id); return toggleSelectRow(sender, row); } /* this is for dijit Checkbox */ function toggleSelectListRow2(sender) { - var row = sender.domNode.parentNode; + const row = sender.domNode.parentNode; return toggleSelectRow(sender, row); } @@ -301,7 +300,7 @@ function getURLParam(param){ } function closeInfoBox() { - var dialog = dijit.byId("infoBox"); + const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); @@ -313,7 +312,7 @@ function displayDlg(title, id, param, callback) { notify_progress("Loading, please wait...", true); - var query = "?op=dlg&method=" + + const query = "?op=dlg&method=" + param_escape(id) + "¶m=" + param_escape(param); new Ajax.Request("backend.php", { @@ -327,7 +326,7 @@ function displayDlg(title, id, param, callback) { } function infobox_callback2(transport, title) { - var dialog = false; + let dialog = false; if (dijit.byId("infoBox")) { dialog = dijit.byId("infoBox"); @@ -336,7 +335,7 @@ function infobox_callback2(transport, title) { //console.log("infobox_callback2"); notify(''); - var content = transport.responseText; + const content = transport.responseText; if (!dialog) { dialog = new dijit.Dialog({ @@ -390,7 +389,7 @@ function fatalError(code, msg, ext_info) { msg = ERRORS[code]; } - var content = "
Error code: " + code + "
" + + let content = "
Error code: " + code + "
" + "

" + msg + "

"; if (ext_info) { @@ -399,7 +398,7 @@ function fatalError(code, msg, ext_info) { ext_info + ""; } - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ title: "Fatal error", style: "width: 600px", content: content}); @@ -413,9 +412,9 @@ function fatalError(code, msg, ext_info) { } function filterDlgCheckAction(sender) { - var action = sender.value; + const action = sender.value; - var action_param = $("filterDlg_paramBox"); + const action_param = $("filterDlg_paramBox"); if (!action_param) { console.log("filterDlgCheckAction: can't find action param box!"); @@ -474,8 +473,8 @@ function strip_tags(s) { function hotkey_prefix_timeout() { - var date = new Date(); - var ts = Math.round(date.getTime() / 1000); + const date = new Date(); + const ts = Math.round(date.getTime() / 1000); if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { console.log("hotkey_prefix seems to be stuck, aborting"); @@ -509,7 +508,7 @@ function uploadIconHandler(rc) { function removeFeedIcon(id) { if (confirm(__("Remove stored feed icon?"))) { - var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); + const query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); console.log(query); @@ -531,23 +530,21 @@ function removeFeedIcon(id) { } function uploadFeedIcon() { - var file = $("icon_file"); + const file = $("icon_file"); if (file.value.length == 0) { alert(__("Please select an image file to upload.")); - } else { - if (confirm(__("Upload new icon for this feed?"))) { + } else if (confirm(__("Upload new icon for this feed?"))) { notify_progress("Uploading, please wait...", true); return true; } - } return false; } function addLabel(select, callback) { - var caption = prompt(__("Please enter label caption:"), ""); + const caption = prompt(__("Please enter label caption:"), ""); if (caption != undefined) { @@ -556,7 +553,7 @@ function addLabel(select, callback) { return false; } - var query = "?op=pref-labels&method=add&caption=" + + let query = "?op=pref-labels&method=add&caption=" + param_escape(caption); if (select) @@ -581,7 +578,7 @@ function addLabel(select, callback) { } function quickAddFeed() { - var query = "backend.php?op=feeds&method=quickAddFeed"; + const query = "backend.php?op=feeds&method=quickAddFeed"; // overlapping widgets if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); @@ -592,7 +589,7 @@ function quickAddFeed() { title: __("Subscribe to Feed"), style: "width: 600px", show_error: function(msg) { - var elem = $("fadd_error_message"); + const elem = $("fadd_error_message"); elem.innerHTML = msg; @@ -604,7 +601,7 @@ function quickAddFeed() { if (this.validate()) { console.log(dojo.objectToQuery(this.attr('value'))); - var feed_url = this.attr('value').feed; + const feed_url = this.attr('value').feed; Element.show("feed_add_spinner"); Element.hide("fadd_error_message"); @@ -623,7 +620,7 @@ function quickAddFeed() { return; } - var rc = reply['result']; + const rc = reply['result']; notify(''); Element.hide("feed_add_spinner"); @@ -656,7 +653,7 @@ function quickAddFeed() { select.addOption({value: '', label: __("Expand to select feed")}); var count = 0; - for (var feedUrl in feeds) { + for (const feedUrl in feeds) { select.addOption({value: feedUrl, label: feeds[feedUrl]}); count++; } @@ -692,11 +689,11 @@ function quickAddFeed() { } function createNewRuleElement(parentNode, replaceNode) { - var form = document.forms["filter_new_rule_form"]; + const form = document.forms["filter_new_rule_form"]; //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,""); - var query = "backend.php?op=pref-filters&method=printrulename&rule="+ + const query = "backend.php?op=pref-filters&method=printrulename&rule="+ param_escape(dojo.formToJson(form)); console.log(query); @@ -705,9 +702,9 @@ function createNewRuleElement(parentNode, replaceNode) { parameters: query, onComplete: function (transport) { try { - var li = dojo.create("li"); + const li = dojo.create("li"); - var cb = dojo.create("input", { type: "checkbox" }, li); + const cb = dojo.create("input", { type: "checkbox" }, li); new dijit.form.CheckBox({ onChange: function() { @@ -736,7 +733,7 @@ function createNewRuleElement(parentNode, replaceNode) { } function createNewActionElement(parentNode, replaceNode) { - var form = document.forms["filter_new_action_form"]; + const form = document.forms["filter_new_action_form"]; if (form.action_id.value == 7) { form.action_param.value = form.action_param_label.value; @@ -744,7 +741,7 @@ function createNewActionElement(parentNode, replaceNode) { form.action_param.value = form.action_param_plugin.value; } - var query = "backend.php?op=pref-filters&method=printactionname&action="+ + const query = "backend.php?op=pref-filters&method=printactionname&action="+ param_escape(dojo.formToJson(form)); console.log(query); @@ -753,9 +750,9 @@ function createNewActionElement(parentNode, replaceNode) { parameters: query, onComplete: function (transport) { try { - var li = dojo.create("li"); + const li = dojo.create("li"); - var cb = dojo.create("input", { type: "checkbox" }, li); + const cb = dojo.create("input", { type: "checkbox" }, li); new dijit.form.CheckBox({ onChange: function() { @@ -789,10 +786,10 @@ function addFilterRule(replaceNode, ruleStr) { if (dijit.byId("filterNewRuleDlg")) dijit.byId("filterNewRuleDlg").destroyRecursive(); - var query = "backend.php?op=pref-filters&method=newrule&rule=" + + const query = "backend.php?op=pref-filters&method=newrule&rule=" + param_escape(ruleStr); - var rule_dlg = new dijit.Dialog({ + const rule_dlg = new dijit.Dialog({ id: "filterNewRuleDlg", title: ruleStr ? __("Edit rule") : __("Add rule"), style: "width: 600px", @@ -811,10 +808,10 @@ function addFilterAction(replaceNode, actionStr) { if (dijit.byId("filterNewActionDlg")) dijit.byId("filterNewActionDlg").destroyRecursive(); - var query = "backend.php?op=pref-filters&method=newaction&action=" + + const query = "backend.php?op=pref-filters&method=newaction&action=" + param_escape(actionStr); - var rule_dlg = new dijit.Dialog({ + const rule_dlg = new dijit.Dialog({ id: "filterNewActionDlg", title: actionStr ? __("Edit action") : __("Add action"), style: "width: 600px", @@ -842,7 +839,7 @@ function editFilterTest(query) { limit: 100, max_offset: 10000, getTestResults: function(query, offset) { - var updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; + const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; console.log("getTestResults:" + offset); @@ -850,7 +847,7 @@ function editFilterTest(query) { parameters: updquery, onComplete: function (transport) { try { - var result = JSON.parse(transport.responseText); + const result = JSON.parse(transport.responseText); if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { test_dlg.results += result.size(); @@ -863,8 +860,8 @@ function editFilterTest(query) { console.log(offset + " " + test_dlg.max_offset); - for (var i = 0; i < result.size(); i++) { - var tmp = new Element("table"); + for (let i = 0; i < result.size(); i++) { + const tmp = new Element("table"); tmp.innerHTML = result[i]; dojo.parser.parse(tmp); @@ -920,7 +917,7 @@ function editFilterTest(query) { } function quickAddFilter() { - var query = ""; + let query = ""; if (!inPreferences()) { query = "backend.php?op=pref-filters&method=newfilter&feed=" + param_escape(getActiveFeedId()) + "&is_cat=" + @@ -942,7 +939,7 @@ function quickAddFilter() { title: __("Create Filter"), style: "width: 600px", test: function() { - var query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; + const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; editFilterTest(query); }, @@ -967,13 +964,13 @@ function quickAddFilter() { }); }, editRule: function(e) { - var li = e.parentNode; - var rule = li.getElementsByTagName("INPUT")[1].value; + const li = e.parentNode; + const rule = li.getElementsByTagName("INPUT")[1].value; addFilterRule(li, rule); }, editAction: function(e) { - var li = e.parentNode; - var action = li.getElementsByTagName("INPUT")[1].value; + const li = e.parentNode; + const action = li.getElementsByTagName("INPUT")[1].value; addFilterAction(li, action); }, addAction: function() { addFilterAction(); }, @@ -987,7 +984,7 @@ function quickAddFilter() { execute: function() { if (this.validate()) { - var query = dojo.formToQuery("filter_new_form"); + const query = dojo.formToQuery("filter_new_form"); console.log(query); @@ -1005,30 +1002,30 @@ function quickAddFilter() { href: query}); if (!inPreferences()) { - var selectedText = getSelectionText(); + const selectedText = getSelectionText(); var lh = dojo.connect(dialog, "onLoad", function(){ dojo.disconnect(lh); if (selectedText != "") { - var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : + const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : getActiveFeedId(); - var rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 }; + const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 }; addFilterRule(null, dojo.toJson(rule)); } else { - var query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId(); + const query = "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId(); new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); - var title = false; + let title = false; if (reply && reply.title) title = reply.title; @@ -1036,10 +1033,10 @@ function quickAddFilter() { console.log(title + " " + getActiveFeedId()); - var feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : + const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : getActiveFeedId(); - var rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 }; + const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 }; addFilterRule(null, dojo.toJson(rule)); } @@ -1057,12 +1054,12 @@ function quickAddFilter() { function unsubscribeFeed(feed_id, title) { - var msg = __("Unsubscribe from %s?").replace("%s", title); + const msg = __("Unsubscribe from %s?").replace("%s", title); if (title == undefined || confirm(msg)) { notify_progress("Removing feed..."); - var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id; + const query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id; new Ajax.Request("backend.php", { parameters: query, @@ -1095,14 +1092,14 @@ function backend_sanity_check_callback(transport) { return; } - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (!reply) { fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); return; } - var error_code = reply['error']['code']; + const error_code = reply['error']['code']; if (error_code && error_code != 0) { return fatalError(error_code, reply['error']['message']); @@ -1110,12 +1107,12 @@ function backend_sanity_check_callback(transport) { console.log("sanity check ok"); - var params = reply['init-params']; + const params = reply['init-params']; if (params) { console.log('reading init-params...'); - for (var k in params) { + for (const k in params) { console.log("IP: " + k + " => " + JSON.stringify(params[k])); if (k == "label_base_index") _label_base_index = parseInt(params[k]); } @@ -1133,22 +1130,22 @@ function backend_sanity_check_callback(transport) { } function genUrlChangeKey(feed, is_cat) { - var ok = confirm(__("Generate new syndication address for this feed?")); + const ok = confirm(__("Generate new syndication address for this feed?")); if (ok) { notify_progress("Trying to change address...", true); - var query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) + + const query = "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed) + "&is_cat=" + param_escape(is_cat); new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - var reply = JSON.parse(transport.responseText); - var new_link = reply.link; + const reply = JSON.parse(transport.responseText); + const new_link = reply.link; - var e = $('gen_feed_url'); + const e = $('gen_feed_url'); if (new_link) { @@ -1172,19 +1169,19 @@ function genUrlChangeKey(feed, is_cat) { // mode = all, none, invert function selectTableRows(id, mode) { - var rows = $(id).rows; + const rows = $(id).rows; - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; - var cb = false; - var dcb = false; + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + let cb = false; + let dcb = false; if (row.id && row.className) { - var bare_id = row.id.replace(/^[A-Z]*?-/, ""); - var inputs = rows[i].getElementsByTagName("input"); + const bare_id = row.id.replace(/^[A-Z]*?-/, ""); + const inputs = rows[i].getElementsByTagName("input"); - for (var j = 0; j < inputs.length; j++) { - var input = inputs[j]; + for (let j = 0; j < inputs.length; j++) { + const input = inputs[j]; if (input.getAttribute("type") == "checkbox" && input.id.match(bare_id)) { @@ -1196,7 +1193,7 @@ function selectTableRows(id, mode) { } if (cb || dcb) { - var issel = row.hasClassName("Selected"); + const issel = row.hasClassName("Selected"); if (mode == "all" && !issel) { row.addClassName("Selected"); @@ -1226,13 +1223,13 @@ function selectTableRows(id, mode) { } function getSelectedTableRowIds(id) { - var rows = []; + const rows = []; - var elem_rows = $(id).rows; + const elem_rows = $(id).rows; - for (var i = 0; i < elem_rows.length; i++) { + for (let i = 0; i < elem_rows.length; i++) { if (elem_rows[i].hasClassName("Selected")) { - var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); + const bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); rows.push(bare_id); } } @@ -1244,7 +1241,7 @@ function editFeed(feed) { if (feed <= 0) return alert(__("You can't edit this kind of feed.")); - var query = "backend.php?op=pref-feeds&method=editfeed&id=" + + const query = "backend.php?op=pref-feeds&method=editfeed&id=" + param_escape(feed); console.log(query); @@ -1280,7 +1277,7 @@ function editFeed(feed) { } function feedBrowser() { - var query = "backend.php?op=feeds&method=feedBrowser"; + const query = "backend.php?op=feeds&method=feedBrowser"; if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").hide(); @@ -1293,11 +1290,11 @@ function feedBrowser() { title: __("More Feeds"), style: "width: 600px", getSelectedFeedIds: function () { - var list = $$("#browseFeedList li[id*=FBROW]"); - var selected = new Array(); + const list = $$("#browseFeedList li[id*=FBROW]"); + const selected = new Array(); list.each(function (child) { - var id = child.id.replace("FBROW-", ""); + const id = child.id.replace("FBROW-", ""); if (child.hasClassName('Selected')) { selected.push(id); @@ -1307,12 +1304,12 @@ function feedBrowser() { return selected; }, getSelectedFeeds: function () { - var list = $$("#browseFeedList li.Selected"); - var selected = new Array(); + const list = $$("#browseFeedList li.Selected"); + const selected = new Array(); list.each(function (child) { - var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; - var url = child.getElementsBySelector("a.fb_feedUrl")[0].href; + const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; + const url = child.getElementsBySelector("a.fb_feedUrl")[0].href; selected.push([title, url]); @@ -1322,8 +1319,8 @@ function feedBrowser() { }, subscribe: function () { - var mode = this.attr('value').mode; - var selected = []; + const mode = this.attr('value').mode; + let selected = []; if (mode == "1") selected = this.getSelectedFeeds(); @@ -1338,7 +1335,7 @@ function feedBrowser() { // we use dojo.toJson instead of JSON.stringify because // it somehow escapes everything TWICE, at least in Chrome 9 - var query = "?op=rpc&method=massSubscribe&payload=" + + const query = "?op=rpc&method=massSubscribe&payload=" + param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); console.log(query); @@ -1357,7 +1354,7 @@ function feedBrowser() { }, update: function () { - var query = dojo.objectToQuery(dialog.attr('value')); + const query = dojo.objectToQuery(dialog.attr('value')); Element.show('feed_browser_spinner'); @@ -1368,12 +1365,12 @@ function feedBrowser() { Element.hide('feed_browser_spinner'); - var c = $("browseFeedList"); + const c = $("browseFeedList"); - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); - var r = reply['content']; - var mode = reply['mode']; + const r = reply['content']; + const mode = reply['mode']; if (c && r) { c.innerHTML = r; @@ -1391,18 +1388,18 @@ function feedBrowser() { }); }, removeFromArchive: function () { - var selected = this.getSelectedFeedIds(); + const selected = this.getSelectedFeedIds(); if (selected.length > 0) { - var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); + const pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed."); if (confirm(pr)) { Element.show('feed_browser_spinner'); - var query = "?op=rpc&method=remarchive&ids=" + + const query = "?op=rpc&method=remarchive&ids=" + param_escape(selected.toString()); - ; + new Ajax.Request("backend.php", { parameters: query, @@ -1425,7 +1422,7 @@ function feedBrowser() { } function showFeedsWithErrors() { - var query = "backend.php?op=pref-feeds&method=feedsWithErrors"; + const query = "backend.php?op=pref-feeds&method=feedsWithErrors"; if (dijit.byId("errorFeedsDlg")) dijit.byId("errorFeedsDlg").destroyRecursive(); @@ -1438,17 +1435,17 @@ function showFeedsWithErrors() { return getSelectedTableRowIds("prefErrorFeedList"); }, removeSelected: function() { - var sel_rows = this.getSelectedFeeds(); + const sel_rows = this.getSelectedFeeds(); console.log(sel_rows); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected feeds?")); + const ok = confirm(__("Remove selected feeds?")); if (ok) { notify_progress("Removing selected feeds...", true); - var query = "?op=pref-feeds&method=remove&ids="+ + const query = "?op=pref-feeds&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1474,17 +1471,17 @@ function showFeedsWithErrors() { } function get_timestamp() { - var date = new Date(); + const date = new Date(); return Math.round(date.getTime() / 1000); } function helpDialog(topic) { - var query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); + const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); if (dijit.byId("helpDlg")) dijit.byId("helpDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "helpDlg", title: __("Help"), style: "width: 600px", @@ -1514,14 +1511,14 @@ function htmlspecialchars_decode (string, quote_style) { // * returns 1: '

this -> "

' // * example 2: htmlspecialchars_decode("&quot;"); // * returns 2: '"' - var optTemp = 0, + let optTemp = 0, i = 0, noquotes = false; if (typeof quote_style === 'undefined') { quote_style = 2; } string = string.toString().replace(/</g, '<').replace(/>/g, '>'); - var OPTS = { + const OPTS = { 'ENT_NOQUOTES': 0, 'ENT_HTML_QUOTE_SINGLE': 1, 'ENT_HTML_QUOTE_DOUBLE': 2, @@ -1569,13 +1566,13 @@ function feed_to_label_id(feed) { // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac function getSelectionText() { - var text = ""; + let text = ""; if (typeof window.getSelection != "undefined") { - var sel = window.getSelection(); + const sel = window.getSelection(); if (sel.rangeCount) { - var container = document.createElement("div"); - for (var i = 0, len = sel.rangeCount; i < len; ++i) { + const container = document.createElement("div"); + for (let i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); } text = container.innerHTML; @@ -1590,13 +1587,13 @@ function getSelectionText() { } function openUrlPopup(url) { - var w = window.open(""); + const w = window.open(""); w.opener = null; w.location = url; } function openArticlePopup(id) { - var w = window.open("", + const w = window.open("", "ttrss_article_popup", "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no"); diff --git a/js/prefs.js b/js/prefs.js index c2190280..e67d80df 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -11,8 +11,8 @@ function notify_callback2(transport, sticky) { function updateFeedList() { - var user_search = $("feed_search"); - var search = ""; + const user_search = $("feed_search"); + let search = ""; if (user_search) { search = user_search.value; } new Ajax.Request("backend.php", { @@ -36,14 +36,14 @@ function checkInactiveFeeds() { } function updateUsersList(sort_key) { - var user_search = $("user_search"); - var search = ""; + const user_search = $("user_search"); + let search = ""; if (user_search) { search = user_search.value; } - var query = "?op=pref-users&sort=" - + param_escape(sort_key) + + const query = "?op=pref-users&sort=" + + param_escape(sort_key) + "&search=" + param_escape(search); new Ajax.Request("backend.php", { @@ -57,7 +57,7 @@ function updateUsersList(sort_key) { } function addUser() { - var login = prompt(__("Please enter login:"), ""); + const login = prompt(__("Please enter login:"), ""); if (login == null) { return false; @@ -70,7 +70,7 @@ function addUser() { notify_progress("Adding user..."); - var query = "?op=pref-users&method=add&login=" + + const query = "?op=pref-users&method=add&login=" + param_escape(login); new Ajax.Request("backend.php", { @@ -85,7 +85,7 @@ function addUser() { function editUser(id) { - var query = "backend.php?op=pref-users&method=edit&id=" + + const query = "backend.php?op=pref-users&method=edit&id=" + param_escape(id); if (dijit.byId("userEditDlg")) @@ -99,7 +99,7 @@ function editUser(id) { if (this.validate()) { notify_progress("Saving data...", true); - var query = dojo.formToQuery("user_edit_form"); + const query = dojo.formToQuery("user_edit_form"); new Ajax.Request("backend.php", { parameters: query, @@ -118,7 +118,7 @@ function editUser(id) { function editFilter(id) { - var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); + const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").destroyRecursive(); @@ -132,7 +132,7 @@ function editFilter(id) { style: "width: 600px", test: function () { - var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; + const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; editFilterTest(query); }, @@ -157,26 +157,26 @@ function editFilter(id) { }); }, editRule: function (e) { - var li = e.parentNode; - var rule = li.getElementsByTagName("INPUT")[1].value; + const li = e.parentNode; + const rule = li.getElementsByTagName("INPUT")[1].value; addFilterRule(li, rule); }, editAction: function (e) { - var li = e.parentNode; - var action = li.getElementsByTagName("INPUT")[1].value; + const li = e.parentNode; + const action = li.getElementsByTagName("INPUT")[1].value; addFilterAction(li, action); }, removeFilter: function () { - var msg = __("Remove filter?"); + const msg = __("Remove filter?"); if (confirm(msg)) { this.hide(); notify_progress("Removing filter..."); - var id = this.attr('value').id; + const id = this.attr('value').id; - var query = "?op=pref-filters&method=remove&ids=" + + const query = "?op=pref-filters&method=remove&ids=" + param_escape(id); new Ajax.Request("backend.php", { @@ -208,7 +208,7 @@ function editFilter(id) { notify_progress("Saving data...", true); - var query = dojo.formToQuery("filter_edit_form"); + const query = dojo.formToQuery("filter_edit_form"); console.log(query); @@ -229,9 +229,9 @@ function editFilter(id) { function getSelectedLabels() { - var tree = dijit.byId("labelTree"); - var items = tree.model.getCheckedItems(); - var rv = []; + const tree = dijit.byId("labelTree"); + const items = tree.model.getCheckedItems(); + const rv = []; items.each(function(item) { rv.push(tree.model.store.getValue(item, 'bare_id')); @@ -245,9 +245,9 @@ function getSelectedUsers() { } function getSelectedFeeds() { - var tree = dijit.byId("feedTree"); - var items = tree.model.getCheckedItems(); - var rv = []; + const tree = dijit.byId("feedTree"); + const items = tree.model.getCheckedItems(); + const rv = []; items.each(function(item) { if (item.id[0].match("FEED:")) @@ -258,9 +258,9 @@ function getSelectedFeeds() { } function getSelectedCategories() { - var tree = dijit.byId("feedTree"); - var items = tree.model.getCheckedItems(); - var rv = []; + const tree = dijit.byId("feedTree"); + const items = tree.model.getCheckedItems(); + const rv = []; items.each(function(item) { if (item.id[0].match("CAT:")) @@ -271,9 +271,9 @@ function getSelectedCategories() { } function getSelectedFilters() { - var tree = dijit.byId("filterTree"); - var items = tree.model.getCheckedItems(); - var rv = []; + const tree = dijit.byId("filterTree"); + const items = tree.model.getCheckedItems(); + const rv = []; items.each(function(item) { rv.push(tree.model.store.getValue(item, 'bare_id')); @@ -285,16 +285,16 @@ function getSelectedFilters() { function removeSelectedLabels() { - var sel_rows = getSelectedLabels(); + const sel_rows = getSelectedLabels(); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected labels?")); + const ok = confirm(__("Remove selected labels?")); if (ok) { notify_progress("Removing selected labels..."); - var query = "?op=pref-labels&method=remove&ids="+ + const query = "?op=pref-labels&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -313,16 +313,16 @@ function removeSelectedLabels() { function removeSelectedUsers() { - var sel_rows = getSelectedUsers(); + const sel_rows = getSelectedUsers(); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed.")); + const ok = confirm(__("Remove selected users? Neither default admin nor your account will be removed.")); if (ok) { notify_progress("Removing selected users..."); - var query = "?op=pref-users&method=remove&ids=" + + const query = "?op=pref-users&method=remove&ids=" + param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -343,16 +343,16 @@ function removeSelectedUsers() { function removeSelectedFilters() { - var sel_rows = getSelectedFilters(); + const sel_rows = getSelectedFilters(); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected filters?")); + const ok = confirm(__("Remove selected filters?")); if (ok) { notify_progress("Removing selected filters..."); - var query = "?op=pref-filters&method=remove&ids=" + + const query = "?op=pref-filters&method=remove&ids=" + param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -371,17 +371,17 @@ function removeSelectedFilters() { function removeSelectedFeeds() { - var sel_rows = getSelectedFeeds(); + const sel_rows = getSelectedFeeds(); if (sel_rows.length > 0) { - var ok = confirm(__("Unsubscribe from selected feeds?")); + const ok = confirm(__("Unsubscribe from selected feeds?")); if (ok) { notify_progress("Unsubscribing from selected feeds...", true); - var query = "?op=pref-feeds&method=remove&ids=" + + const query = "?op=pref-feeds&method=remove&ids=" + param_escape(sel_rows.toString()); console.log(query); @@ -402,7 +402,7 @@ function removeSelectedFeeds() { } function editSelectedUser() { - var rows = getSelectedUsers(); + const rows = getSelectedUsers(); if (rows.length == 0) { alert(__("No users are selected.")); @@ -421,7 +421,7 @@ function editSelectedUser() { function resetSelectedUserPass() { - var rows = getSelectedUsers(); + const rows = getSelectedUsers(); if (rows.length == 0) { alert(__("No users are selected.")); @@ -433,14 +433,14 @@ function resetSelectedUserPass() { return; } - var ok = confirm(__("Reset password of selected user?")); + const ok = confirm(__("Reset password of selected user?")); if (ok) { notify_progress("Resetting password for selected user..."); - var id = rows[0]; + const id = rows[0]; - var query = "?op=pref-users&method=resetPass&id=" + + const query = "?op=pref-users&method=resetPass&id=" + param_escape(id); new Ajax.Request("backend.php", { @@ -455,7 +455,7 @@ function resetSelectedUserPass() { function selectedUserDetails() { - var rows = getSelectedUsers(); + const rows = getSelectedUsers(); if (rows.length == 0) { alert(__("No users are selected.")); @@ -467,9 +467,9 @@ function selectedUserDetails() { return; } - var id = rows[0]; + const id = rows[0]; - var query = "backend.php?op=pref-users&method=userdetails&id=" + id; + const query = "backend.php?op=pref-users&method=userdetails&id=" + id; if (dijit.byId("userDetailsDlg")) dijit.byId("userDetailsDlg").destroyRecursive(); @@ -489,7 +489,7 @@ function selectedUserDetails() { function editSelectedFilter() { - var rows = getSelectedFilters(); + const rows = getSelectedFilters(); if (rows.length == 0) { alert(__("No filters are selected.")); @@ -508,19 +508,19 @@ function editSelectedFilter() { } function joinSelectedFilters() { - var rows = getSelectedFilters(); + const rows = getSelectedFilters(); if (rows.length == 0) { alert(__("No filters are selected.")); return; } - var ok = confirm(__("Combine selected filters?")); + const ok = confirm(__("Combine selected filters?")); if (ok) { notify_progress("Joining filters..."); - var query = "?op=pref-filters&method=join&ids="+ + const query = "?op=pref-filters&method=join&ids="+ param_escape(rows.toString()); console.log(query); @@ -534,7 +534,7 @@ function joinSelectedFilters() { } function editSelectedFeed() { - var rows = getSelectedFeeds(); + const rows = getSelectedFeeds(); if (rows.length == 0) { alert(__("No feeds are selected.")); @@ -552,7 +552,7 @@ function editSelectedFeed() { } function editSelectedFeeds() { - var rows = getSelectedFeeds(); + const rows = getSelectedFeeds(); if (rows.length == 0) { alert(__("No feeds are selected.")); @@ -561,7 +561,7 @@ function editSelectedFeeds() { notify_progress("Loading, please wait..."); - var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" + + const query = "backend.php?op=pref-feeds&method=editfeeds&ids=" + param_escape(rows.toString()); console.log(query); @@ -580,7 +580,7 @@ function editSelectedFeeds() { title: __("Edit Multiple Feeds"), style: "width: 600px", getChildByName: function (name) { - var rv = null; + let rv = null; this.getChildren().each( function (child) { if (child.name == name) { @@ -602,7 +602,7 @@ function editSelectedFeeds() { }, execute: function () { if (this.validate() && confirm(__("Save changes to selected feeds?"))) { - var query = dojo.objectToQuery(this.attr('value')); + let query = dojo.objectToQuery(this.attr('value')); /* Form.serialize ignores unchecked checkboxes */ @@ -674,9 +674,9 @@ function opmlImportComplete(iframe) { if (dijit.byId('opmlImportDlg')) dijit.byId('opmlImportDlg').destroyRecursive(); - var content = iframe.contentDocument.body.innerHTML; + const content = iframe.contentDocument.body.innerHTML; - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "opmlImportDlg", title: __("OPML Import"), style: "width: 600px", @@ -694,7 +694,7 @@ function opmlImportComplete(iframe) { function opmlImport() { - var opml_file = $("opml_file"); + const opml_file = $("opml_file"); if (opml_file.value.length == 0) { alert(__("Please choose an OPML file first.")); @@ -710,8 +710,8 @@ function opmlImport() { function updateFilterList() { - var user_search = $("filter_search"); - var search = ""; + const user_search = $("filter_search"); + let search = ""; if (user_search) { search = user_search.value; } new Ajax.Request("backend.php", { @@ -767,7 +767,7 @@ function selectTab(id, noupdate) { updateSystemList(); } - var tab = dijit.byId(id + "Tab"); + const tab = dijit.byId(id + "Tab"); dijit.byId("pref-tabs").selectChild(tab); } @@ -778,17 +778,17 @@ function init_second_stage() { loading_set_progress(50); notify(""); - var tab = getURLParam('tab'); + let tab = getURLParam('tab'); if (tab) { tab = dijit.byId(tab + "Tab"); if (tab) dijit.byId("pref-tabs").selectChild(tab); } - var method = getURLParam('method'); + const method = getURLParam('method'); if (method == 'editFeed') { - var param = getURLParam('methodparam'); + const param = getURLParam('methodparam'); window.setTimeout(function() { editFeed(param) }, 100); } @@ -846,7 +846,7 @@ function init() { loading_set_progress(50); - var clientTzOffset = new Date().getTimezoneOffset() * 60; + const clientTzOffset = new Date().getTimezoneOffset() * 60; new Ajax.Request("backend.php", { parameters: { @@ -866,11 +866,11 @@ function init() { function validatePrefsReset() { - var ok = confirm(__("Reset to defaults?")); + const ok = confirm(__("Reset to defaults?")); if (ok) { - var query = "?op=pref-prefs&method=resetconfig"; + const query = "?op=pref-prefs&method=resetconfig"; console.log(query); new Ajax.Request("backend.php", { @@ -890,10 +890,10 @@ function pref_hotkey_handler(e) { if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; - var keycode = false; - var shift_key = false; + let keycode = false; + let shift_key = false; - var cmdline = $('cmdline'); + const cmdline = $('cmdline'); try { shift_key = e.shiftKey; @@ -907,7 +907,7 @@ function pref_hotkey_handler(e) { keycode = e.which; } - var keychar = String.fromCharCode(keycode); + let keychar = String.fromCharCode(keycode); if (keycode == 27) { // escape hotkey_prefix = false; @@ -922,8 +922,8 @@ function pref_hotkey_handler(e) { if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) { - var date = new Date(); - var ts = Math.round(date.getTime() / 1000); + const date = new Date(); + const ts = Math.round(date.getTime() / 1000); hotkey_prefix = keychar; hotkey_prefix_pressed = ts; @@ -936,14 +936,14 @@ function pref_hotkey_handler(e) { Element.hide(cmdline); - var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; + let hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey; hotkey_prefix = false; - var hotkey_action = false; + let hotkey_action = false; var hotkeys = getInitParam("hotkeys"); - for (var sequence in hotkeys[1]) { + for (const sequence in hotkeys[1]) { if (sequence == hotkey) { hotkey_action = hotkeys[1][sequence]; break; @@ -970,10 +970,10 @@ function pref_hotkey_handler(e) { function removeCategory(id, item) { - var ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name)); + const ok = confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name)); if (ok) { - var query = "?op=pref-feeds&method=removeCat&ids=" + + const query = "?op=pref-feeds&method=removeCat&ids=" + param_escape(id); notify_progress("Removing category..."); @@ -990,16 +990,16 @@ function removeCategory(id, item) { function removeSelectedCategories() { - var sel_rows = getSelectedCategories(); + const sel_rows = getSelectedCategories(); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected categories?")); + const ok = confirm(__("Remove selected categories?")); if (ok) { notify_progress("Removing selected categories..."); - var query = "?op=pref-feeds&method=removeCat&ids="+ + const query = "?op=pref-feeds&method=removeCat&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1017,13 +1017,13 @@ function removeSelectedCategories() { } function createCategory() { - var title = prompt(__("Category title:")); + const title = prompt(__("Category title:")); if (title) { notify_progress("Creating category..."); - var query = "?op=pref-feeds&method=addCat&cat=" + + const query = "?op=pref-feeds&method=addCat&cat=" + param_escape(title); new Ajax.Request("backend.php", { @@ -1037,7 +1037,7 @@ function createCategory() { } function showInactiveFeeds() { - var query = "backend.php?op=pref-feeds&method=inactiveFeeds"; + const query = "backend.php?op=pref-feeds&method=inactiveFeeds"; if (dijit.byId("inactiveFeedsDlg")) dijit.byId("inactiveFeedsDlg").destroyRecursive(); @@ -1050,17 +1050,17 @@ function showInactiveFeeds() { return getSelectedTableRowIds("prefInactiveFeedList"); }, removeSelected: function () { - var sel_rows = this.getSelectedFeeds(); + const sel_rows = this.getSelectedFeeds(); console.log(sel_rows); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected feeds?")); + const ok = confirm(__("Remove selected feeds?")); if (ok) { notify_progress("Removing selected feeds...", true); - var query = "?op=pref-feeds&method=remove&ids=" + + const query = "?op=pref-feeds&method=remove&ids=" + param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1088,22 +1088,22 @@ function showInactiveFeeds() { } function opmlRegenKey() { - var ok = confirm(__("Replace current OPML publishing address with a new one?")); + const ok = confirm(__("Replace current OPML publishing address with a new one?")); if (ok) { notify_progress("Trying to change address...", true); - var query = "?op=pref-feeds&method=regenOPMLKey"; + const query = "?op=pref-feeds&method=regenOPMLKey"; new Ajax.Request("backend.php", { parameters: query, onComplete: function (transport) { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); - var new_link = reply.link; + const new_link = reply.link; - var e = $('pub_opml_url'); + const e = $('pub_opml_url'); if (new_link) { e.href = new_link; @@ -1123,13 +1123,13 @@ function opmlRegenKey() { } function labelColorReset() { - var labels = getSelectedLabels(); + const labels = getSelectedLabels(); if (labels.length > 0) { - var ok = confirm(__("Reset selected labels to default colors?")); + const ok = confirm(__("Reset selected labels to default colors?")); if (ok) { - var query = "?op=pref-labels&method=colorreset&ids=" + + const query = "?op=pref-labels&method=colorreset&ids=" + param_escape(labels.toString()); new Ajax.Request("backend.php", { @@ -1154,7 +1154,7 @@ function editProfiles() { if (dijit.byId("profileEditDlg")) dijit.byId("profileEditDlg").destroyRecursive(); - var query = "backend.php?op=pref-prefs&method=editPrefProfiles"; + const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; var dialog = new dijit.Dialog({ id: "profileEditDlg", @@ -1164,15 +1164,15 @@ function editProfiles() { return getSelectedTableRowIds("prefFeedProfileList"); }, removeSelected: function () { - var sel_rows = this.getSelectedProfiles(); + const sel_rows = this.getSelectedProfiles(); if (sel_rows.length > 0) { - var ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed.")); + const ok = confirm(__("Remove selected profiles? Active and default profiles will not be removed.")); if (ok) { notify_progress("Removing selected profiles...", true); - var query = "?op=rpc&method=remprofiles&ids=" + + const query = "?op=rpc&method=remprofiles&ids=" + param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1190,16 +1190,16 @@ function editProfiles() { } }, activateProfile: function () { - var sel_rows = this.getSelectedProfiles(); + const sel_rows = this.getSelectedProfiles(); if (sel_rows.length == 1) { - var ok = confirm(__("Activate selected profile?")); + const ok = confirm(__("Activate selected profile?")); if (ok) { notify_progress("Loading, please wait..."); - var query = "?op=rpc&method=setprofile&id=" + + const query = "?op=rpc&method=setprofile&id=" + param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1218,7 +1218,7 @@ function editProfiles() { if (this.validate()) { notify_progress("Creating profile...", true); - var query = "?op=rpc&method=addprofile&title=" + + const query = "?op=rpc&method=addprofile&title=" + param_escape(dialog.attr('value').newprofile); new Ajax.Request("backend.php", { @@ -1243,16 +1243,16 @@ function editProfiles() { function activatePrefProfile() { - var sel_rows = getSelectedFeedCats(); + const sel_rows = getSelectedFeedCats(); if (sel_rows.length == 1) { - var ok = confirm(__("Activate selected profile?")); + const ok = confirm(__("Activate selected profile?")); if (ok) { notify_progress("Loading, please wait..."); - var query = "?op=rpc&method=setprofile&id="+ + const query = "?op=rpc&method=setprofile&id="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1271,12 +1271,12 @@ function activatePrefProfile() { function clearFeedAccessKeys() { - var ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?")); + const ok = confirm(__("This will invalidate all previously generated feed URLs. Continue?")); if (ok) { notify_progress("Clearing URLs..."); - var query = "?op=pref-feeds&method=clearKeys"; + const query = "?op=pref-feeds&method=clearKeys"; new Ajax.Request("backend.php", { parameters: query, @@ -1300,7 +1300,6 @@ function resetFilterOrder() { } - function resetFeedOrder() { notify_progress("Loading, please wait..."); @@ -1324,7 +1323,7 @@ function resetCatOrder() { } function editCat(id, item) { - var new_name = prompt(__('Rename category to:'), item.name); + const new_name = prompt(__('Rename category to:'), item.name); if (new_name && new_name != item.name) { @@ -1345,20 +1344,20 @@ function editCat(id, item) { } function editLabel(id) { - var query = "backend.php?op=pref-labels&method=edit&id=" + + const query = "backend.php?op=pref-labels&method=edit&id=" + param_escape(id); if (dijit.byId("labelEditDlg")) dijit.byId("labelEditDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "labelEditDlg", title: __("Label Editor"), style: "width: 600px", setLabelColor: function (id, fg, bg) { - var kind = ''; - var color = ''; + let kind = ''; + let color = ''; if (fg && bg) { kind = 'both'; @@ -1370,13 +1369,13 @@ function editLabel(id) { color = bg; } - var query = "?op=pref-labels&method=colorset&kind=" + kind + + const query = "?op=pref-labels&method=colorset&kind=" + kind + "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) + "&bg=" + param_escape(bg) + "&color=" + param_escape(color); // console.log(query); - var e = $("LICID-" + id); + const e = $("LICID-" + id); if (e) { if (fg) e.style.color = fg; @@ -1389,10 +1388,10 @@ function editLabel(id) { }, execute: function () { if (this.validate()) { - var caption = this.attr('value').caption; - var fg_color = this.attr('value').fg_color; - var bg_color = this.attr('value').bg_color; - var query = dojo.objectToQuery(this.attr('value')); + const caption = this.attr('value').caption; + const fg_color = this.attr('value').fg_color; + const bg_color = this.attr('value').bg_color; + const query = dojo.objectToQuery(this.attr('value')); dijit.byId('labelTree').setNameById(id, caption); this.setLabelColor(id, fg_color, bg_color); @@ -1414,12 +1413,12 @@ function editLabel(id) { function customizeCSS() { - var query = "backend.php?op=pref-prefs&method=customizeCSS"; + const query = "backend.php?op=pref-prefs&method=customizeCSS"; if (dijit.byId("cssEditDlg")) dijit.byId("cssEditDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "cssEditDlg", title: __("Customize stylesheet"), style: "width: 600px", @@ -1445,13 +1444,13 @@ function insertSSLserial(value) { } function gotoExportOpml(filename, settings) { - var tmp = settings ? 1 : 0; + const tmp = settings ? 1 : 0; document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; } function batchSubscribe() { - var query = "backend.php?op=pref-feeds&method=batchSubscribe"; + const query = "backend.php?op=pref-feeds&method=batchSubscribe"; // overlapping widgets if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); @@ -1501,7 +1500,7 @@ function clearSqlLog() { if (confirm(__("Clear all messages in the error log?"))) { notify_progress("Loading, please wait..."); - var query = "?op=pref-system&method=clearLog"; + const query = "?op=pref-system&method=clearLog"; new Ajax.Request("backend.php", { parameters: query, diff --git a/js/tt-rss.js b/js/tt-rss.js index 3f65a2ce..872407e7 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -50,11 +50,11 @@ function updateFeedList() { dijit.byId("feedTree").destroyRecursive(); } - var store = new dojo.data.ItemFileWriteStore({ + const store = new dojo.data.ItemFileWriteStore({ url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2" }); - var treeModel = new fox.FeedStoreModel({ + const treeModel = new fox.FeedStoreModel({ store: store, query: { "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed" @@ -64,12 +64,12 @@ function updateFeedList() { childrenAttrs: ["items"] }); - var tree = new fox.FeedTree({ + const tree = new fox.FeedTree({ model: treeModel, onClick: function (item, node) { - var id = String(item.id); - var is_cat = id.match("^CAT:"); - var feed = id.substr(id.indexOf(":") + 1); + const id = String(item.id); + const is_cat = id.match("^CAT:"); + const feed = id.substr(id.indexOf(":") + 1); viewfeed({feed: feed, is_cat: is_cat}); return false; }, @@ -115,11 +115,11 @@ function updateFeedList() { function catchupAllFeeds() { - var str = __("Mark all articles as read?"); + const str = __("Mark all articles as read?"); if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - var query_str = "backend.php?op=feeds&method=catchupAll"; + const query_str = "backend.php?op=feeds&method=catchupAll"; notify_progress("Marking all feeds as read..."); @@ -154,13 +154,13 @@ function timeout() { } function search() { - var query = "backend.php?op=feeds&method=search¶m=" + + const query = "backend.php?op=feeds&method=search¶m=" + param_escape(getActiveFeedId() + ":" + activeFeedIsCat()); if (dijit.byId("searchDlg")) dijit.byId("searchDlg").destroyRecursive(); - var dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "searchDlg", title: __("Search"), style: "width: 600px", @@ -177,20 +177,12 @@ function search() { } function updateTitle() { - var tmp = "Tiny Tiny RSS"; + let tmp = "Tiny Tiny RSS"; if (global_unread > 0) { tmp = "(" + global_unread + ") " + tmp; } - if (window.fluid) { - if (global_unread > 0) { - window.fluid.dockBadge = global_unread; - } else { - window.fluid.dockBadge = ""; - } - } - document.title = tmp; } @@ -258,12 +250,12 @@ function init() { loading_set_progress(30); - var a = document.createElement('audio'); + const a = document.createElement('audio'); - var hasAudio = !!a.canPlayType; - var hasSandbox = "sandbox" in document.createElement("iframe"); - var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); - var clientTzOffset = new Date().getTimezoneOffset() * 60; + const hasAudio = !!a.canPlayType; + const hasSandbox = "sandbox" in document.createElement("iframe"); + const hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); + const clientTzOffset = new Date().getTimezoneOffset() * 60; init_hotkey_actions(); @@ -290,13 +282,13 @@ function init() { function init_hotkey_actions() { hotkey_actions["next_feed"] = function() { - var rv = dijit.byId("feedTree").getNextFeed( + const rv = dijit.byId("feedTree").getNextFeed( getActiveFeedId(), activeFeedIsCat()); if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) }; hotkey_actions["prev_feed"] = function() { - var rv = dijit.byId("feedTree").getPreviousFeed( + const rv = dijit.byId("feedTree").getPreviousFeed( getActiveFeedId(), activeFeedIsCat()); if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) @@ -320,8 +312,8 @@ function init_hotkey_actions() { moveToPost('prev', true, true); }; hotkey_actions["collapse_article"] = function() { - var id = getActiveArticleId(); - var elem = $("CICD-"+id); + const id = getActiveArticleId(); + const elem = $("CICD-"+id); if (elem) { if (elem.visible()) { @@ -333,8 +325,8 @@ function init_hotkey_actions() { } }; hotkey_actions["toggle_expand"] = function() { - var id = getActiveArticleId(); - var elem = $("CICD-"+id); + const id = getActiveArticleId(); + const elem = $("CICD-"+id); if (elem) { if (elem.visible()) { @@ -358,10 +350,10 @@ function init_hotkey_actions() { selectionToggleUnread(undefined, false, true); }; hotkey_actions["edit_tags"] = function() { - var id = getActiveArticleId(); + const id = getActiveArticleId(); if (id) { editArticleTags(id); - }; + } } hotkey_actions["open_in_new_window"] = function() { if (getActiveArticleId()) { @@ -457,7 +449,7 @@ function init_hotkey_actions() { reverseHeadlineOrder(); }; hotkey_actions["feed_toggle_vgroup"] = function() { - var query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; + const query_str = "?op=rpc&method=togglepref&key=VFEED_GROUP_BY_FEED"; new Ajax.Request("backend.php", { parameters: query_str, @@ -494,12 +486,12 @@ function init_hotkey_actions() { gotoPreferences(); }; hotkey_actions["select_article_cursor"] = function() { - var id = getArticleUnderPointer(); + const id = getArticleUnderPointer(); if (id) { - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (row) { - var cb = dijit.getEnclosingWidget( + const cb = dijit.getEnclosingWidget( row.getElementsByClassName("rchk")[0]); if (cb) { @@ -546,8 +538,8 @@ function init_hotkey_actions() { hotkey_actions["toggle_combined_mode"] = function() { notify_progress("Loading, please wait..."); - var value = isCdmMode() ? "false" : "true"; - var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value; + const value = isCdmMode() ? "false" : "true"; + const query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value; new Ajax.Request("backend.php", { parameters: query, @@ -563,8 +555,8 @@ function init_hotkey_actions() { hotkey_actions["toggle_cdm_expanded"] = function() { notify_progress("Loading, please wait..."); - var value = getInitParam("cdm_expanded") ? "false" : "true"; - var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value; + const value = getInitParam("cdm_expanded") ? "false" : "true"; + const query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value; new Ajax.Request("backend.php", { parameters: query, @@ -603,7 +595,7 @@ function init_second_stage() { delCookie("ttrss_test"); - var toolbar = document.forms["main_toolbar_form"]; + const toolbar = document.forms["main_toolbar_form"]; dijit.getEnclosingWidget(toolbar.view_mode).attr('value', getInitParam("default_view_mode")); @@ -611,10 +603,10 @@ function init_second_stage() { dijit.getEnclosingWidget(toolbar.order_by).attr('value', getInitParam("default_view_order_by")); - var feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; + const feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; - var hash_feed_id = hash_get('f'); - var hash_feed_is_cat = hash_get('c') == "1"; + const hash_feed_id = hash_get('f'); + const hash_feed_is_cat = hash_get('c') == "1"; if (hash_feed_id != undefined) { setActiveFeedId(hash_feed_id, hash_feed_is_cat); @@ -626,11 +618,11 @@ function init_second_stage() { if ('sessionStorage' in window && window['sessionStorage'] !== null) sessionStorage.clear(); - var hotkeys = getInitParam("hotkeys"); - var tmp = []; + const hotkeys = getInitParam("hotkeys"); + const tmp = []; - for (var sequence in hotkeys[1]) { - var filtered = sequence.replace(/\|.*$/, ""); + for (const sequence in hotkeys[1]) { + const filtered = sequence.replace(/\|.*$/, ""); tmp[filtered] = hotkeys[1][sequence]; } @@ -733,11 +725,11 @@ function quickMenuGo(opid) { function toggleDispRead() { - var hide = !(getInitParam("hide_read_feeds") == "1"); + const hide = !(getInitParam("hide_read_feeds") == "1"); hideOrShowFeeds(hide); - var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" + + const query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" + param_escape(hide); setInitParam("hide_read_feeds", hide); @@ -753,8 +745,8 @@ function parse_runtime_info(data) { //console.log("parsing runtime info..."); - for (var k in data) { - var v = data[k]; + for (const k in data) { + const v = data[k]; // console.log("RI: " + k + " => " + v); @@ -770,7 +762,7 @@ function parse_runtime_info(data) { } if (k == "update_result") { - var updatesIcon = dijit.byId("updatesIcon").domNode; + const updatesIcon = dijit.byId("updatesIcon").domNode; if (v) { Element.show(updatesIcon); @@ -801,7 +793,7 @@ function parse_runtime_info(data) { function collapse_feedlist() { Element.toggle("feeds-holder"); - var splitter = $("feeds-holder_splitter"); + const splitter = $("feeds-holder_splitter"); Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); @@ -815,7 +807,7 @@ function viewModeChanged() { function rescoreCurrentFeed() { - var actid = getActiveFeedId(); + const actid = getActiveFeedId(); if (activeFeedIsCat() || actid < 0) { alert(__("You can't rescore this kind of feed.")); @@ -827,13 +819,13 @@ function rescoreCurrentFeed() { return; } - var fn = getFeedName(actid); - var pr = __("Rescore articles in %s?").replace("%s", fn); + const fn = getFeedName(actid); + const pr = __("Rescore articles in %s?").replace("%s", fn); if (confirm(pr)) { notify_progress("Rescoring articles..."); - var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid; + const query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid; new Ajax.Request("backend.php", { parameters: query, @@ -847,9 +839,9 @@ function hotkey_handler(e) { if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; - var keycode = false; + let keycode = false; - var cmdline = $('cmdline'); + const cmdline = $('cmdline'); if (window.event) { keycode = window.event.keyCode; @@ -865,12 +857,12 @@ function hotkey_handler(e) { if (keycode == 17) return; // ignore lone ctrl var hotkeys = getInitParam("hotkeys"); - var keychar = String.fromCharCode(keycode).toLowerCase(); + const keychar = String.fromCharCode(keycode).toLowerCase(); if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) { - var date = new Date(); - var ts = Math.round(date.getTime() / 1000); + const date = new Date(); + const ts = Math.round(date.getTime() / 1000); hotkey_prefix = keychar; hotkey_prefix_pressed = ts; @@ -886,7 +878,7 @@ function hotkey_handler(e) { Element.hide(cmdline); - var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; + let hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; // ensure ^*char notation if (e.shiftKey) hotkey = "*" + hotkey; @@ -897,17 +889,17 @@ function hotkey_handler(e) { hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey; hotkey_prefix = false; - var hotkey_action = false; + let hotkey_action = false; var hotkeys = getInitParam("hotkeys"); - for (var sequence in hotkeys[1]) { + for (const sequence in hotkeys[1]) { if (sequence == hotkey) { hotkey_action = hotkeys[1][sequence]; break; } } - var action = hotkey_actions[hotkey_action]; + const action = hotkey_actions[hotkey_action]; if (action != null) { action(); @@ -922,10 +914,10 @@ function inPreferences() { function reverseHeadlineOrder() { - var toolbar = document.forms["main_toolbar_form"]; - var order_by = dijit.getEnclosingWidget(toolbar.order_by); + const toolbar = document.forms["main_toolbar_form"]; + const order_by = dijit.getEnclosingWidget(toolbar.order_by); - var value = order_by.attr('value'); + let value = order_by.attr('value'); if (value == "date_reverse") value = "default"; @@ -940,21 +932,21 @@ function reverseHeadlineOrder() { function handle_rpc_json(transport, scheduled_call) { - var netalert_dijit = dijit.byId("net-alert"); - var netalert = false; + const netalert_dijit = dijit.byId("net-alert"); + let netalert = false; if (netalert_dijit) netalert = netalert_dijit.domNode; try { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (reply) { - var error = reply['error']; + const error = reply['error']; if (error) { - var code = error['code']; - var msg = error['msg']; + const code = error['code']; + const msg = error['msg']; console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg); @@ -964,7 +956,7 @@ function handle_rpc_json(transport, scheduled_call) { } } - var seq = reply['seq']; + const seq = reply['seq']; if (seq) { if (get_seq() != seq) { @@ -974,7 +966,7 @@ function handle_rpc_json(transport, scheduled_call) { } } - var message = reply['message']; + const message = reply['message']; if (message) { if (message == "UPDATE_COUNTERS") { @@ -984,24 +976,22 @@ function handle_rpc_json(transport, scheduled_call) { } } - var counters = reply['counters']; + const counters = reply['counters']; if (counters) parse_counters(counters, scheduled_call); - var runtime_info = reply['runtime-info']; + const runtime_info = reply['runtime-info']; if (runtime_info) parse_runtime_info(runtime_info); if (netalert) netalert.hide(); - } else { - if (netalert) + } else if (netalert) netalert.show(); else notify_error("Communication problem with server."); - } } catch (e) { if (netalert) @@ -1018,7 +1008,7 @@ function handle_rpc_json(transport, scheduled_call) { function switchPanelMode(wide) { if (isCdmMode()) return; - var article_id = getActiveArticleId(); + const article_id = getActiveArticleId(); if (wide) { dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); @@ -1077,11 +1067,11 @@ function update_random_feed() { } function hash_get(key) { - var kv = window.location.hash.substring(1).toQueryParams(); + const kv = window.location.hash.substring(1).toQueryParams(); return kv[key]; } function hash_set(key, value) { - var kv = window.location.hash.substring(1).toQueryParams(); + const kv = window.location.hash.substring(1).toQueryParams(); kv[key] = value; window.location.hash = $H(kv).toQueryString(); } diff --git a/js/viewfeed.js b/js/viewfeed.js index 23332802..8f1605fa 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -24,10 +24,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) { console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req); - var is_cat = false; - var feed_id = false; + let is_cat = false; + let feed_id = false; - var reply = false; + let reply = false; try { reply = JSON.parse(transport.responseText); @@ -42,7 +42,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { last_search_query = reply['headlines']['search_query']; if (background) { - var content = reply['headlines']['content']; + let content = reply['headlines']['content']; content = content + "
"; return; @@ -63,14 +63,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) { $("floatingTitle").setAttribute("data-article-id", 0); $("floatingTitle").innerHTML = ""; } - } catch (e) { }; + } catch (e) { } $("headlines-frame").removeClassName("cdm"); $("headlines-frame").removeClassName("normal"); $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal"); - var headlines_count = reply['headlines-info']['count']; + const headlines_count = reply['headlines-info']['count']; vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; @@ -81,8 +81,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } current_first_id = reply['headlines']['first_id']; - var counters = reply['counters']; - var articles = reply['articles']; + const counters = reply['counters']; + const articles = reply['articles']; //var runtime_info = reply['runtime-info']; if (infscroll_req == false) { @@ -132,13 +132,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) { ""; } - } else { - - if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { + } else if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { console.log("adding some more headlines: " + headlines_count); - var c = dijit.byId("headlines-frame"); - var ids = getSelectedArticleIds2(); + const c = dijit.byId("headlines-frame"); + const ids = getSelectedArticleIds2(); var hsp = $("headlines-spacer"); @@ -180,7 +178,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } else { console.log("no new headlines received"); - var first_id_changed = reply['headlines']['first_id_changed']; + const first_id_changed = reply['headlines']['first_id_changed']; console.log("first id changed:" + first_id_changed); var hsp = $("headlines-spacer"); @@ -197,11 +195,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) { } } - } if (articles) { for (var i = 0; i < articles.length; i++) { - var a_id = articles[i]['id']; + const a_id = articles[i]['id']; cache_set("article:" + a_id, articles[i]['content']); } } else { @@ -244,11 +241,11 @@ function render_article(article) { dijit.byId("headlines-wrap-inner").addChild( dijit.byId("content-insert")); - var c = dijit.byId("content-insert"); + const c = dijit.byId("content-insert"); try { c.domNode.scrollTop = 0; - } catch (e) { }; + } catch (e) { } c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); @@ -257,11 +254,11 @@ function render_article(article) { try { c.focus(); - } catch (e) { }; + } catch (e) { } } function showArticleInHeadlines(id, noexpand) { - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (!row) return; if (!noexpand) @@ -279,7 +276,7 @@ function article_callback2(transport, id) { handle_rpc_json(transport); - var reply = false; + let reply = false; try { reply = JSON.parse(transport.responseText); @@ -310,17 +307,17 @@ function article_callback2(transport, id) { __('Could not display article (invalid object received - see error console for details)') + "
"); } - var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length + const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length request_counters(unread_in_buffer == 0); notify(""); } function view(id, activefeed, noexpand) { - var oldrow = $("RROW-" + getActiveArticleId()); + const oldrow = $("RROW-" + getActiveArticleId()); if (oldrow) oldrow.removeClassName("active"); - var crow = $("RROW-" + id); + const crow = $("RROW-" + id); if (!crow) return; if (noexpand) { @@ -331,19 +328,19 @@ function view(id, activefeed, noexpand) { console.log("loading article: " + id); - var cached_article = cache_get("article:" + id); + const cached_article = cache_get("article:" + id); console.log("cache check result: " + (cached_article != false)); - var query = "?op=article&method=view&id=" + param_escape(id); + let query = "?op=article&method=view&id=" + param_escape(id); - var neighbor_ids = getRelativePostIds(id); + const neighbor_ids = getRelativePostIds(id); /* only request uncached articles */ - var cids_to_request = []; + const cids_to_request = []; - for (var i = 0; i < neighbor_ids.length; i++) { + for (let i = 0; i < neighbor_ids.length; i++) { if (cids_requested.indexOf(neighbor_ids[i]) == -1) if (!cache_get("article:" + neighbor_ids[i])) { cids_to_request.push(neighbor_ids[i]); @@ -355,7 +352,7 @@ function view(id, activefeed, noexpand) { query = query + "&cids=" + cids_to_request.toString(); - var article_is_unread = crow.hasClassName("Unread"); + const article_is_unread = crow.hasClassName("Unread"); setActiveArticleId(id); showArticleInHeadlines(id); @@ -397,29 +394,29 @@ function view(id, activefeed, noexpand) { } function toggleMark(id, client_only) { - var query = "?op=rpc&id=" + id + "&method=mark"; + let query = "?op=rpc&id=" + id + "&method=mark"; - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (!row) return; - var imgs = []; + const imgs = []; - var row_imgs = row.getElementsByClassName("markedPic"); + const row_imgs = row.getElementsByClassName("markedPic"); for (var i = 0; i < row_imgs.length; i++) imgs.push(row_imgs[i]); - var ft = $("floatingTitle"); + const ft = $("floatingTitle"); if (ft && ft.getAttribute("data-article-id") == id) { - var fte = ft.getElementsByClassName("markedPic"); + const fte = ft.getElementsByClassName("markedPic"); for (var i = 0; i < fte.length; i++) imgs.push(fte[i]); } for (i = 0; i < imgs.length; i++) { - var img = imgs[i]; + const img = imgs[i]; if (!row.hasClassName("marked")) { img.src = img.src.replace("mark_unset", "mark_set"); @@ -443,7 +440,7 @@ function toggleMark(id, client_only) { } function togglePub(id, client_only, no_effects, note) { - var query = "?op=rpc&id=" + id + "&method=publ"; + let query = "?op=rpc&id=" + id + "&method=publ"; if (note != undefined) { query = query + "¬e=" + param_escape(note); @@ -451,27 +448,27 @@ function togglePub(id, client_only, no_effects, note) { query = query + "¬e=undefined"; } - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (!row) return; - var imgs = []; + const imgs = []; - var row_imgs = row.getElementsByClassName("pubPic"); + const row_imgs = row.getElementsByClassName("pubPic"); for (var i = 0; i < row_imgs.length; i++) imgs.push(row_imgs[i]); - var ft = $("floatingTitle"); + const ft = $("floatingTitle"); if (ft && ft.getAttribute("data-article-id") == id) { - var fte = ft.getElementsByClassName("pubPic"); + const fte = ft.getElementsByClassName("pubPic"); for (var i = 0; i < fte.length; i++) imgs.push(fte[i]); } for (var i = 0; i < imgs.length; i++) { - var img = imgs[i]; + const img = imgs[i]; if (!row.hasClassName("published") || note != undefined) { img.src = img.src.replace("pub_unset", "pub_set"); @@ -498,10 +495,10 @@ function togglePub(id, client_only, no_effects, note) { } function moveToPost(mode, noscroll, noexpand) { - var rows = getLoadedArticleIds(); + const rows = getLoadedArticleIds(); - var prev_id = false; - var next_id = false; + let prev_id = false; + let next_id = false; if (!$('RROW-' + getActiveArticleId())) { setActiveArticleId(0); @@ -511,13 +508,13 @@ function moveToPost(mode, noscroll, noexpand) { next_id = rows[0]; prev_id = rows[rows.length-1] } else { - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { if (rows[i] == getActiveArticleId()) { // Account for adjacent identical article ids. if (i > 0) prev_id = rows[i-1]; - for (var j = i+1; j < rows.length; j++) { + for (let j = i+1; j < rows.length; j++) { if (rows[j] != getActiveArticleId()) { next_id = rows[j]; break; @@ -559,7 +556,7 @@ function moveToPost(mode, noscroll, noexpand) { if (isCdmMode()) { var article = $("RROW-" + getActiveArticleId()); - var prev_article = $("RROW-" + prev_id); + const prev_article = $("RROW-" + prev_id); var ctr = $("headlines-frame"); if (!getInitParam("cdm_expanded")) { @@ -570,9 +567,7 @@ function moveToPost(mode, noscroll, noexpand) { cdmExpandArticle(prev_id, noexpand); cdmScrollToArticleId(prev_id, true); } - } else { - - if (!noscroll && article && article.offsetTop < ctr.scrollTop) { + } else if (!noscroll && article && article.offsetTop < ctr.scrollTop) { scrollArticle(-ctr.offsetHeight/3); } else if (!noscroll && prev_article && prev_article.offsetTop < ctr.scrollTop) { @@ -582,7 +577,6 @@ function moveToPost(mode, noscroll, noexpand) { cdmExpandArticle(prev_id, noexpand); cdmScrollToArticleId(prev_id, noscroll); } - } } else if (prev_id) { correctHeadlinesOffset(prev_id); @@ -594,10 +588,10 @@ function moveToPost(mode, noscroll, noexpand) { } function toggleSelected(id, force_on) { - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (row) { - var cb = dijit.getEnclosingWidget( + const cb = dijit.getEnclosingWidget( row.getElementsByClassName("rchk")[0]); if (row.hasClassName('Selected') && !force_on) { @@ -613,8 +607,8 @@ function toggleSelected(id, force_on) { } function updateSelectedPrompt() { - var count = getSelectedArticleIds2().size(); - var elem = $("selected_prompt"); + const count = getSelectedArticleIds2().size(); + const elem = $("selected_prompt"); if (elem) { elem.innerHTML = ngettext("%d article selected", @@ -629,9 +623,9 @@ function updateSelectedPrompt() { } function toggleUnread(id, cmode, effect) { - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (row) { - var tmpClassName = row.className; + const tmpClassName = row.className; if (cmode == undefined || cmode == 2) { if (row.hasClassName("Unread")) { @@ -651,7 +645,7 @@ function toggleUnread(id, cmode, effect) { if (cmode == undefined) cmode = 2; - var query = "?op=rpc&method=catchupSelected" + + const query = "?op=rpc&method=catchupSelected" + "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); // notify_progress("Loading, please wait..."); @@ -676,7 +670,7 @@ function selectionRemoveLabel(id, ids) { return; } - var query = "?op=article&method=removeFromLabel&ids=" + + const query = "?op=article&method=removeFromLabel&ids=" + param_escape(ids.toString()) + "&lid=" + param_escape(id); console.log(query); @@ -698,7 +692,7 @@ function selectionAssignLabel(id, ids) { return; } - var query = "?op=article&method=assignToLabel&ids=" + + const query = "?op=article&method=assignToLabel&ids=" + param_escape(ids.toString()) + "&lid=" + param_escape(id); console.log(query); @@ -712,15 +706,15 @@ function selectionAssignLabel(id, ids) { } function selectionToggleUnread(set_state, callback, no_error, ids) { - var rows = ids ? ids : getSelectedArticleIds2(); + const rows = ids ? ids : getSelectedArticleIds2(); if (rows.length == 0 && !no_error) { alert(__("No articles are selected.")); return; } - for (var i = 0; i < rows.length; i++) { - var row = $("RROW-" + rows[i]); + for (let i = 0; i < rows.length; i++) { + const row = $("RROW-" + rows[i]); if (row) { if (set_state == undefined) { if (row.hasClassName("Unread")) { @@ -744,7 +738,7 @@ function selectionToggleUnread(set_state, callback, no_error, ids) { if (rows.length > 0) { - var cmode = ""; + let cmode = ""; if (set_state == undefined) { cmode = "2"; @@ -754,7 +748,7 @@ function selectionToggleUnread(set_state, callback, no_error, ids) { cmode = "0"; } - var query = "?op=rpc&method=catchupSelected" + + const query = "?op=rpc&method=catchupSelected" + "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); notify_progress("Loading, please wait..."); @@ -771,20 +765,20 @@ function selectionToggleUnread(set_state, callback, no_error, ids) { // sel_state ignored function selectionToggleMarked(sel_state, callback, no_error, ids) { - var rows = ids ? ids : getSelectedArticleIds2(); + const rows = ids ? ids : getSelectedArticleIds2(); if (rows.length == 0 && !no_error) { alert(__("No articles are selected.")); return; } - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { toggleMark(rows[i], true, true); } if (rows.length > 0) { - var query = "?op=rpc&method=markSelected&ids=" + + const query = "?op=rpc&method=markSelected&ids=" + param_escape(rows.toString()) + "&cmode=2"; new Ajax.Request("backend.php", { @@ -799,20 +793,20 @@ function selectionToggleMarked(sel_state, callback, no_error, ids) { // sel_state ignored function selectionTogglePublished(sel_state, callback, no_error, ids) { - var rows = ids ? ids : getSelectedArticleIds2(); + const rows = ids ? ids : getSelectedArticleIds2(); if (rows.length == 0 && !no_error) { alert(__("No articles are selected.")); return; } - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { togglePub(rows[i], true, true); } if (rows.length > 0) { - var query = "?op=rpc&method=publishSelected&ids=" + + const query = "?op=rpc&method=publishSelected&ids=" + param_escape(rows.toString()) + "&cmode=2"; new Ajax.Request("backend.php", { @@ -826,7 +820,7 @@ function selectionTogglePublished(sel_state, callback, no_error, ids) { function getSelectedArticleIds2() { - var rv = []; + const rv = []; $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( function(child) { @@ -837,9 +831,9 @@ function getSelectedArticleIds2() { } function getLoadedArticleIds() { - var rv = []; + const rv = []; - var children = $$("#headlines-frame > div[id*=RROW-]"); + const children = $$("#headlines-frame > div[id*=RROW-]"); children.each(function(child) { if (Element.visible(child)) { @@ -855,12 +849,12 @@ function getLoadedArticleIds() { function selectArticles(mode, query) { if (!query) query = "#headlines-frame > div[id*=RROW]"; - var children = $$(query); + const children = $$(query); children.each(function(child) { - var id = child.getAttribute("data-article-id"); + const id = child.getAttribute("data-article-id"); - var cb = dijit.getEnclosingWidget( + const cb = dijit.getEnclosingWidget( child.getElementsByClassName("rchk")[0]); if (mode == "all") { @@ -911,15 +905,15 @@ function selectArticles(mode, query) { function deleteSelection() { - var rows = getSelectedArticleIds2(); + const rows = getSelectedArticleIds2(); if (rows.length == 0) { alert(__("No articles are selected.")); return; } - var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); - var str; + const fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); + let str; if (getActiveFeedId() != 0) { str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?", rows.length); @@ -934,7 +928,7 @@ function deleteSelection() { return; } - var query = "?op=rpc&method=delete&ids=" + param_escape(rows); + const query = "?op=rpc&method=delete&ids=" + param_escape(rows); console.log(query); @@ -949,16 +943,16 @@ function deleteSelection() { function archiveSelection() { - var rows = getSelectedArticleIds2(); + const rows = getSelectedArticleIds2(); if (rows.length == 0) { alert(__("No articles are selected.")); return; } - var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); - var str; - var op; + const fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); + let str; + let op; if (getActiveFeedId() != 0) { str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length); @@ -978,11 +972,11 @@ function archiveSelection() { return; } - var query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); + const query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); console.log(query); - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { cache_delete("article:" + rows[i]); } @@ -997,16 +991,16 @@ function archiveSelection() { function catchupSelection() { - var rows = getSelectedArticleIds2(); + const rows = getSelectedArticleIds2(); if (rows.length == 0) { alert(__("No articles are selected.")); return; } - var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); + const fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); - var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); + let str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); str = str.replace("%d", rows.length); str = str.replace("%s", fn); @@ -1019,7 +1013,7 @@ function catchupSelection() { } function editArticleTags(id) { - var query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); + const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); if (dijit.byId("editTagsDlg")) dijit.byId("editTagsDlg").destroyRecursive(); @@ -1030,7 +1024,7 @@ function editArticleTags(id) { style: "width: 600px", execute: function() { if (this.validate()) { - var query = dojo.objectToQuery(this.attr('value')); + const query = dojo.objectToQuery(this.attr('value')); notify_progress("Saving article tags...", true); @@ -1041,15 +1035,15 @@ function editArticleTags(id) { notify(''); dialog.hide(); - var data = JSON.parse(transport.responseText); + const data = JSON.parse(transport.responseText); if (data) { - var id = data.id; + const id = data.id; console.log(id); - var tags = $("ATSTR-" + id); - var tooltip = dijit.byId("ATSTRTIP-" + id); + const tags = $("ATSTR-" + id); + const tooltip = dijit.byId("ATSTRTIP-" + id); if (tags) tags.innerHTML = data.content; if (tooltip) tooltip.attr('label', data.content_full); @@ -1077,8 +1071,8 @@ function editArticleTags(id) { } function cdmScrollToArticleId(id, force) { - var ctr = $("headlines-frame"); - var e = $("RROW-" + id); + const ctr = $("headlines-frame"); + const e = $("RROW-" + id); if (!e || !ctr) return; @@ -1114,7 +1108,7 @@ function unpackVisibleHeadlines() { $$("#headlines-frame span.cencw[id]").each( function (child) { - var row = $("RROW-" + child.id.replace("CENCW-", "")); + const row = $("RROW-" + child.id.replace("CENCW-", "")); if (row && row.offsetTop <= $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight) { @@ -1142,7 +1136,7 @@ function headlines_scroll_handler(e) { _headlines_scroll_offset = e.scrollTop; - var hsp = $("headlines-spacer"); + const hsp = $("headlines-spacer"); unpackVisibleHeadlines(); @@ -1151,9 +1145,9 @@ function headlines_scroll_handler(e) { getSelectedArticleIds2().length <= 1 && getInitParam("cdm_expanded")) { - var rows = $$("#headlines-frame > div[id*=RROW]"); + const rows = $$("#headlines-frame > div[id*=RROW]"); - for (var i = 0; i < rows.length; i++) { + for (let i = 0; i < rows.length; i++) { var child = rows[i]; if ($("headlines-frame").scrollTop <= child.offsetTop && @@ -1161,7 +1155,7 @@ function headlines_scroll_handler(e) { child.getAttribute("data-article-id") != _active_article_id) { if (_active_article_id) { - var row = $("RROW-" + _active_article_id); + const row = $("RROW-" + _active_article_id); if (row) row.removeClassName("active"); } @@ -1194,7 +1188,7 @@ function headlines_scroll_handler(e) { if (getInitParam("cdm_auto_catchup") == 1) { // let's get DOM some time to settle down - var ts = new Date().getTime(); + const ts = new Date().getTime(); if (ts - _last_headlines_update < 100) return; $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( @@ -1202,7 +1196,7 @@ function headlines_scroll_handler(e) { if (child.hasClassName("Unread") && $("headlines-frame").scrollTop > (child.offsetTop + child.offsetHeight/2)) { - var id = child.getAttribute("data-article-id") + const id = child.getAttribute("data-article-id") if (catchup_id_batch.indexOf(id) == -1) catchup_id_batch.push(id); @@ -1233,8 +1227,8 @@ function headlines_scroll_handler(e) { } function openNextUnreadFeed() { - var is_cat = activeFeedIsCat(); - var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat); + const is_cat = activeFeedIsCat(); + const nuf = getNextUnreadFeed(getActiveFeedId(), is_cat); if (nuf) viewfeed({feed: nuf, is_cat: is_cat}); } @@ -1244,8 +1238,8 @@ function catchupBatchedArticles() { console.log("catchupBatchedArticles: working"); // make a copy of the array - var batch = catchup_id_batch.slice(); - var query = "?op=rpc&method=catchupSelected" + + const batch = catchup_id_batch.slice(); + const query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + param_escape(batch.toString()); console.log(query); @@ -1259,12 +1253,12 @@ function catchupBatchedArticles() { _catchup_request_sent = false; - var reply = JSON.parse(transport.responseText); - var batch = reply.ids; + const reply = JSON.parse(transport.responseText); + const batch = reply.ids; batch.each(function (id) { console.log(id); - var elem = $("RROW-" + id); + const elem = $("RROW-" + id); if (elem) elem.removeClassName("Unread"); catchup_id_batch.remove(id); }); @@ -1285,9 +1279,9 @@ function catchupRelativeToArticle(below, id) { return; } - var visible_ids = getLoadedArticleIds(); + const visible_ids = getLoadedArticleIds(); - var ids_to_mark = new Array(); + const ids_to_mark = new Array(); if (!below) { for (var i = 0; i < visible_ids.length; i++) { @@ -1318,7 +1312,7 @@ function catchupRelativeToArticle(below, id) { if (ids_to_mark.length == 0) { alert(__("No articles found to mark")); } else { - var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length); + const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length); if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { @@ -1327,7 +1321,7 @@ function catchupRelativeToArticle(below, id) { e.removeClassName("Unread"); } - var query = "?op=rpc&method=catchupSelected" + + const query = "?op=rpc&method=catchupSelected" + "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); new Ajax.Request("backend.php", { @@ -1344,11 +1338,11 @@ function catchupRelativeToArticle(below, id) { function cdmCollapseArticle(event, id, unmark) { if (unmark == undefined) unmark = true; - var row = $("RROW-" + id); - var elem = $("CICD-" + id); + const row = $("RROW-" + id); + const elem = $("CICD-" + id); if (elem && row) { - var collapse = row.select("span[class='collapseBtn']")[0]; + const collapse = row.select("span[class='collapseBtn']")[0]; Element.hide(elem); Element.show("CEXC-" + id); @@ -1381,20 +1375,20 @@ function cdmCollapseArticle(event, id, unmark) { function cdmExpandArticle(id, noexpand) { console.log("cdmExpandArticle " + id); - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (!row) return false; - var oldrow = $("RROW-" + getActiveArticleId()); + const oldrow = $("RROW-" + getActiveArticleId()); - var elem = $("CICD-" + getActiveArticleId()); + let elem = $("CICD-" + getActiveArticleId()); if (id == getActiveArticleId() && Element.visible(elem)) return true; selectArticles("none"); - var old_offset = row.offsetTop; + const old_offset = row.offsetTop; if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) { var collapse = oldrow.select("span[class='collapseBtn']")[0]; @@ -1412,7 +1406,7 @@ function cdmExpandArticle(id, noexpand) { var collapse = row.select("span[class='collapseBtn']")[0]; - var cencw = $("CENCW-" + id); + const cencw = $("CENCW-" + id); if (!Element.visible(elem) && !noexpand) { if (cencw) { @@ -1426,7 +1420,7 @@ function cdmExpandArticle(id, noexpand) { Element.show(collapse); } - var new_offset = row.offsetTop; + const new_offset = row.offsetTop; if (old_offset > new_offset) $("headlines-frame").scrollTop -= (old_offset - new_offset); @@ -1452,12 +1446,12 @@ function getArticleUnderPointer() { function scrollArticle(offset) { if (!isCdmMode()) { - var ci = $("content-insert"); + const ci = $("content-insert"); if (ci) { ci.scrollTop += offset; } } else { - var hi = $("headlines-frame"); + const hi = $("headlines-frame"); if (hi) { hi.scrollTop += offset; } @@ -1466,7 +1460,7 @@ function scrollArticle(offset) { } function show_labels_in_headlines(transport) { - var data = JSON.parse(transport.responseText); + const data = JSON.parse(transport.responseText); if (data) { data['info-for-headlines'].each(function (elem) { @@ -1506,7 +1500,7 @@ function cdmClicked(event, id, in_body) { updateFloatingTitle(true); } - var query = "?op=rpc&method=catchupSelected" + + const query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + param_escape(id); new Ajax.Request("backend.php", { @@ -1537,7 +1531,7 @@ function cdmClicked(event, id, in_body) { return true; } - var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length + const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length request_counters(unread_in_buffer == 0); return false; @@ -1559,7 +1553,7 @@ function hlClicked(event, id) { function openArticleInNewWindow(id) { toggleUnread(id, 0, false); - var w = window.open(""); + const w = window.open(""); w.opener = null; w.location = "backend.php?op=article&method=redirect&id=" + id; } @@ -1571,9 +1565,9 @@ function isCdmMode() { function markHeadline(id, marked) { if (marked == undefined) marked = true; - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (row) { - var check = dijit.getEnclosingWidget( + const check = dijit.getEnclosingWidget( row.getElementsByClassName("rchk")[0]); if (check) { @@ -1589,15 +1583,15 @@ function markHeadline(id, marked) { function getRelativePostIds(id, limit) { - var tmp = []; + const tmp = []; if (!limit) limit = 6; //3 - var ids = getLoadedArticleIds(); + const ids = getLoadedArticleIds(); - for (var i = 0; i < ids.length; i++) { + for (let i = 0; i < ids.length; i++) { if (ids[i] == id) { - for (var k = 1; k <= limit; k++) { + for (let k = 1; k <= limit; k++) { //if (i > k-1) tmp.push(ids[i-k]); if (i < ids.length - k) tmp.push(ids[i + k]); } @@ -1610,15 +1604,15 @@ function getRelativePostIds(id, limit) { function correctHeadlinesOffset(id) { - var container = $("headlines-frame"); - var row = $("RROW-" + id); + const container = $("headlines-frame"); + const row = $("RROW-" + id); if (!container || !row) return; - var viewport = container.offsetHeight; + const viewport = container.offsetHeight; - var rel_offset_top = row.offsetTop - container.scrollTop; - var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; + const rel_offset_top = row.offsetTop - container.scrollTop; + const rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); //console.log("Vport: " + viewport); @@ -1649,7 +1643,7 @@ function closeArticlePanel() { function initFloatingMenu() { if (!dijit.byId("floatingMenu")) { - var menu = new dijit.Menu({ + const menu = new dijit.Menu({ id: "floatingMenu", targetNodeIds: ["floatingTitle"] }); @@ -1682,9 +1676,9 @@ function headlinesMenuCommon(menu) { label: __("Toggle unread"), onClick: function (event) { - var ids = getSelectedArticleIds2(); + let ids = getSelectedArticleIds2(); // cast to string - var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleUnread(undefined, false, true, ids); @@ -1694,9 +1688,9 @@ function headlinesMenuCommon(menu) { menu.addChild(new dijit.MenuItem({ label: __("Toggle starred"), onClick: function (event) { - var ids = getSelectedArticleIds2(); + let ids = getSelectedArticleIds2(); // cast to string - var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleMarked(undefined, false, true, ids); @@ -1706,9 +1700,9 @@ function headlinesMenuCommon(menu) { menu.addChild(new dijit.MenuItem({ label: __("Toggle published"), onClick: function (event) { - var ids = getSelectedArticleIds2(); + let ids = getSelectedArticleIds2(); // cast to string - var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionTogglePublished(undefined, false, true, ids); @@ -1732,27 +1726,27 @@ function headlinesMenuCommon(menu) { })); - var labels = getInitParam("labels"); + const labels = getInitParam("labels"); if (labels && labels.length) { menu.addChild(new dijit.MenuSeparator()); - var labelAddMenu = new dijit.Menu({ownerMenu: menu}); - var labelDelMenu = new dijit.Menu({ownerMenu: menu}); + const labelAddMenu = new dijit.Menu({ownerMenu: menu}); + const labelDelMenu = new dijit.Menu({ownerMenu: menu}); labels.each(function (label) { - var bare_id = label.id; - var name = label.caption; + const bare_id = label.id; + const name = label.caption; labelAddMenu.addChild(new dijit.MenuItem({ label: name, labelId: bare_id, onClick: function (event) { - var ids = getSelectedArticleIds2(); + let ids = getSelectedArticleIds2(); // cast to string - var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; + const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1764,9 +1758,9 @@ function headlinesMenuCommon(menu) { label: name, labelId: bare_id, onClick: function (event) { - var ids = getSelectedArticleIds2(); + let ids = getSelectedArticleIds2(); // cast to string - var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; + const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1884,7 +1878,7 @@ function cancelSearch() { } function setSelectionScore() { - var ids = getSelectedArticleIds2(); + const ids = getSelectedArticleIds2(); if (ids.length > 0) { console.log(ids); @@ -1892,21 +1886,21 @@ function setSelectionScore() { var score = prompt(__("Please enter new score for selected articles:"), score); if (score != undefined) { - var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) + + const query = "op=article&method=setScore&id=" + param_escape(ids.toString()) + "&score=" + param_escape(score); new Ajax.Request("backend.php", { parameters: query, onComplete: function (transport) { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (reply) { console.log(ids); ids.each(function (id) { - var row = $("RROW-" + id); + const row = $("RROW-" + id); if (row) { - var pic = row.getElementsByClassName("hlScorePic")[0]; + const pic = row.getElementsByClassName("hlScorePic")[0]; if (pic) { pic.src = pic.src.replace(/score_.*?\.png/, @@ -1926,18 +1920,18 @@ function setSelectionScore() { } function updateScore(id) { - var pic = $$("#RROW-" + id + " .hlScorePic")[0]; + const pic = $$("#RROW-" + id + " .hlScorePic")[0]; if (pic) { - var query = "op=article&method=getScore&id=" + param_escape(id); + const query = "op=article&method=getScore&id=" + param_escape(id); new Ajax.Request("backend.php", { parameters: query, onComplete: function (transport) { console.log(transport.responseText); - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (reply) { pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); @@ -1950,19 +1944,19 @@ function updateScore(id) { } function changeScore(id, pic) { - var score = pic.getAttribute("score"); + const score = pic.getAttribute("score"); - var new_score = prompt(__("Please enter new score for this article:"), score); + const new_score = prompt(__("Please enter new score for this article:"), score); if (new_score != undefined) { - var query = "op=article&method=setScore&id=" + param_escape(id) + + const query = "op=article&method=setScore&id=" + param_escape(id) + "&score=" + param_escape(new_score); new Ajax.Request("backend.php", { parameters: query, onComplete: function (transport) { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (reply) { pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); @@ -1975,12 +1969,12 @@ function changeScore(id, pic) { } function displayArticleUrl(id) { - var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id); + const query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id); new Ajax.Request("backend.php", { parameters: query, onComplete: function (transport) { - var reply = JSON.parse(transport.responseText); + const reply = JSON.parse(transport.responseText); if (reply && reply.link) { prompt(__("Article URL:"), reply.link); @@ -1990,7 +1984,7 @@ function displayArticleUrl(id) { } function scrollToRowId(id) { - var row = $(id); + const row = $(id); if (row) $("headlines-frame").scrollTop = row.offsetTop - 4; @@ -1999,17 +1993,17 @@ function scrollToRowId(id) { function updateFloatingTitle(unread_only) { if (!isCdmMode()) return; - var hf = $("headlines-frame"); + const hf = $("headlines-frame"); - var elems = $$("#headlines-frame > div[id*=RROW]"); + const elems = $$("#headlines-frame > div[id*=RROW]"); - for (var i = 0; i < elems.length; i++) { + for (let i = 0; i < elems.length; i++) { - var child = elems[i]; + const child = elems[i]; if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) { - var header = child.getElementsByClassName("cdmHeader")[0]; + const header = child.getElementsByClassName("cdmHeader")[0]; if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) { if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) { @@ -2020,7 +2014,7 @@ function updateFloatingTitle(unread_only) { initFloatingMenu(); - var cb = $$("#floatingTitle .dijitCheckBox")[0]; + const cb = $$("#floatingTitle .dijitCheckBox")[0]; if (cb) cb.parentNode.removeChild(cb);