]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
reduce the number of always included libraries
[tt-rss.git] / viewfeed.js
index c36b06a618593d270e15becb3b25d31135a23248..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,24 +71,27 @@ 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();
 
                        } else {
-                               if (headlines_count > 0) {
+
+                               if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
                                        console.log("adding some more headlines...");
 
                                        var c = dijit.byId("headlines-frame");
@@ -99,6 +108,8 @@ function headlines_callback2(transport, offset, background) {
                                                if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
                                                        row.style.display = 'none';
                                                        c.domNode.appendChild(row);
+                                               } else {
+                                                       row.parentNode.removeChild(row);
                                                }
                                        });
 
@@ -106,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);
 
@@ -153,9 +166,10 @@ function headlines_callback2(transport, offset, background) {
                                request_counters();
 
                } else {
-                       console.warn("headlines_callback: returned no XML object");
+                       console.error("Invalid object received: " + transport.responseText);
                        dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
-                                       __('Could not update headlines (invalid object received)') + "</div>");
+                                       __('Could not update headlines (invalid object received - see error console for details)') +
+                                       "</div>");
                }
 
                _infscroll_request_sent = 0;
@@ -245,7 +259,13 @@ function article_callback2(transport, id) {
 
                handle_rpc_json(transport);
 
-               var reply = JSON.parse(transport.responseText);
+               var reply = false;
+
+               try {
+                       reply = JSON.parse(transport.responseText);
+               } catch (e) {
+                       console.error(e);
+               }
 
                if (reply) {
 
@@ -268,10 +288,10 @@ function article_callback2(transport, id) {
 //                     }
 
                } else {
-                       console.warn("article_callback: returned invalid data");
+                       console.error("Invalid object received: " + transport.responseText);
 
                        render_article("<div class='whiteBox'>" +
-                                       __('Could not display article (invalid data received)') + "</div>");
+                                       __('Could not display article (invalid object received - see error console for details)') + "</div>");
                }
 
                request_counters();
@@ -384,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";
@@ -610,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."));
@@ -672,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) {
@@ -734,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);
                }
 
@@ -766,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);
                }
 
@@ -867,7 +879,7 @@ function catchupPage() {
        }
 
        selectArticles('all');
-       selectionToggleUnread(false, 'viewCurrentFeed()', true)
+       selectionToggleUnread(false, 'viewCurrentFeed()', true);
        selectArticles('none');
 }
 
@@ -884,7 +896,6 @@ function deleteSelection() {
 
                var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
                var str;
-               var op;
 
                if (getActiveFeedId() != 0) {
                        str = __("Delete %d selected articles in %s?");
@@ -987,7 +998,7 @@ function catchupSelection() {
                        return;
                }
 
-               selectionToggleUnread(false, 'viewCurrentFeed()', true)
+               selectionToggleUnread(false, 'viewCurrentFeed()', true);
 
        } catch (e) {
                exception_error("catchupSelection", e);
@@ -1083,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 = "";
@@ -1105,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);
+                               }
                        }
                }
 
@@ -1146,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;
                }
@@ -1162,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")) {
@@ -1174,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")) {
@@ -1289,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']);
                                                });
                                }});
@@ -1639,7 +1657,7 @@ function getVisibleArticleIds() {
 
 function cdmClicked(event, id) {
        try {
-               var shift_key = event.shiftKey;
+               //var shift_key = event.shiftKey;
 
                hideAuxDlg();
 
@@ -1908,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);
 
@@ -2159,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);
@@ -2183,7 +2214,6 @@ function precache_headlines() {
                                window.setTimeout(function() {
                                        feed_precache_timeout_id = false;
                                        }, 3000);
-
                        }, 1000);
                }
 
@@ -2191,3 +2221,25 @@ function precache_headlines() {
                exception_error("precache_headlines", e);
        }
 }
+
+function shareArticle(id) {
+       try {
+               if (dijit.byId("shareArticleDlg"))
+                       dijit.byId("shareArticleDlg").destroyRecursive();
+
+               var query = "backend.php?op=dlg&id=shareArticle&param=" + param_escape(id);
+
+               dialog = new dijit.Dialog({
+                       id: "shareArticleDlg",
+                       title: __("Share article by URL"),
+                       style: "width: 600px",
+                       href: query});
+
+               dialog.show();
+
+       } catch (e) {
+               exception_error("emailArticle", e);
+       }
+}
+
+