]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
cdmExpandArticle: force-scroll to headline
[tt-rss.git] / js / viewfeed.js
index 6c25f6eeb21a66325f941ae7ab26edd0f350f3be..da474a2c00fcee4267ac90ba4fa5cde7ccddeaf1 100644 (file)
@@ -9,8 +9,6 @@ var last_requested_article = false;
 
 var catchup_id_batch = [];
 var catchup_timeout_id = false;
-var feed_precache_timeout_id = false;
-var precache_idle_timeout_id = false;
 
 var cids_requested = [];
 var loaded_article_ids = [];
@@ -47,8 +45,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                if (getInitParam("cdm_auto_catchup") == 1) {
                                        content = content + "<div id='headlines-spacer'></div>";
                                }
-
-                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
                                return;
                        }
 
@@ -183,9 +179,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                }
                        }
 
-                       if (headlines_count > 0)
-                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
-
                        if (articles) {
                                for (var i = 0; i < articles.length; i++) {
                                        var a_id = articles[i]['id'];
@@ -195,10 +188,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                console.log("no cached articles received");
                        }
 
-                       // do not precache stuff after fresh feed
-                       if (feed_id != -3)
-                               precache_headlines();
-
                        if (counters)
                                parse_counters(counters);
                        else
@@ -272,10 +261,6 @@ function showArticleInHeadlines(id) {
                        //
                }
 
-               if (article_is_unread && view_mode == "all_articles") {
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-               }
-
                markHeadline(id);
 
                if (article_is_unread)
@@ -385,8 +370,6 @@ function view(id) {
                setActiveArticleId(id);
                showArticleInHeadlines(id);
 
-               precache_headlines();
-
                if (cached_article && article_is_unread) {
 
                        query = query + "&mode=prefetch";
@@ -458,8 +441,6 @@ function toggleMark(id, client_only) {
                        query = query + "&mark=0";
                }
 
-               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -499,8 +480,6 @@ function togglePub(id, client_only, no_effects, note) {
                        query = query + "&pub=0";
                }
 
-               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -581,11 +560,11 @@ function moveToPost(mode, noscroll) {
                                        var ctr = $("headlines-frame");
 
                                        if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
-                                               scrollArticle(-ctr.offsetHeight/2);
+                                               scrollArticle(-ctr.offsetHeight/3);
                                        } else if (!noscroll && prev_article &&
                                                        prev_article.offsetTop < ctr.scrollTop) {
                                                cdmExpandArticle(prev_id);
-                                               scrollArticle(-ctr.offsetHeight/2);
+                                               scrollArticle(-ctr.offsetHeight/3);
                                        } else if (prev_id) {
                                                cdmExpandArticle(prev_id);
                                                cdmScrollToArticleId(prev_id, noscroll);
@@ -1333,6 +1312,35 @@ function catchupRelativeToArticle(below, id) {
        }
 }
 
+function cdmCollapseArticle(event, id) {
+       try {
+               var row = $("RROW-" + id);
+               var elem = $("CICD-" + id);
+
+               if (elem && row) {
+                       row.removeClassName("Selected");
+
+                       var collapse = $$("div#RROW-" + id +
+                               " span[class='collapseBtn']")[0];
+
+                       Element.hide(elem);
+                       Element.show("CEXC-" + id);
+                       Element.hide(collapse);
+
+                       markHeadline(id, false);
+
+                       if (id == getActiveArticleId()) {
+                               setActiveArticleId(0);
+                       }
+
+                       if (event) Event.stop(event);
+               }
+
+       } catch (e) {
+               exception_error("cdmCollapseArticle", e);
+       }
+}
+
 function cdmExpandArticle(id) {
        try {
 
@@ -1348,26 +1356,28 @@ function cdmExpandArticle(id) {
                var old_offset = $("RROW-" + id).offsetTop;
 
                if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
+                       var collapse = $$("div#RROW-" + getActiveArticleId() +
+                               " span[class='collapseBtn']")[0];
+
                        Element.hide(elem);
                        Element.show("CEXC-" + getActiveArticleId());
+                       Element.hide(collapse);
                }
 
                setActiveArticleId(id);
+               cdmScrollToArticleId(id, true);
 
                elem = $("CICD-" + id);
 
+               var collapse = $$("div#RROW-" + id +
+                               " span[class='collapseBtn']")[0];
+
                if (!Element.visible(elem)) {
                        Element.show(elem);
                        Element.hide("CEXC-" + id);
+                       Element.show(collapse);
                }
 
-               /* var new_offset = $("RROW-" + id).offsetTop;
-
-               $("headlines-frame").scrollTop += (new_offset-old_offset);
-
-               if ($("RROW-" + id).offsetTop != old_offset)
-                       $("headlines-frame").scrollTop = new_offset; */
-
                toggleUnread(id, 0, true);
                toggleSelected(id);
 
@@ -1431,9 +1441,6 @@ function show_labels_in_headlines(transport) {
 
                                if (ctr) ctr.innerHTML = elem.labels;
                        });
-
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                }
        } catch (e) {
                exception_error("show_labels_in_headlines", e);
@@ -1538,6 +1545,7 @@ function cdmClicked(event, id) {
                if (!event.ctrlKey) {
 
                        if (!getInitParam("cdm_expanded")) {
+                               if (event) Event.stop(event);
                                return cdmExpandArticle(id);
                        } else {
 
@@ -1565,7 +1573,7 @@ function cdmClicked(event, id) {
                                                handle_rpc_json(transport);
                                        } });
 
-                               return true;
+                               return !event.shiftKey;
                        }
 
                } else {
@@ -1633,13 +1641,15 @@ function isCdmMode() {
        return getInitParam("combined_display_mode");
 }
 
-function markHeadline(id) {
+function markHeadline(id, marked) {
+       if (marked == undefined) marked = true;
+
        var row = $("RROW-" + id);
        if (row) {
                var check = dijit.byId("RCHK-" + id);
 
                if (check) {
-                       check.attr("checked", true);
+                       check.attr("checked", marked);
                }
 
                row.addClassName("Selected");
@@ -1901,107 +1911,6 @@ function cache_delete(id) {
                sessionStorage.removeItem(id);
 }
 
-function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
-       if (toolbar_obj && content_obj) {
-               cache_set("feed:" + feed + ":" + is_cat,
-                       JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
-       } else {
-               try {
-                       obj =   cache_get("feed:" + feed + ":" + is_cat);
-
-                       if (obj) {
-                               obj = JSON.parse(obj);
-
-                               if (toolbar_obj) obj.toolbar = toolbar_obj;
-                               if (content_obj) obj.content = content_obj;
-
-                               cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
-                       }
-
-               } catch (e) {
-                       console.warn("cache_headlines failed: " + e);
-               }
-       }
-}
-
-function render_local_headlines(feed, is_cat, obj) {
-       try {
-
-               dijit.byId("headlines-toolbar").attr('content',
-                       obj.toolbar);
-
-               dijit.byId("headlines-frame").attr('content',
-                       obj.content);
-
-               dojo.parser.parse('headlines-toolbar');
-
-               $("headlines-frame").scrollTop = 0;
-               selectArticles('none');
-               setActiveFeedId(feed, is_cat);
-               initHeadlinesMenu();
-
-               dijit.getEnclosingWidget(
-                       document.forms["main_toolbar_form"].update).attr('disabled',
-                               is_cat || feed <= 0);
-
-               precache_headlines();
-
-       } catch (e) {
-               exception_error("render_local_headlines", e);
-       }
-}
-
-function precache_headlines_idle() {
-       try {
-               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
-                       if (get_timestamp() - _viewfeed_last > 120) {
-
-                               var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
-                               var uncached = [];
-
-                               feeds.each(function(item) {
-                                       if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
-                                               uncached.push(item);
-                               });
-
-                               if (uncached.length > 0) {
-                                       var rf = uncached[Math.floor(Math.random()*uncached.length)];
-                                       viewfeed(rf[0], '', rf[1], 0, true);
-                               }
-                       }
-               }
-               precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
-
-       } catch (e) {
-               exception_error("precache_headlines_idle", e);
-       }
-}
-
-function precache_headlines() {
-       try {
-               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
-
-                       feed_precache_timeout_id = window.setTimeout(function() {
-                               var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
-                               var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
-
-                               if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
-                                       viewfeed(nuf, '', activeFeedIsCat(), 0, true);
-
-                               if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
-                                       viewfeed(nf[0], '', nf[1], 0, true);
-
-                               window.setTimeout(function() {
-                                       feed_precache_timeout_id = false;
-                                       }, 3000);
-                       }, 1000);
-               }
-
-       } catch (e) {
-               exception_error("precache_headlines", e);
-       }
-}
-
 function cancelSearch() {
        try {
                _search_query = "";