]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
fix infinite scrolling for search results
[tt-rss.git] / js / viewfeed.js
index a4e9f82c052e77cb56959ab802a63bccd7b62b40..cb0a759603c15a393f2bb502d45df408e94f87ff 100644 (file)
@@ -80,6 +80,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                dijit.byId("headlines-toolbar").attr('content',
                                        reply['headlines']['toolbar']);
 
+                               $$("#headlines-frame > div[id*=RROW]").each(function(row) {
+                                       if ($$("#headlines-frame DIV[id="+row.id+"]").length > 1) {
+                                               row.parentNode.removeChild(row);
+                                       }
+                               });
 
                                if (getInitParam("cdm_auto_catchup") == 1) {
                                        var hsp = $("headlines-spacer");
@@ -92,10 +97,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        } else {
 
                                if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
-                                       console.log("adding some more headlines...");
+                                       console.log("adding some more headlines: " + headlines_count);
 
                                        var c = dijit.byId("headlines-frame");
                                        var ids = getSelectedArticleIds2();
+                                       var num_added = 0;
 
                                        $("headlines-tmp").innerHTML = reply['headlines']['content'];
 
@@ -108,6 +114,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
                                                        row.style.display = 'none';
                                                        c.domNode.appendChild(row);
+                                                       ++num_added;
                                                } else {
                                                        row.parentNode.removeChild(row);
                                                }
@@ -121,6 +128,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                c.domNode.appendChild(hsp);
                                        }
 
+                                       console.log("added " + num_added + " headlines");
+
+                                       if (num_added == 0)
+                                               _infscroll_disable = true;
+
                                        console.log("restore selected ids: " + ids);
 
                                        for (var i = 0; i < ids.length; i++) {
@@ -296,7 +308,9 @@ function article_callback2(transport, id) {
 
                request_counters();
 
-               try {
+               headlines_scroll_handler($("headlines-frame"));
+
+/*             try {
                        if (!_infscroll_disable &&
                                        $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
 
@@ -304,7 +318,7 @@ function article_callback2(transport, id) {
                        }
                } catch (e) {
                        console.warn(e);
-               }
+               } */
 
                notify("");
        } catch (e) {
@@ -373,7 +387,7 @@ function view(id) {
                        // the server roundtrip altogether
                        if (cids_to_request.length == 0) {
 
-                               try {
+/*                             try {
                                        if (!_infscroll_disable &&
                                                $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
 
@@ -381,7 +395,9 @@ function view(id) {
                                        }
                                } catch (e) {
                                        console.warn(e);
-                               }
+                               } */
+
+                               headlines_scroll_handler($("headlines-frame"));
 
                                return;
                        }
@@ -838,7 +854,7 @@ function getLoadedArticleIds() {
 
 }
 
-// mode = all,none,unread,invert
+// mode = all,none,unread,invert,marked,published
 function selectArticles(mode) {
        try {
 
@@ -859,6 +875,27 @@ function selectArticles(mode) {
                                        child.removeClassName("Selected");
                                        cb.checked = false;
                                }
+                       } else if (mode == "marked") {
+                               var img = $("FMPIC-" + child.id.replace("RROW-", ""));
+
+                               if (img && img.src.match("mark_set")) {
+                                       child.addClassName("Selected");
+                                       cb.checked = true;
+                               } else {
+                                       child.removeClassName("Selected");
+                                       cb.checked = false;
+                               }
+                       } else if (mode == "published") {
+                               var img = $("FPPIC-" + child.id.replace("RROW-", ""));
+
+                               if (img && img.src.match("pub_set")) {
+                                       child.addClassName("Selected");
+                                       cb.checked = true;
+                               } else {
+                                       child.removeClassName("Selected");
+                                       cb.checked = false;
+                               }
+
                        } else if (mode == "invert") {
                                if (child.hasClassName("Selected")) {
                                        child.removeClassName("Selected");
@@ -1104,8 +1141,9 @@ function headlines_scroll_handler(e) {
                var hsp = $("headlines-spacer");
 
                if (!_infscroll_disable) {
-                       if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
-                                       e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
+                       if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
+                                       (e.scrollHeight != 0 &&
+                                               ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
 
                                if (hsp)
                                        hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
@@ -1154,20 +1192,24 @@ function catchupBatchedArticles() {
        try {
                if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
 
+                       // make a copy of the array
+                       var batch = catchup_id_batch.slice();
                        var query = "?op=rpc&method=catchupSelected" +
-                               "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
+                               "&cmode=0&ids=" + param_escape(batch.toString());
+
+                       console.log(query);
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
 
-                                       catchup_id_batch.each(function(id) {
+                                       batch.each(function(id) {
                                                var elem = $("RROW-" + id);
                                                if (elem) elem.removeClassName("Unread");
+                                               catchup_id_batch.remove(id);
                                        });
 
-                                       catchup_id_batch = [];
                                } });
                }
 
@@ -1780,6 +1822,8 @@ function correctHeadlinesOffset(id) {
                var container = $("headlines-frame");
                var row = $("RROW-" + id);
 
+               if (!container || !row) return;
+
                var viewport = container.offsetHeight;
 
                var rel_offset_top = row.offsetTop - container.scrollTop;
@@ -1917,16 +1961,26 @@ function initHeadlinesMenu() {
                                        label: name,
                                        labelId: bare_id,
                                        onClick: function(event) {
-                                               selectionAssignLabel(this.labelId,
-                                                       [this.getParent().ownerMenu.callerRowId]);
+                                               var ids = getSelectedArticleIds2();
+                                               // cast to string
+                                               var id = this.getParent().ownerMenu.callerRowId + "";
+
+                                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                                               selectionAssignLabel(this.labelId, ids);
                                }}));
 
                                labelDelMenu.addChild(new dijit.MenuItem({
                                        label: name,
                                        labelId: bare_id,
                                        onClick: function(event) {
-                                               selectionRemoveLabel(this.labelId,
-                                                       [this.getParent().ownerMenu.callerRowId]);
+                                               var ids = getSelectedArticleIds2();
+                                               // cast to string
+                                               var id = this.getParent().ownerMenu.callerRowId + "";
+
+                                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                                               selectionRemoveLabel(this.labelId, ids);
                                }}));
 
                        });
@@ -2052,17 +2106,20 @@ function render_local_headlines(feed, is_cat, obj) {
 function precache_headlines_idle() {
        try {
                if (!feed_precache_timeout_id) {
-                       var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
-                       var uncached = [];
+                       if (get_timestamp() - _viewfeed_last > 120) {
 
-                       feeds.each(function(item) {
-                               if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
-                                       uncached.push(item);
-                       });
+                               var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
+                               var uncached = [];
+
+                               feeds.each(function(item) {
+                                       if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
+                                               uncached.push(item);
+                               });
 
-                       if (uncached.length > 0) {
-                               var rf = uncached[Math.floor(Math.random()*uncached.length)];
-                               viewfeed(rf[0], '', rf[1], 0, true);
+                               if (uncached.length > 0) {
+                                       var rf = uncached[Math.floor(Math.random()*uncached.length)];
+                                       viewfeed(rf[0], '', rf[1], 0, true);
+                               }
                        }
                }
                precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);