]> git.wh0rd.org - tt-rss.git/commitdiff
implement CDM auto-catchup for articles
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 25 Jan 2007 09:12:33 +0000 (10:12 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 25 Jan 2007 09:12:33 +0000 (10:12 +0100)
backend.php
viewfeed.js

index 71bbcea4029223428e6caeb9a7e662da84225bd8..223842f349ad609689cd50a3e018f26e37876ecb 100644 (file)
 
                                        print "<div class=\"cdmHeader\">";
 
-                                       print "<div style=\"float : right\">$updated_fmt,
-                                               <a class=\"cdmToggleLink\"
-                                                       href=\"javascript:toggleUnread($id)\">Toggle unread</a>
+                                       print "<div style=\"float : right\">$updated_fmt $id
+                                               <!-- <a class=\"cdmToggleLink\"
+                                                       href=\"javascript:toggleUnread($id)\">Toggle unread</a> -->
                                        </div>";
                                        
                                        print "<a class=\"title\" 
index d89cac347eb7bce680f4da4c845cfd107abfdde5..987fa10637513ea016b0166d6319a00e0908fbc1 100644 (file)
@@ -9,6 +9,9 @@ var _tag_active_feed_id = false;
 // FIXME: kludge, needs proper implementation
 var _reload_feedlist_after_view = false;
 
+var _cdm_wd_timeout = false;
+var _cdm_wd_vishist = new Array();
+
 function catchup_callback() {
        if (xmlhttp_rpc.readyState == 4) {
                try {
@@ -35,6 +38,15 @@ function headlines_callback() {
                if (typeof correctPNG != 'undefined') {
                        correctPNG();
                }
+
+               if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
+
+               if (!document.getElementById("headlinesList")) {
+                       debug("starting CDM watchdog");
+                       _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
+                       _cdm_wd_vishist = new Array();
+               }
+
                notify("");
        }
 }
@@ -514,3 +526,72 @@ function editTagsInsert() {
                exception_error(e, "editTagsInsert");
        }
 }
+
+function cdmWatchdog() {
+
+       try {
+
+               var ctr = document.getElementById("headlinesInnerContainer");
+
+               if (!ctr.hasChildNodes()) return;
+
+               var ids = new Array();
+
+               var e = ctr.firstChild;
+
+               while (e) {
+                       if (e.className && e.className == "cdmArticleUnread" && e.id &&
+                                       e.id.match("RROW-")) {
+
+                               // article fits in viewport OR article is longer than viewport and
+                               // its bottom is visible
+
+                               if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
+                                               ctr.scrollTop + ctr.offsetHeight) {
+
+//                                     debug(e.id + " is visible " + e.offsetTop + "." + 
+//                                             (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
+//                                             (ctr.scrollTop + ctr.offsetHeight));
+
+                                       ids.push(e.id.replace("RROW-", ""));
+
+                               } else if (e.offsetHeight > ctr.offsetHeight &&
+                                               e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
+                                               e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
+
+                                       ids.push(e.id.replace("RROW-", "")); 
+
+                               }
+
+                       }
+
+                       e = e.nextSibling;
+               }
+
+               debug("cdmWatchdog, ids= " + ids.toString());
+
+               if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
+
+                       for (var i = 0; i < ids.length; i++) {
+                               var e = document.getElementById("RROW-" + ids[i]);
+                               if (e) {
+                                       e.className = e.className.replace("Unread", "");
+                               }
+                       }
+
+                       var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
+                               param_escape(ids.toString()) + "&cmode=0";
+
+/*                     xmlhttp_rpc.open("GET", query, true);
+                       xmlhttp_rpc.onreadystatechange=all_counters_callback;
+                       xmlhttp_rpc.send(null);  */
+
+               }
+
+               _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
+
+       } catch (e) {
+               exception_error(e, "cdmWatchdog");
+       }
+
+}