diff options
author | Andrew Dolgov <[email protected]> | 2018-12-01 17:54:16 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-12-01 17:54:16 +0300 |
commit | 97df81d8d9d9ebcbf5a41dd736924d7a61855fbc (patch) | |
tree | 2ed6e123dffba1d4f14950333e7400e0f2815457 | |
parent | 1d82bd4f19de40f0cf966545c372595caa2c8afe (diff) |
even more objectification of JS
-rwxr-xr-x | classes/feeds.php | 12 | ||||
-rw-r--r-- | js/feedlist.js | 4 | ||||
-rw-r--r-- | js/tt-rss.js | 2 | ||||
-rwxr-xr-x | js/viewfeed.js | 201 |
4 files changed, 109 insertions, 110 deletions
diff --git a/classes/feeds.php b/classes/feeds.php index 63366fd0d..d9bcbbd04 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -29,7 +29,7 @@ class Feeds extends Handler_Protected { $tog_marked_link = "selectionToggleMarked()"; $tog_published_link = "selectionTogglePublished()"; - $set_score_link = "setSelectionScore()"; + $set_score_link = "Article.setSelectionScore()"; if ($is_cat) $cat_q = "&is_cat=$is_cat"; @@ -345,7 +345,7 @@ class Feeds extends Handler_Protected { $score_pic = "images/" . get_score_pic($score); - $score_pic = "<img class='score-pic' score='$score' onclick='changeScore($id, this)' src=\"$score_pic\" + $score_pic = "<img class='score-pic' score='$score' onclick='Article.changeScore($id, this)' src=\"$score_pic\" title=\"$score\">"; if ($score > 500) { @@ -413,7 +413,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "</div>"; - $reply['content'] .= "<div onclick='return hlClicked(event, $id)' + $reply['content'] .= "<div onclick='return Headlines.click(event, $id)' class=\"title\"><span class='hl-content $hlc_suffix'>"; $reply['content'] .= "<a class=\"title $hlc_suffix\" href=\"" . htmlspecialchars($line["link"]) . "\" @@ -523,7 +523,7 @@ class Feeds extends Handler_Protected { // data-article-id included for context menu $tmp_content .= "<span - onclick=\"return cdmClicked(event, $id);\" + onclick=\"return Headlines.click(event, $id);\" data-article-id=\"$id\" class=\"titleWrap hlMenuAttach $hlc_suffix\"> <a class=\"title $hlc_suffix\" @@ -536,7 +536,7 @@ class Feeds extends Handler_Protected { $tmp_content .= $labels_str; $tmp_content .= "<span class='collapse'> - <img src=\"images/collapse.png\" onclick=\"return cdmCollapseActive(event)\" + <img src=\"images/collapse.png\" onclick=\"return Article.cdmCollapseActive(event)\" title=\"".__("Collapse article")."\"/></span>"; $tmp_content .= "</span>"; @@ -567,7 +567,7 @@ class Feeds extends Handler_Protected { $tmp_content .= "</div>"; //header - $tmp_content .= "<div class=\"content\" onclick=\"return cdmClicked(event, $id, true);\">"; + $tmp_content .= "<div class=\"content\" onclick=\"return Headlines.click(event, $id, true);\">"; $tmp_content .= "<div id=\"POSTNOTE-$id\">"; if ($line['note']) { 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); - } - }); - } -} |