]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
viewfeed: do not return sync counters on subop
[tt-rss.git] / viewfeed.js
index a5ca881c6d326fbbf9c13c3e971ba2a56882c8a5..3a21323da1f208b92d8bd2811d298796d7e1c8c7 100644 (file)
@@ -14,13 +14,16 @@ var preload_timeout_id = false;
 
 var cache_added = [];
 
-function headlines_callback2(transport, feed_cur_page) {
+var catchup_id_batch = [];
+var catchup_timeout_id = false;
+
+function headlines_callback2(transport, offset) {
        try {
                handle_rpc_json(transport);
 
                loading_set_progress(25);
 
-               console.log("headlines_callback2 [page=" + feed_cur_page + "]");
+               console.log("headlines_callback2 [offset=" + offset + "]");
 
                var is_cat = false;
                var feed_id = false;
@@ -45,7 +48,7 @@ function headlines_callback2(transport, feed_cur_page) {
                        update_btn.disabled = !(feed_id >= 0 && !is_cat);
 
                        try {
-                               if (feed_cur_page == 0) {
+                               if (offset == 0) {
                                        $("headlines-frame").scrollTop = 0;
                                }
                        } catch (e) { };
@@ -65,13 +68,22 @@ function headlines_callback2(transport, feed_cur_page) {
                        var articles = reply['articles'];
                        var runtime_info = reply['runtime-info'];
 
-                       if (feed_cur_page == 0) {
+                       if (offset == 0) {
                                dijit.byId("headlines-frame").attr('content',
                                        reply['headlines']['content']);
 
                                dijit.byId("headlines-toolbar").attr('content',
                                        reply['headlines']['toolbar']);
 
+                               var hsp = $("headlines-spacer");
+                               if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
+
+/*                             if (!_infscroll_disable)
+                                       hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
+                                               __("Loading, please wait..."); */
+
+                               dijit.byId('headlines-frame').domNode.appendChild(hsp);
+
                                initHeadlinesMenu();
 
                        } else {
@@ -83,10 +95,26 @@ function headlines_callback2(transport, feed_cur_page) {
 
                                        $("headlines-tmp").innerHTML = reply['headlines']['content'];
 
+                                       var hsp = $("headlines-spacer");
+
+                                       if (hsp)
+                                               c.domNode.removeChild(hsp);
+
                                        $$("#headlines-tmp > div").each(function(row) {
+                                               row.style.display = 'none';
                                                c.domNode.appendChild(row);
                                        });
 
+                                       if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
+
+/*                                     if (!_infscroll_disable)
+                                               hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
+                                                       __("Loading, please wait..."); */
+
+                                       fixHeadlinesOrder(getLoadedArticleIds());
+
+                                       c.domNode.appendChild(hsp);
+
                                        console.log("restore selected ids: " + ids);
 
                                        for (var i = 0; i < ids.length; i++) {
@@ -95,8 +123,18 @@ function headlines_callback2(transport, feed_cur_page) {
 
                                        initHeadlinesMenu();
 
+                                       $$("#headlines-frame > div[id*=RROW]").each(
+                                       function(child) {
+                                               if (!Element.visible(child))
+                                                       new Effect.Appear(child, { duration : 0.5 });
+                                       });
+
                                } else {
                                        console.log("no new headlines received");
+
+                                       var hsp = $("headlines-spacer");
+
+                                       if (hsp) hsp.innerHTML = "";
                                }
                        }
 
@@ -120,7 +158,7 @@ function headlines_callback2(transport, feed_cur_page) {
                                        __('Could not update headlines (invalid object received)') + "</div>");
                }
 
-               _feed_cur_page = feed_cur_page;
+               //_feed_cur_page = feed_cur_page;
                _infscroll_request_sent = 0;
 
                notify("");
@@ -324,6 +362,8 @@ function view(id) {
 
                last_requested_article = id;
 
+               console.log(query);
+
                new Ajax.Request("backend.php", {
                        parameters: query,
                        onComplete: function(transport) {
@@ -992,10 +1032,10 @@ function editArticleTags(id) {
                                                        var id = tags_str.id;
 
                                                        var tags = $("ATSTR-" + id);
+                                                       var tooltip = dijit.byId("ATSTRTIP-" + id);
 
-                                                       if (tags) {
-                                                               tags.innerHTML = tags_str.content;
-                                                       }
+                                                       if (tags) tags.innerHTML = tags_str.content;
+                                                       if (tooltip) tooltip.attr('label', tags_str.content_full);
 
                                                        cache_invalidate(id);
                                                }
@@ -1236,7 +1276,7 @@ function preloadBatchedArticles() {
                                        var id = articles[i]['id'];
                                        if (!cache_check(id)) {
                                                cache_inject(id, articles[i]['content']);
-                                               console.log("preloaded article: " + id);
+                                               //console.log("preloaded article: " + id);
                                        }
                                }
                } });
@@ -1252,7 +1292,7 @@ function preloadArticleUnderPointer(id) {
 
                if (post_under_pointer == id && !cache_check(id)) {
 
-                       console.log("trying to preload article " + id);
+                       //console.log("trying to preload article " + id);
 
                        var neighbor_ids = getRelativePostIds(id, 1);
 
@@ -1304,46 +1344,72 @@ function postMouseOut(id) {
 
 function headlines_scroll_handler(e) {
        try {
+               var hsp = $("headlines-spacer");
+
+               if (!_infscroll_disable) {
+                       if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
+                                       e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
+
+                               hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
+                                       __("Loading, please wait...");
+
+                               loadMoreHeadlines();
 
-               if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
-                       if (!_infscroll_disable) {
-                               viewNextFeedPage();
+                               //viewNextFeedPage();
                        }
+               } else {
+                       if (hsp) hsp.innerHTML = "";
                }
 
-
                if (getInitParam("cdm_auto_catchup") == 1) {
 
-                       var ids = [];
-
                        $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
                                function(child) {
                                        if ($("headlines-frame").scrollTop >
-                                                       (child.offsetTop + child.offsetHeight)) {
+                                                       (child.offsetTop + child.offsetHeight/2)) {
 
-                                               ids.push(child.id.replace("RROW-", ""));
+                                               var id = child.id.replace("RROW-", "");
+
+                                               if (catchup_id_batch.indexOf(id) == -1)
+                                                       catchup_id_batch.push(id);
                                        }
                                });
 
-                       if (ids.length > 0) {
+                       if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
+                               window.clearTimeout(catchup_timeout_id);
+                               catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
+                                               1000);
+                       }
+               }
 
-                               var query = "?op=rpc&subop=catchupSelected" +
-                                       "&cmode=0&ids=" + param_escape(ids.toString());
+       } catch (e) {
+               exception_error("headlines_scroll_handler", e);
+       }
+}
 
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function(transport) {
-                                               handle_rpc_json(transport);
+function catchupBatchedArticles() {
+       try {
+               if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
 
-                                               ids.each(function(id) {
-                                                       var elem = $("RROW-" + id);
-                                                       if (elem) elem.removeClassName("Unread");
-                                               });
-                                       } });
-                       }
+                       var query = "?op=rpc&subop=catchupSelected" +
+                               "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       handle_rpc_json(transport);
+
+                                       catchup_id_batch.each(function(id) {
+                                               var elem = $("RROW-" + id);
+                                               if (elem) elem.removeClassName("Unread");
+                                       });
+
+                                       catchup_id_batch = [];
+                               } });
                }
+
        } catch (e) {
-               exception_error("headlines_scroll_handler", e);
+               exception_error("catchupBatchedArticles", e);
        }
 }
 
@@ -1536,6 +1602,9 @@ function zoomToArticle(event, id) {
                        if (!event || !event.shiftKey)
                                return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
 
+               if (dijit.byId("ATSTRTIP-" + id))
+                       dijit.byId("ATSTRTIP-" + id).destroyRecursive();
+
                if (cached_article) {
                        //closeArticlePanel();