]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
use xhrPost in more places; various minor cleanup
[tt-rss.git] / js / viewfeed.js
index 8f1605faca6faa0618cf06bc06f6d36b5491144b..b9c635f013a0905537d2b8f2908e64b065562f23 100755 (executable)
@@ -1,39 +1,36 @@
-var _active_article_id = 0;
+/* global dijit, __ */
 
-var vgroup_last_feed = false;
-var post_under_pointer = false;
+let _active_article_id = 0;
 
-var last_requested_article = false;
+let vgroup_last_feed = false;
+let post_under_pointer = false;
 
-var catchup_id_batch = [];
-var catchup_timeout_id = false;
+let last_requested_article = 0;
 
-var cids_requested = [];
-var loaded_article_ids = [];
-var _last_headlines_update = 0;
-var _headlines_scroll_offset = 0;
-var current_first_id = 0;
-var last_search_query;
+let catchup_id_batch = [];
+let catchup_timeout_id = false;
 
-var _catchup_request_sent = false;
+let cids_requested = [];
+let loaded_article_ids = [];
+let _last_headlines_update = 0;
+let _headlines_scroll_offset = 0;
+let current_first_id = 0;
+let last_search_query;
 
-var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
+let _catchup_request_sent = false;
+
+let has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
 function headlines_callback2(transport, offset, background, infscroll_req) {
-       handle_rpc_json(transport);
+       const reply = handle_rpc_json(transport);
 
        console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
 
-       let is_cat = false;
-       let feed_id = false;
-
-       let reply = false;
+       if (background)
+               return;
 
-       try {
-               reply = JSON.parse(transport.responseText);
-       } catch (e) {
-               console.error(e);
-       }
+       var is_cat = false;
+       var feed_id = false;
 
        if (reply) {
 
@@ -41,20 +38,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                feed_id = reply['headlines']['id'];
                last_search_query = reply['headlines']['search_query'];
 
-               if (background) {
-                       let content = reply['headlines']['content'];
-
-                       content = content + "<div id='headlines-spacer'></div>";
-                       return;
-               }
+        console.log(feed_id, getActiveFeedId(), is_cat, activeFeedIsCat());
 
                if (feed_id != -7 && (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()))
                        return;
 
-               /* dijit.getEnclosingWidget(
-                       document.forms["main_toolbar_form"].update).attr('disabled',
-                               is_cat || feed_id <= 0); */
-
                try {
                        if (infscroll_req == false) {
                                $("headlines-frame").scrollTop = 0;
@@ -83,7 +71,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                current_first_id = reply['headlines']['first_id'];
                const counters = reply['counters'];
                const articles = reply['articles'];
-               //var runtime_info = reply['runtime-info'];
 
                if (infscroll_req == false) {
                        loaded_article_ids = [];
@@ -92,17 +79,9 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        reply['headlines']['toolbar'],
                                        {parseContent: true});
 
-                       /*dojo.html.set($("headlines-frame"),
-                               reply['headlines']['content'],
-                               {parseContent: true});
-
-                       $$("#headlines-frame div[id*='RROW']").each(function(row) {
-                               loaded_article_ids.push(row.id);
-                       });*/
-
                        $("headlines-frame").innerHTML = '';
 
-                       var tmp = new Element("div");
+                       let tmp = document.createElement("div");
                        tmp.innerHTML = reply['headlines']['content'];
                        dojo.parser.parse(tmp);
 
@@ -116,7 +95,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                }
                        }
 
-                       var hsp = $("headlines-spacer");
+                       let hsp = $("headlines-spacer");
                        if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
                        dijit.byId('headlines-frame').domNode.appendChild(hsp);
 
@@ -138,17 +117,17 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                const c = dijit.byId("headlines-frame");
                                const ids = getSelectedArticleIds2();
 
-                               var hsp = $("headlines-spacer");
+                               let hsp = $("headlines-spacer");
 
                                if (hsp)
                                        c.domNode.removeChild(hsp);
 
-                               var tmp = new Element("div");
+                               let tmp = document.createElement("div");
                                tmp.innerHTML = reply['headlines']['content'];
                                dojo.parser.parse(tmp);
 
                                while (tmp.hasChildNodes()) {
-                                       var row = tmp.removeChild(tmp.firstChild);
+                                       let row = tmp.removeChild(tmp.firstChild);
 
                                        if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
                                                dijit.byId("headlines-frame").domNode.appendChild(row);
@@ -164,7 +143,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                console.log("restore selected ids: " + ids);
 
-                               for (var i = 0; i < ids.length; i++) {
+                               for (let i = 0; i < ids.length; i++) {
                                        markHeadline(ids[i]);
                                }
 
@@ -181,7 +160,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                const first_id_changed = reply['headlines']['first_id_changed'];
                                console.log("first id changed:" + first_id_changed);
 
-                               var hsp = $("headlines-spacer");
+                               let hsp = $("headlines-spacer");
 
                                if (hsp) {
                                        if (first_id_changed) {
@@ -197,7 +176,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        }
 
                if (articles) {
-                       for (var i = 0; i < articles.length; i++) {
+                       for (let i = 0; i < articles.length; i++) {
                                const a_id = articles[i]['id'];
                                cache_set("article:" + a_id, articles[i]['content']);
                        }
@@ -607,7 +586,7 @@ function toggleSelected(id, force_on) {
 }
 
 function updateSelectedPrompt() {
-       const count = getSelectedArticleIds2().size();
+       const count = getSelectedArticleIds2().length;
        const elem = $("selected_prompt");
 
        if (elem) {
@@ -1018,7 +997,7 @@ function editArticleTags(id) {
        if (dijit.byId("editTagsDlg"))
                dijit.byId("editTagsDlg").destroyRecursive();
 
-       var dialog = new dijit.Dialog({
+       const dialog = new dijit.Dialog({
                id: "editTagsDlg",
                title: __("Edit article Tags"),
                style: "width: 600px",
@@ -1148,7 +1127,7 @@ function headlines_scroll_handler(e) {
                        const rows = $$("#headlines-frame > div[id*=RROW]");
 
                        for (let i = 0; i < rows.length; i++) {
-                               var child = rows[i];
+                               const child = rows[i];
 
                                if ($("headlines-frame").scrollTop <= child.offsetTop &&
                                        child.offsetTop - $("headlines-frame").scrollTop < 100 &&
@@ -1193,8 +1172,7 @@ function headlines_scroll_handler(e) {
 
                        $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
                                function(child) {
-                                       if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
-                                                       (child.offsetTop + child.offsetHeight/2)) {
+                                       if ($("headlines-frame").scrollTop > (child.offsetTop + child.offsetHeight/2)) {
 
                                                const id = child.getAttribute("data-article-id")
 
@@ -1207,7 +1185,7 @@ function headlines_scroll_handler(e) {
                                });
 
                        if (_infscroll_disable) {
-                               var child = $$("#headlines-frame div[id*=RROW]").last();
+                               const child = $$("#headlines-frame div[id*=RROW]").last();
 
                                if (child && $("headlines-frame").scrollTop >
                                                (child.offsetTop + child.offsetHeight - 50)) {
@@ -1281,7 +1259,7 @@ function catchupRelativeToArticle(below, id) {
 
        const visible_ids = getLoadedArticleIds();
 
-       const ids_to_mark = new Array();
+       const ids_to_mark = [];
 
        if (!below) {
                for (var i = 0; i < visible_ids.length; i++) {
@@ -1391,7 +1369,7 @@ function cdmExpandArticle(id, noexpand) {
        const old_offset = row.offsetTop;
 
        if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
-               var collapse = oldrow.select("span[class='collapseBtn']")[0];
+               let collapse = oldrow.select("span[class='collapseBtn']")[0];
 
                Element.hide(elem);
                Element.show("CEXC-" + getActiveArticleId());
@@ -1404,7 +1382,7 @@ function cdmExpandArticle(id, noexpand) {
 
        elem = $("CICD-" + id);
 
-       var collapse = row.select("span[class='collapseBtn']")[0];
+       let collapse = row.select("span[class='collapseBtn']")[0];
 
        const cencw = $("CENCW-" + id);
 
@@ -1480,15 +1458,15 @@ function cdmClicked(event, id, in_body) {
                        return cdmExpandArticle(id);
                } else {
 
-                       var elem = $("RROW-" + getActiveArticleId());
+                       let elem = $("RROW-" + getActiveArticleId());
 
                        if (elem) elem.removeClassName("active");
 
                        selectArticles("none");
                        toggleSelected(id);
 
-                       var elem = $("RROW-" + id);
-                       var article_is_unread = elem.hasClassName("Unread");
+                       elem = $("RROW-" + id);
+                       const article_is_unread = elem.hasClassName("Unread");
 
                        elem.removeClassName("Unread");
                        elem.addClassName("active");
@@ -1517,8 +1495,8 @@ function cdmClicked(event, id, in_body) {
 
                toggleSelected(id, true);
 
-               var elem = $("RROW-" + id);
-               var article_is_unread = elem.hasClassName("Unread");
+               let elem = $("RROW-" + id);
+               const article_is_unread = elem.hasClassName("Unread");
 
                if (article_is_unread) {
                        decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
@@ -1674,12 +1652,12 @@ function headlinesMenuCommon(menu) {
 
        menu.addChild(new dijit.MenuItem({
                label: __("Toggle unread"),
-               onClick: function (event) {
+               onClick: function () {
 
                        let ids = getSelectedArticleIds2();
                        // cast to string
                        const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
-                       ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+                       ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                        selectionToggleUnread(undefined, false, true, ids);
                }
@@ -1687,11 +1665,11 @@ function headlinesMenuCommon(menu) {
 
        menu.addChild(new dijit.MenuItem({
                label: __("Toggle starred"),
-               onClick: function (event) {
+               onClick: function () {
                        let ids = getSelectedArticleIds2();
                        // cast to string
                        const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
-                       ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+                       ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                        selectionToggleMarked(undefined, false, true, ids);
                }
@@ -1699,11 +1677,11 @@ function headlinesMenuCommon(menu) {
 
        menu.addChild(new dijit.MenuItem({
                label: __("Toggle published"),
-               onClick: function (event) {
+               onClick: function () {
                        let ids = getSelectedArticleIds2();
                        // cast to string
                        const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
-                       ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+                       ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                        selectionTogglePublished(undefined, false, true, ids);
                }
@@ -1713,14 +1691,14 @@ function headlinesMenuCommon(menu) {
 
        menu.addChild(new dijit.MenuItem({
                label: __("Mark above as read"),
-               onClick: function (event) {
+               onClick: function () {
                        catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id"));
                }
        }));
 
        menu.addChild(new dijit.MenuItem({
                label: __("Mark below as read"),
-               onClick: function (event) {
+               onClick: function () {
                        catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id"));
                }
        }));
@@ -1742,13 +1720,13 @@ function headlinesMenuCommon(menu) {
                        labelAddMenu.addChild(new dijit.MenuItem({
                                label: name,
                                labelId: bare_id,
-                               onClick: function (event) {
+                               onClick: function () {
 
                                        let ids = getSelectedArticleIds2();
                                        // cast to string
                                        const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
 
-                                       ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+                                       ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                                        selectionAssignLabel(this.labelId, ids);
                                }
@@ -1757,12 +1735,12 @@ function headlinesMenuCommon(menu) {
                        labelDelMenu.addChild(new dijit.MenuItem({
                                label: name,
                                labelId: bare_id,
-                               onClick: function (event) {
+                               onClick: function () {
                                        let ids = getSelectedArticleIds2();
                                        // cast to string
                                        const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
 
-                                       ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+                                       ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                                        selectionRemoveLabel(this.labelId, ids);
                                }
@@ -1786,7 +1764,7 @@ function headlinesMenuCommon(menu) {
 function initHeadlinesMenu() {
        if (!dijit.byId("headlinesMenu")) {
 
-               var menu = new dijit.Menu({
+               const menu = new dijit.Menu({
                        id: "headlinesMenu",
                        targetNodeIds: ["headlines-frame"],
                        selector: ".hlMenuAttach"
@@ -1801,7 +1779,7 @@ function initHeadlinesMenu() {
 
        if (!dijit.byId("headlinesFeedTitleMenu")) {
 
-               var menu = new dijit.Menu({
+               const menu = new dijit.Menu({
                        id: "headlinesFeedTitleMenu",
                        targetNodeIds: ["headlines-frame"],
                        selector: "div.cdmFeedTitle"
@@ -1819,7 +1797,7 @@ function initHeadlinesMenu() {
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Mark group as read"),
-                       onClick: function (event) {
+                       onClick: function () {
                                selectArticles("none");
                                selectArticles("all",
                                        "#headlines-frame > div[id*=RROW]" +
@@ -1831,14 +1809,14 @@ function initHeadlinesMenu() {
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Mark feed as read"),
-                       onClick: function (event) {
+                       onClick: function () {
                                catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id"));
                        }
                }));
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Edit feed"),
-                       onClick: function (event) {
+                       onClick: function () {
                                editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
                        }
                }));
@@ -1883,7 +1861,7 @@ function setSelectionScore() {
        if (ids.length > 0) {
                console.log(ids);
 
-               var score = prompt(__("Please enter new score for selected articles:"), score);
+               const score = prompt(__("Please enter new score for selected articles:"));
 
                if (score != undefined) {
                        const query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
@@ -2051,7 +2029,3 @@ function catchupCurrentBatchIfNeeded() {
                }
        }
 }
-
-function cdmFooterClick(event) {
-       event.stopPropagation();
-}