]> git.wh0rd.org - tt-rss.git/commitdiff
infinite scrolling
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 9 Aug 2007 07:36:04 +0000 (08:36 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 9 Aug 2007 07:36:04 +0000 (08:36 +0100)
feedlist.js
functions.php
viewfeed.js

index ac852e9e9cad11276919e315edcbd65e12855983..66b040f9f8f9351f4d9d872a48ceeecdf2552468 100644 (file)
@@ -1,5 +1,7 @@
 //var xmlhttp = Ajax.getTransport();
 
+var feed_cur_page = 0;
+
 function viewCategory(cat) {
        active_feed_is_cat = true;
        viewfeed(cat, '', true);
@@ -35,13 +37,35 @@ function viewFeedGoPage(i) {
        }
 }
 
+
+function viewNextFeedPage() {
+       try {
+               if (!getActiveFeedId()) return;
+
+               feed_cur_page++;
+
+               viewfeed(getActiveFeedId(), undefined, undefined, undefined,
+                       undefined, feed_cur_page);
+
+       } catch (e) {
+               exception_error(e, "viewFeedGoPage");
+       }
+}
+
 function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
        try {
 
-               //if (!offset) page_offset = 0;
+//             if (!offset) page_offset = 0;
 
-               if (offset != undefined) {
+               if (offset > 0) {
                        page_offset = offset;
+               } else {
+                       page_offset = 0;
+                       feed_cur_page = 0;
+               }
+
+               if (getActiveFeedId() != feed) {
+                       feed_cur_page = 0;
                }
 
                enableHotkeys();
index 3bf2a0b7d03e12178a65903f9bb075022f858ef7..7ca93956dca3afd68fa5956b1a0710f87b308bbc 100644 (file)
 
                $topmost_article_ids = array();
 
-               if (!$offset) $offset = 0;
+               if (!$offset) {
+                       $offset = 0;
+               }
 
                if ($subop == "undefined") $subop = "";
 
                
                /// STOP //////////////////////////////////////////////////////////////////////////////////
 
-               print "<div id=\"headlinesContainer\" $rtl_tag>";
+               if (!$offset) {
+                       print "<div id=\"headlinesContainer\" $rtl_tag>";
 
-               if (!$result) {
-                       print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
-                       return;
-               }
+                       if (!$result) {
+                               print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
+                               return;
+                       }
 
-               print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, 
-                       $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode, 
-                       $offset, $limit);
+                       print_headline_subtoolbar($link, $feed_site_url, $feed_title, false, 
+                               $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode, 
+                               $offset, $limit);
 
-               print "<div id=\"headlinesInnerContainer\">";
+                       print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
+               }
 
                if (db_num_rows($result) > 0) {
 
 #                      print "\{$offset}";
 
-                       if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
+                       if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
                                print "<table class=\"headlinesList\" id=\"headlinesList\" 
                                        cellspacing=\"0\">";
                        }
                                ++$lnum;
                        }
 
-                       if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {                        
+                       if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {                    
                                print "</table>";
                        }
 
 
 
                } else {
-                       print "<div class='whiteBox'>".__('No articles found.')."</div>";
+                       if (!$offset) print "<div class='whiteBox'>".__('No articles found.')."</div>";
                }
 
-               print "</div>";
-
-               print "</div>";
+               if (!$offset) {
+                       print "</div>";
+                       print "</div>";
+               }
 
                return $topmost_article_ids;
        }
index 1a3d775ffde67dd8e479dbf6b6b71f0efd2241a5..e464f21981fbb1b7f42eb51eb70cb2b38dfb2314 100644 (file)
@@ -38,7 +38,10 @@ function headlines_callback() {
                debug("headlines_callback");
                var f = document.getElementById("headlines-frame");
                try {
-                       f.scrollTop = 0;
+                       if (feed_cur_page == 0) { 
+                               debug("resetting headlines scrollTop");
+                               f.scrollTop = 0; 
+                       }
                } catch (e) { };
 
                if (xmlhttp.responseXML) {
@@ -47,11 +50,29 @@ function headlines_callback() {
                        var articles = xmlhttp.responseXML.getElementsByTagName("article");
                        var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info");
 
-                       if (headlines) {
-                               f.innerHTML = headlines.firstChild.nodeValue;
+                       if (feed_cur_page == 0) {
+                               if (headlines) {
+                                       f.innerHTML = headlines.firstChild.nodeValue;
+                               } else {
+                                       debug("headlines_callback: returned no data");
+                               f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
+       
+                               }
                        } else {
-                               debug("headlines_callback: returned no data");
-                       f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
+                               if (headlines) {
+                                       debug("adding some more headlines...");
+
+                                       var c = document.getElementById("headlinesList");
+
+                                       if (!c) {
+                                               c = document.getElementById("headlinesInnerContainer");
+                                       }
+
+                                       c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
+                               } else {
+                                       debug("headlines_callback: returned no data");
+                                       notify_error("Error while trying to load more headlines");      
+                               }
 
                        }
 
@@ -103,6 +124,8 @@ function headlines_callback() {
                        try {
                                document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
                                _tag_cdm_scroll = false;
+                               debug("resetting headlinesInner scrollTop");
+
                        } catch (e) { }
                }
 
@@ -937,3 +960,19 @@ function cdmMouseIn(elem) {
 function cdmMouseOut(elem) {
        active_post_id = false;
 }
+
+function headlines_scroll_handler() {
+       try {
+
+               var e = document.getElementById("headlinesInnerContainer");
+
+               if (e.scrollTop + e.offsetHeight == e.scrollHeight) {
+                       debug("more cowbell!");
+
+                       viewNextFeedPage();
+               }
+
+       } catch (e) {
+               exception_error("headlines_scroll_handler", e);
+       }
+}