]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
Merge pull request #134 from sunjayc99/master
[tt-rss.git] / js / viewfeed.js
index c1163eab773e1b3d6ac22be6ceebf61de71c6c70..db1a4bf94c982bba1c9eb1b8f2a93853876c6db3 100644 (file)
@@ -12,6 +12,7 @@ var catchup_timeout_id = false;
 
 var cids_requested = [];
 var loaded_article_ids = [];
+var _last_headlines_update = 0;
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -48,7 +49,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                return;
                        }
 
-                       setActiveFeedId(feed_id, is_cat);
+                       if (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat())
+                               return;
 
                        /* dijit.getEnclosingWidget(
                                document.forms["main_toolbar_form"].update).attr('disabled',
@@ -204,6 +206,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                }
 
                _infscroll_request_sent = 0;
+               _last_headlines_update = new Date().getTime();
 
                unpackVisibleHeadlines();
 
@@ -238,7 +241,7 @@ function render_article(article) {
        }
 }
 
-function showArticleInHeadlines(id) {
+function showArticleInHeadlines(id, noexpand) {
 
        try {
                selectArticles("none");
@@ -249,7 +252,8 @@ function showArticleInHeadlines(id) {
 
                var article_is_unread = crow.hasClassName("Unread");
 
-               crow.removeClassName("Unread");
+               if (!noexpand)
+                       crow.removeClassName("Unread");
                crow.addClassName("active");
 
                selectArticles('none');
@@ -265,7 +269,7 @@ function showArticleInHeadlines(id) {
 
                markHeadline(id);
 
-               if (article_is_unread)
+               if (article_is_unread && !noexpand)
                        _force_scheduled_update = true;
 
        } catch (e) {
@@ -333,7 +337,7 @@ function article_callback2(transport, id) {
        }
 }
 
-function view(id) {
+function view(id, activefeed, noexpand) {
        try {
                var oldrow = $("RROW-" + getActiveArticleId());
                if (oldrow) oldrow.removeClassName("active");
@@ -341,6 +345,11 @@ function view(id) {
                var crow = $("RROW-" + id);
 
                if (!crow) return;
+               if (noexpand) {
+                       setActiveArticleId(id);
+                       showArticleInHeadlines(id, noexpand);
+                       return;
+               }
 
                console.log("loading article: " + id);
 
@@ -496,7 +505,7 @@ function togglePub(id, client_only, no_effects, note) {
        }
 }
 
-function moveToPost(mode, noscroll) {
+function moveToPost(mode, noscroll, noexpand) {
 
        try {
 
@@ -543,13 +552,13 @@ function moveToPost(mode, noscroll) {
                                                scrollArticle(ctr.offsetHeight/4);
 
                                        } else if (next_id) {
-                                               cdmExpandArticle(next_id);
+                                               cdmExpandArticle(next_id, noexpand);
                                                cdmScrollToArticleId(next_id, true);
                                        }
 
                                } else if (next_id) {
                                        correctHeadlinesOffset(next_id);
-                                       view(next_id, getActiveFeedId());
+                                       view(next_id, getActiveFeedId(), noexpand);
                                }
                        }
                }
@@ -567,7 +576,7 @@ function moveToPost(mode, noscroll) {
                                                if (!noscroll && article.offsetTop < ctr.scrollTop) {
                                                        scrollArticle(-ctr.offsetHeight/4);
                                                } else {
-                                                       cdmExpandArticle(prev_id);
+                                                       cdmExpandArticle(prev_id, noexpand);
                                                        cdmScrollToArticleId(prev_id, true);
                                                }
                                        } else {
@@ -576,17 +585,17 @@ function moveToPost(mode, noscroll) {
                                                        scrollArticle(-ctr.offsetHeight/3);
                                                } else if (!noscroll && prev_article &&
                                                                prev_article.offsetTop < ctr.scrollTop) {
-                                                       cdmExpandArticle(prev_id);
+                                                       cdmExpandArticle(prev_id, noexpand);
                                                        scrollArticle(-ctr.offsetHeight/4);
                                                } else if (prev_id) {
-                                                       cdmExpandArticle(prev_id);
+                                                       cdmExpandArticle(prev_id, noexpand);
                                                        cdmScrollToArticleId(prev_id, noscroll);
                                                }
                                        }
 
                                } else if (prev_id) {
                                        correctHeadlinesOffset(prev_id);
-                                       view(prev_id, getActiveFeedId());
+                                       view(prev_id, getActiveFeedId(), noexpand);
                                }
                        }
                }
@@ -1159,7 +1168,6 @@ function postMouseOut(id) {
 
 function unpackVisibleHeadlines() {
        try {
-
                if (!isCdmMode()) return;
 
                $$("#headlines-frame > div[id*=RROW]").each(
@@ -1178,7 +1186,6 @@ function unpackVisibleHeadlines() {
                        }
                );
 
-
        } catch (e) {
                exception_error("unpackVisibleHeadlines", e);
        }
@@ -1209,6 +1216,10 @@ function headlines_scroll_handler(e) {
 
                if (getInitParam("cdm_auto_catchup") == 1) {
 
+                       // let's get DOM some time to settle down
+                       var ts = new Date().getTime();
+                       if (ts - _last_headlines_update < 100) return;
+
                        $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
                                function(child) {
                                        if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
@@ -1254,7 +1265,11 @@ function catchupBatchedArticles() {
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
 
+                                       reply = JSON.parse(transport.responseText);
+                                       var batch = reply.ids;
+
                                        batch.each(function(id) {
+                                               console.log(id);
                                                var elem = $("RROW-" + id);
                                                if (elem) elem.removeClassName("Unread");
                                                catchup_id_batch.remove(id);
@@ -1366,7 +1381,28 @@ function cdmCollapseArticle(event, id) {
        }
 }
 
-function cdmExpandArticle(id) {
+function cdmUnexpandArticle(event, id) {
+       try {
+               var row = $("RROW-" + id);
+               var elem = $("CICD-" + id);
+
+               if (elem && row) {
+                       var collapse = $$("div#RROW-" + id +
+                               " span[class='collapseBtn']")[0];
+
+                       Element.hide(elem);
+                       Element.show("CEXC-" + id);
+                       Element.hide(collapse);
+
+                       if (event) Event.stop(event);
+               }
+
+       } catch (e) {
+               exception_error("cdmUnexpandArticle", e);
+       }
+}
+
+function cdmExpandArticle(id, noexpand) {
        try {
                console.log("cdmExpandArticle " + id);
 
@@ -1403,7 +1439,7 @@ function cdmExpandArticle(id) {
 
                var cencw = $("CENCW-" + id);
 
-               if (!Element.visible(elem)) {
+               if (!Element.visible(elem) && !noexpand) {
                        if (cencw) {
                                cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
                                cencw.setAttribute('id', '');
@@ -1420,7 +1456,8 @@ function cdmExpandArticle(id) {
                if (old_offset > new_offset)
                        $("headlines-frame").scrollTop -= (old_offset-new_offset);
 
-               toggleUnread(id, 0, true);
+               if (!noexpand)
+                       toggleUnread(id, 0, true);
                toggleSelected(id);
                $("RROW-" + id).addClassName("active");