From 97df81d8d9d9ebcbf5a41dd736924d7a61855fbc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:54:16 +0300 Subject: even more objectification of JS --- js/feedlist.js | 4 +- js/tt-rss.js | 2 +- js/viewfeed.js | 201 ++++++++++++++++++++++++++++----------------------------- 3 files changed, 103 insertions(+), 104 deletions(-) (limited to 'js') diff --git a/js/feedlist.js b/js/feedlist.js index a95a82672..a0b552132 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -43,7 +43,7 @@ const Feeds = { parseCounters: function (elems) { for (let l = 0; l < elems.length; l++) { - if (this._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { + if (Feeds._counters_prev[l] && this.counterEquals(elems[l], this._counters_prev[l])) { continue; } @@ -169,7 +169,7 @@ const Feeds = { const id = String(item.id); const is_cat = id.match("^CAT:"); const feed = id.substr(id.indexOf(":") + 1); - this.viewfeed({feed: feed, is_cat: is_cat}); + Feeds.viewfeed({feed: feed, is_cat: is_cat}); return false; }, openOnClick: false, diff --git a/js/tt-rss.js b/js/tt-rss.js index 66a94f714..e48e4ece9 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -326,7 +326,7 @@ function init_hotkey_actions() { }; hotkey_actions["close_article"] = function () { if (App.isCombinedMode()) { - cdmCollapseActive(); + Article.cdmCollapseActive(); } else { Article.closeArticlePanel(); } diff --git a/js/viewfeed.js b/js/viewfeed.js index f57f7fc6c..45d2efebb 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -38,6 +38,60 @@ const ArticleCache = { }; const Article = { + setSelectionScore: function() { + const ids = getSelectedArticleIds2(); + + if (ids.length > 0) { + console.log(ids); + + const score = prompt(__("Please enter new score for selected articles:")); + + if (score != undefined) { + const query = { + op: "article", method: "setScore", id: ids.toString(), + score: score + }; + + xhrJson("backend.php", query, (reply) => { + if (reply) { + reply.id.each((id) => { + const row = $("RROW-" + id); + + if (row) { + const pic = row.getElementsByClassName("score-pic")[0]; + + if (pic) { + pic.src = pic.src.replace(/score_.*?\.png/, + reply["score_pic"]); + pic.setAttribute("score", reply["score"]); + } + } + }); + } + }); + } + + } else { + alert(__("No articles are selected.")); + } + }, + changeScore: function(id, pic) { + const score = pic.getAttribute("score"); + + const new_score = prompt(__("Please enter new score for this article:"), score); + + if (new_score != undefined) { + const query = {op: "article", method: "setScore", id: id, score: new_score}; + + xhrJson("backend.php", query, (reply) => { + if (reply) { + pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); + pic.setAttribute("score", new_score); + pic.setAttribute("title", new_score); + } + }); + } + }, closeArticlePanel: function () { if (dijit.byId("content-insert")) dijit.byId("headlines-wrap-inner").removeChild( @@ -136,10 +190,55 @@ const Article = { return false; }, -} + cdmCollapseActive: function(event) { + const row = $("RROW-" + getActiveArticleId()); + + if (row) { + row.removeClassName("active"); + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + + if (cb && !row.hasClassName("Selected")) + cb.attr("checked", false); + + setActiveArticleId(0); + + if (event) + event.stopPropagation(); + + return false; + } + } +}; const Headlines = { _headlines_scroll_timeout: 0, + click: function(event, id, in_body) { + in_body = in_body || false; + + if (App.isCombinedMode()) { + + if (!in_body && (event.ctrlKey || id == getActiveArticleId() || getInitParam("cdm_expanded"))) { + Article.openArticleInNewWindow(id); + } + + setActiveArticleId(id); + + if (!getInitParam("cdm_expanded")) + cdmScrollToArticleId(id); + + return in_body; + + } else { + if (event.ctrlKey) { + Article.openArticleInNewWindow(id); + setActiveArticleId(id); + } else { + Article.view(id); + } + + return false; + } + }, initScrollHandler: function() { $("headlines-frame").onscroll = (event) => { clearTimeout(this._headlines_scroll_timeout); @@ -1238,33 +1337,6 @@ function updateHeadlineLabels(transport) { } } -function cdmClicked(event, id, in_body) { - in_body = in_body || false; - - if (!in_body && (event.ctrlKey || id == getActiveArticleId() || getInitParam("cdm_expanded"))) { - Article.openArticleInNewWindow(id); - } - - setActiveArticleId(id); - - if (!getInitParam("cdm_expanded")) - cdmScrollToArticleId(id); - - return in_body; -} - -function hlClicked(event, id) { - if (event.ctrlKey) { - Article.openArticleInNewWindow(id); - setActiveArticleId(id); - } else { - Article.view(id); - } - - return false; -} - - function getRelativePostIds(id, limit) { const tmp = []; @@ -1313,25 +1385,6 @@ function headlineActionsChange(elem) { elem.attr('value', 'false'); } -function cdmCollapseActive(event) { - const row = $("RROW-" + getActiveArticleId()); - - if (row) { - row.removeClassName("active"); - const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); - - if (cb && !row.hasClassName("Selected")) - cb.attr("checked", false); - - setActiveArticleId(0); - - if (event) - event.stopPropagation(); - - return false; - } -} - function initFloatingMenu() { if (!dijit.byId("floatingMenu")) { @@ -1539,59 +1592,5 @@ function initHeadlinesMenu() { } } -// noinspection JSUnusedGlobalSymbols -function setSelectionScore() { - const ids = getSelectedArticleIds2(); - - if (ids.length > 0) { - console.log(ids); - - const score = prompt(__("Please enter new score for selected articles:")); - - if (score != undefined) { - const query = { op: "article", method: "setScore", id: ids.toString(), - score: score }; - - xhrJson("backend.php", query, (reply) => { - if (reply) { - reply.id.each((id) => { - const row = $("RROW-" + id); - - if (row) { - const pic = row.getElementsByClassName("score-pic")[0]; - - if (pic) { - pic.src = pic.src.replace(/score_.*?\.png/, - reply["score_pic"]); - pic.setAttribute("score", reply["score"]); - } - } - }); - } - }); - } - - } else { - alert(__("No articles are selected.")); - } -} - -// noinspection JSUnusedGlobalSymbols -function changeScore(id, pic) { - const score = pic.getAttribute("score"); - - const new_score = prompt(__("Please enter new score for this article:"), score); - - if (new_score != undefined) { - const query = { op: "article", method: "setScore", id: id, score: new_score }; - xhrJson("backend.php", query, (reply) => { - if (reply) { - pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); - pic.setAttribute("score", new_score); - pic.setAttribute("title", new_score); - } - }); - } -} -- cgit v1.2.3