]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
infinite scrolling
[tt-rss.git] / viewfeed.js
index 604af1bae02c020a114787ca3933c0a83fbf27d7..e464f21981fbb1b7f42eb51eb70cb2b38dfb2314 100644 (file)
@@ -22,11 +22,11 @@ function catchup_callback() {
        if (xmlhttp_rpc.readyState == 4) {
                try {
                        debug("catchup_callback");
-                       if (_catchup_callback_func) {
-                               setTimeout(_catchup_callback_func, 100);        
-                       }
                        notify("");                     
                        all_counters_callback();
+                       if (_catchup_callback_func) {
+                               setTimeout(_catchup_callback_func, 10); 
+                       }
                } catch (e) {
                        exception_error("catchup_callback", e);
                }
@@ -38,19 +38,41 @@ 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) {
                        var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0];
                        var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0];
                        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");      
+                               }
 
                        }
 
@@ -70,6 +92,14 @@ function headlines_callback() {
                        } else {
                                debug("counters container not found in reply");
                        }
+
+                       if (runtime_info) {
+                               debug("parsing runtime info: " + runtime_info[0]);
+                               parse_runtime_info(runtime_info[0]);
+                       } else {
+                               debug("counters container not found in reply");
+                       }
+
                } else {
                        debug("headlines_callback: returned no XML object");
                        f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
@@ -94,6 +124,8 @@ function headlines_callback() {
                        try {
                                document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
                                _tag_cdm_scroll = false;
+                               debug("resetting headlinesInner scrollTop");
+
                        } catch (e) { }
                }
 
@@ -182,10 +214,6 @@ function view(id, feed_id, skip_history) {
                var cached_article = cache_find(id);
 
                debug("cache check result: " + (cached_article != false));
-
-/*             if (!skip_history) {
-                       history_push("ARTICLE:" + id + ":" + feed_id);
-               } */
        
                enableHotkeys();
        
@@ -199,6 +227,10 @@ function view(id, feed_id, skip_history) {
                if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
                        debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
                        xmlhttp.abort();
+                       if (is_safari()) {
+                               debug("trying alternative reset method for Safari");
+                               xmlhttp = Ajax.getTransport();
+                       }
                }
 
                if (xmlhttp_ready(xmlhttp)) {
@@ -638,6 +670,14 @@ function cdmSelectArticles(mode) {
 
 function catchupPage() {
 
+       var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
+       
+       var str = "Mark all visible articles in " + fn + " as read?";
+
+       if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
+               return;
+       }
+
        if (document.getElementById("headlinesList")) {
                selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
                selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
@@ -727,7 +767,11 @@ function editTagsSave() {
 
        var query = Form.serialize("tag_edit_form");
 
-       xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);                      
+       query = "backend.php?op=rpc&subop=setArticleTags&" + query;
+
+       debug(query);
+
+       xmlhttp_rpc.open("GET", query, true);                   
        xmlhttp_rpc.onreadystatechange=tag_saved_callback;
        xmlhttp_rpc.send(null);
 
@@ -896,3 +940,39 @@ function cache_invalidate(id) {
                exception_error("cache_invalidate", e);
        }
 }
+
+function getActiveArticleId() {
+       return active_post_id;
+}
+
+function cdmMouseIn(elem) {
+       try {
+               if (elem.id && elem.id.match("RROW-")) {
+                       var id = elem.id.replace("RROW-", "");
+                       active_post_id = id;
+               }
+       } catch (e) {
+               exception_error("cdmMouseIn", e);
+       }
+
+}
+
+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);
+       }
+}