]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
reduce the number of always included libraries
[tt-rss.git] / viewfeed.js
index daaf57aafaf4939c0ea385a612749909a111678e..9cb902315a714bb5ca4cd8972551ce09993547d3 100644 (file)
@@ -16,18 +16,18 @@ var cids_requested = [];
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
-function headlines_callback2(transport, offset, background) {
+function headlines_callback2(transport, offset, background, infscroll_req) {
        try {
                handle_rpc_json(transport);
 
                loading_set_progress(25);
 
-               console.log("headlines_callback2 [offset=" + offset + "] B:" + background);
+               console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
 
                var is_cat = false;
                var feed_id = false;
 
-               var reply;
+               var reply = false;
 
                try {
                        reply = JSON.parse(transport.responseText);
@@ -41,14 +41,20 @@ function headlines_callback2(transport, offset, background) {
                        feed_id = reply['headlines']['id'];
 
                        if (background) {
-                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], reply['headlines']['content']);
+                               var content = reply['headlines']['content'];
+
+                               if (getInitParam("cdm_auto_catchup") == 1) {
+                                       content = content + "<div id='headlines-spacer'></div>";
+                               }
+
+                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
                                return;
                        }
 
                        setActiveFeedId(feed_id, is_cat);
 
                        try {
-                               if (offset == 0) {
+                               if (offset == 0 && infscroll_req == false) {
                                        $("headlines-frame").scrollTop = 0;
                                }
                        } catch (e) { };
@@ -65,19 +71,21 @@ function headlines_callback2(transport, offset, background) {
 
                        var counters = reply['counters'];
                        var articles = reply['articles'];
-                       var runtime_info = reply['runtime-info'];
+                       //var runtime_info = reply['runtime-info'];
 
-                       if (offset == 0) {
+                       if (offset == 0 && infscroll_req == false) {
                                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"});
 
-                               dijit.byId('headlines-frame').domNode.appendChild(hsp);
+                               if (getInitParam("cdm_auto_catchup") == 1) {
+                                       var hsp = $("headlines-spacer");
+                                       if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
+                                       dijit.byId('headlines-frame').domNode.appendChild(hsp);
+                               }
 
                                initHeadlinesMenu();
 
@@ -109,7 +117,9 @@ function headlines_callback2(transport, offset, background) {
 
                                        fixHeadlinesOrder(getLoadedArticleIds());
 
-                                       c.domNode.appendChild(hsp);
+                                       if (getInitParam("cdm_auto_catchup") == 1) {
+                                               c.domNode.appendChild(hsp);
+                                       }
 
                                        console.log("restore selected ids: " + ids);
 
@@ -394,14 +404,6 @@ function view(id) {
        }
 }
 
-function tMark(id) {
-       return toggleMark(id);
-}
-
-function tPub(id) {
-       return togglePub(id);
-}
-
 function toggleMark(id, client_only) {
        try {
                var query = "?op=rpc&id=" + id + "&subop=mark";
@@ -620,7 +622,7 @@ function toggleUnread(id, cmode, effect) {
 function selectionRemoveLabel(id, ids) {
        try {
 
-               if (!ids) var ids = getSelectedArticleIds2();
+               if (!ids) ids = getSelectedArticleIds2();
 
                if (ids.length == 0) {
                        alert(__("No articles are selected."));
@@ -682,7 +684,7 @@ function selectionToggleUnread(set_state, callback, no_error) {
                        return;
                }
 
-               for (i = 0; i < rows.length; i++) {
+               for (var i = 0; i < rows.length; i++) {
                        var row = $("RROW-" + rows[i]);
                        if (row) {
                                if (set_state == undefined) {
@@ -744,7 +746,7 @@ function selectionToggleMarked() {
                        return;
                }
 
-               for (i = 0; i < rows.length; i++) {
+               for (var i = 0; i < rows.length; i++) {
                        toggleMark(rows[i], true, true);
                }
 
@@ -776,7 +778,7 @@ function selectionTogglePublished() {
                        return;
                }
 
-               for (i = 0; i < rows.length; i++) {
+               for (var i = 0; i < rows.length; i++) {
                        togglePub(rows[i], true, true);
                }
 
@@ -877,7 +879,7 @@ function catchupPage() {
        }
 
        selectArticles('all');
-       selectionToggleUnread(false, 'viewCurrentFeed()', true)
+       selectionToggleUnread(false, 'viewCurrentFeed()', true);
        selectArticles('none');
 }
 
@@ -894,7 +896,6 @@ function deleteSelection() {
 
                var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
                var str;
-               var op;
 
                if (getActiveFeedId() != 0) {
                        str = __("Delete %d selected articles in %s?");
@@ -997,7 +998,7 @@ function catchupSelection() {
                        return;
                }
 
-               selectionToggleUnread(false, 'viewCurrentFeed()', true)
+               selectionToggleUnread(false, 'viewCurrentFeed()', true);
 
        } catch (e) {
                exception_error("catchupSelection", e);
@@ -1093,12 +1094,13 @@ function headlines_scroll_handler(e) {
                        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...");
+                               if (hsp)
+                                       hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
+                                               __("Loading, please wait...");
 
                                loadMoreHeadlines();
+                               return;
 
-                               //viewNextFeedPage();
                        }
                } else {
                        if (hsp) hsp.innerHTML = "";
@@ -1115,13 +1117,18 @@ function headlines_scroll_handler(e) {
 
                                                if (catchup_id_batch.indexOf(id) == -1)
                                                        catchup_id_batch.push(id);
+
+                                               //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
                                        }
                                });
 
-                       if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
+                       if (catchup_id_batch.length > 0) {
                                window.clearTimeout(catchup_timeout_id);
-                               catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
-                                               1000);
+
+                               if (!_infscroll_request_sent) {
+                                       catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
+                                               2000);
+                               }
                        }
                }
 
@@ -1156,12 +1163,13 @@ function catchupBatchedArticles() {
        }
 }
 
-function catchupRelativeToArticle(below) {
+function catchupRelativeToArticle(below, id) {
 
        try {
 
+               if (!id) id = getActiveArticleId();
 
-               if (!getActiveArticleId()) {
+               if (!id) {
                        alert(__("No article is selected."));
                        return;
                }
@@ -1172,7 +1180,7 @@ function catchupRelativeToArticle(below) {
 
                if (!below) {
                        for (var i = 0; i < visible_ids.length; i++) {
-                               if (visible_ids[i] != getActiveArticleId()) {
+                               if (visible_ids[i] != id) {
                                        var e = $("RROW-" + visible_ids[i]);
 
                                        if (e && e.hasClassName("Unread")) {
@@ -1184,7 +1192,7 @@ function catchupRelativeToArticle(below) {
                        }
                } else {
                        for (var i = visible_ids.length-1; i >= 0; i--) {
-                               if (visible_ids[i] != getActiveArticleId()) {
+                               if (visible_ids[i] != id) {
                                        var e = $("RROW-" + visible_ids[i]);
 
                                        if (e && e.hasClassName("Unread")) {
@@ -1299,7 +1307,7 @@ function cdmExpandArticle(id) {
                                                var reply = JSON.parse(transport.responseText);
 
                                                reply.each(function(article) {
-                                                       $("CWRAP-" + article['id']).innerHTML = article['content']
+                                                       $("CWRAP-" + article['id']).innerHTML = article['content'];
                                                        cids_requested.remove(article['id']);
                                                });
                                }});
@@ -1649,7 +1657,7 @@ function getVisibleArticleIds() {
 
 function cdmClicked(event, id) {
        try {
-               var shift_key = event.shiftKey;
+               //var shift_key = event.shiftKey;
 
                hideAuxDlg();
 
@@ -1918,7 +1926,20 @@ function initHeadlinesMenu() {
                                hlOpenInNewTab(event, this.getParent().callerRowId);
                                }}));
 
-//             menu.addChild(new dijit.MenuSeparator());
+               menu.addChild(new dijit.MenuSeparator());
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Mark above as read"),
+                       onClick: function(event) {
+                               catchupRelativeToArticle(0, this.getParent().callerRowId);
+                               }}));
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Mark below as read"),
+                       onClick: function(event) {
+                               catchupRelativeToArticle(1, this.getParent().callerRowId);
+                               }}));
+
 
                var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
 
@@ -2169,7 +2190,7 @@ function precache_headlines_idle() {
                                viewfeed(rf[0], '', rf[1], 0, true);
                        }
                }
-               precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 5000);
+               precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
 
        } catch (e) {
                exception_error("precache_headlines_idle", e);