]> git.wh0rd.org Git - tt-rss.git/commitdiff
fix some issues in infinite scrolling
authorAndrew Dolgov <fox@madoka.spb.ru>
Fri, 24 Aug 2007 05:31:57 +0000 (06:31 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Fri, 24 Aug 2007 05:31:57 +0000 (06:31 +0100)
backend.php
feedlist.js
functions.php
viewfeed.js

index 0e4541e74c069f87a6291505c172e64bf84998c1..3783c82266b3206951d8b5ad9208ce6b3d7b9902 100644 (file)
 
                print "<headlines id=\"$feed\"><![CDATA[";
 
-               $topmost_article_ids = outputHeadlinesList($link, $feed, $subop, 
+               $ret = outputHeadlinesList($link, $feed, $subop, 
                        $view_mode, $limit, $cat_view, $next_unread_feed, $offset);
 
+               $topmost_article_ids = $ret[0];
+               $headlines_count = $ret[1];
+
                print "]]></headlines>";
 
+               print "<headlines-count value=\"$headlines_count\"/>";
+
                if ($_GET["debug"]) $timing_info = print_checkpoint("10", $timing_info);
 
                if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE')) {
index c78a47d5cb2ac7672bac25948113b1fef00a3758..70e436897e7fa06dfeccd7cd90ef6891273420d5 100644 (file)
@@ -1,6 +1,7 @@
 //var xmlhttp = Ajax.getTransport();
 
 var _feed_cur_page = 0;
+var _infscroll_disable = 0;
 
 function viewCategory(cat) {
        active_feed_is_cat = true;
@@ -25,35 +26,14 @@ function feedlist_callback2(transport) {
        }
 }
 
-var page_offset = 0;
-
-function viewFeedGoPage(i) {
-       try {
-               if (!getActiveFeedId()) return;
-
-               if (i != 0) {
-                       page_offset = page_offset + i;
-               } else {
-                       page_offset = 0;
-               }
-
-               if (page_offset < 0) page_offset = 0;
-               viewfeed(getActiveFeedId(), undefined, undefined, undefined,
-                       undefined, page_offset);
-       } catch (e) {
-               exception_error(e, "viewFeedGoPage");
-       }
-}
-
-
 function viewNextFeedPage() {
        try {
                if (!getActiveFeedId()) return;
 
-               _feed_cur_page++;
+               notify_progress("Loading, please wait...");
 
                viewfeed(getActiveFeedId(), undefined, undefined, undefined,
-                       undefined, _feed_cur_page);
+                       undefined, _feed_cur_page+1);
 
        } catch (e) {
                exception_error(e, "viewFeedGoPage");
@@ -72,11 +52,13 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
                } else {
                        page_offset = 0;
                        _feed_cur_page = 0;
+                       _infscroll_disable = 0;
                }
 
                if (getActiveFeedId() != feed) {
                        _feed_cur_page = 0;
                        active_post_id = 0;
+                       _infscroll_disable = 0;
                }
 
                enableHotkeys();
@@ -187,8 +169,9 @@ function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
                }  */
 
                new Ajax.Request(query, {
+                       asynchronous: page_offset == 0,
                        onComplete: function(transport) { 
-                               headlines_callback2(transport, feed, is_cat, _feed_cur_page); 
+                               headlines_callback2(transport, feed, is_cat, page_offset); 
                        } });
 
        } catch (e) {
index f2fa61b6f1c3fd23c8f520711bedd7f0a312d92a..40abd41329128e9089fbdbd205c163561f00a27a 100644 (file)
                        print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
                }
 
+               $headlines_count = db_num_rows($result);
+
                if (db_num_rows($result) > 0) {
 
 #                      print "\{$offset}";
                        print "</div>";
                }
 
-               return $topmost_article_ids;
+               return array($topmost_article_ids, $headlines_count);
        }
 
 // from here: http://www.roscripts.com/Create_tag_cloud-71.html
index 197b7648bc68a0c8e1bdcabd0fcda9a5311366c2..a69c012a23d7c1c7f6f5b89575e832ff36d5c31e 100644 (file)
@@ -46,7 +46,8 @@ function catchup_callback2(transport, callback) {
 }
 
 function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed_cur_page) {
-       debug("headlines_callback2");
+       debug("headlines_callback2 [page=" + feed_cur_page + "]");
+
        var f = document.getElementById("headlines-frame");
        try {
                if (feed_cur_page == 0) { 
@@ -57,6 +58,12 @@ function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed
 
        if (transport.responseXML) {
                var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
+               var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
+
+               var headlines_count = headlines_count_obj.getAttribute("value");
+
+               if (headlines_count == 0) _infscroll_disable = 1;
+
                var counters = transport.responseXML.getElementsByTagName("counters")[0];
                var articles = transport.responseXML.getElementsByTagName("article");
                var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
@@ -71,15 +78,19 @@ function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed
                        }
                } else {
                        if (headlines) {
-                               debug("adding some more headlines...");
+                               if (headlines_count > 0) {
+                                       debug("adding some more headlines...");
 
-                               var c = document.getElementById("headlinesList");
+                                       var c = document.getElementById("headlinesList");
+       
+                                       if (!c) {
+                                               c = document.getElementById("headlinesInnerContainer");
+                                       }
 
-                               if (!c) {
-                                       c = document.getElementById("headlinesInnerContainer");
+                                       c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
+                               } else {
+                                       debug("no new headlines received");
                                }
-
-                               c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
                        } else {
                                debug("headlines_callback: returned no data");
                                notify_error("Error while trying to load more headlines");      
@@ -140,6 +151,8 @@ function headlines_callback2(transport, active_feed_id, active_feed_is_cat, feed
                } catch (e) { }
        }
 
+       _feed_cur_page = feed_cur_page;
+
        notify("");
 }
 
@@ -1244,9 +1257,10 @@ function headlines_scroll_handler() {
                var e = document.getElementById("headlinesInnerContainer");
 
                if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) {
-                       debug("more cowbell!");
-
-                       viewNextFeedPage();
+                       if (!_infscroll_disable) {
+                               debug("more cowbell!");
+                               viewNextFeedPage();
+                       }
                }
 
        } catch (e) {