]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
queryFeedHeadlines: move to array-based arguments, optionally check if first element...
[tt-rss.git] / js / viewfeed.js
index 3c02d462640e7cf8b681767b5db77163208e1ac7..8bc42aadc802955e88f85be834619a457636489f 100644 (file)
@@ -13,6 +13,7 @@ var catchup_timeout_id = false;
 var cids_requested = [];
 var loaded_article_ids = [];
 var _last_headlines_update = 0;
+var current_top_article_id = false;
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -56,7 +57,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                if (infscroll_req == false) {
                                        $("headlines-frame").scrollTop = 0;
 
-                                       Element.hide("floatingTitle");
+                                       $("floatingTitle").style.visibility = "hidden";
                                        $("floatingTitle").setAttribute("rowid", 0);
                                        $("floatingTitle").innerHTML = "";
                                }
@@ -83,12 +84,17 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                        if (infscroll_req == false) {
                                loaded_article_ids = [];
+                               current_top_article_id = false;
 
                                dijit.byId("headlines-frame").attr('content',
                                        reply['headlines']['content']);
 
-                               dijit.byId("headlines-toolbar").attr('content',
-                                       reply['headlines']['toolbar']);
+                               //dijit.byId("headlines-toolbar").attr('content',
+                               //      reply['headlines']['toolbar']);
+
+                               dojo.html.set($("headlines-toolbar"),
+                                               reply['headlines']['toolbar'],
+                                               {parseContent: true});
 
                                $$("#headlines-frame > div[id*=RROW]").each(function(row) {
                                        if (loaded_article_ids.indexOf(row.id) != -1) {
@@ -98,12 +104,20 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        }
                                });
 
+                               if (loaded_article_ids.size() > 0) {
+                                       current_top_article_id = parseInt(loaded_article_ids[0].replace("RROW-", ""));
+                               }
+
                                var hsp = $("headlines-spacer");
                                if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
                                dijit.byId('headlines-frame').domNode.appendChild(hsp);
 
                                initHeadlinesMenu();
 
+                               if (_infscroll_disable)
+                                       hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
+                                               __("Click to open next unread feed.") + "</a>";
+
                                if (_search_query) {
                                        $("feed_title").innerHTML += "<span id='cancel_search'>" +
                                                " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
@@ -143,9 +157,9 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
 
-                                       if (getInitParam("cdm_auto_catchup") == 1) {
+//                                     if (getInitParam("cdm_auto_catchup") == 1) {
                                                c.domNode.appendChild(hsp);
-                                       }
+//                                     }
 
                                        console.log("added " + new_elems.size() + " headlines");
 
@@ -172,7 +186,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        var hsp = $("headlines-spacer");
 
-                                       if (hsp) hsp.innerHTML = "";
+                                       if (hsp) hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
+                                               __("Click to open next unread feed.") + "</a>";
                                }
                        }
 
@@ -190,14 +205,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        else
                                request_counters(true);
 
-               } else if (transport.responseText) {
+               } else {
                        console.error("Invalid object received: " + transport.responseText);
                        dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
                                        __('Could not update headlines (invalid object received - see error console for details)') +
                                        "</div>");
-               } else {
-                       //notify_error("Error communicating with server.");
-                       Element.show(dijit.byId("net-alert").domNode);
                }
 
                _infscroll_request_sent = 0;
@@ -314,13 +326,11 @@ function article_callback2(transport, id) {
 //                             return;
 //                     }
 
-               } else if (transport.responseText) {
+               } else {
                        console.error("Invalid object received: " + transport.responseText);
 
                        render_article("<div class='whiteBox'>" +
                                        __('Could not display article (invalid object received - see error console for details)') + "</div>");
-               } else {
-                       Element.show(dijit.byId("net-alert").domNode);
                }
 
                var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
@@ -1245,7 +1255,7 @@ function postMouseOut(id) {
 
 function unpackVisibleHeadlines() {
        try {
-               if (!isCdmMode()) return;
+               if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
 
                $$("#headlines-frame > div[id*=RROW]").each(
                        function(child) {
@@ -1308,15 +1318,20 @@ function headlines_scroll_handler(e) {
                                                ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
 
                                if (hsp)
-                                       hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
-                                               __("Loading, please wait...");
+                                       hsp.innerHTML = "<span class='loading'><img src='images/indicator_tiny.gif'> " +
+                                               __("Loading, please wait...") + "</span>";
 
                                loadMoreHeadlines();
                                return;
 
                        }
                } else {
-                       if (hsp) hsp.innerHTML = "";
+                       if (hsp)
+                               if (_infscroll_disable)
+                                       hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
+                                               __("Click to open next unread feed.") + "</a>";
+                               else
+                                       hsp.innerHTML = "";
                }
 
                if (isCdmMode()) {
@@ -1352,6 +1367,20 @@ function headlines_scroll_handler(e) {
                                                500);
                                }
                        }
+
+                       if (_infscroll_disable) {
+                               var child = $$("#headlines-frame div[id*=RROW]").last();
+
+                               if (child && $("headlines-frame").scrollTop >
+                                               (child.offsetTop + child.offsetHeight - 50)) {
+
+                                       console.log("we seem to be at an end");
+
+                                       if (getInitParam("on_catchup_show_next_feed") == "1") {
+                                               openNextUnreadFeed();
+                                       }
+                               }
+                       }
                }
 
        } catch (e) {
@@ -1359,6 +1388,16 @@ function headlines_scroll_handler(e) {
        }
 }
 
+function openNextUnreadFeed() {
+       try {
+               var is_cat = activeFeedIsCat();
+               var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat);
+               if (nuf) viewfeed(nuf, '', is_cat);
+       } catch (e) {
+               exception_error("openNextUnreadFeed", e);
+       }
+}
+
 function catchupBatchedArticles() {
        try {
                if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
@@ -1499,7 +1538,7 @@ function cdmCollapseArticle(event, id, unmark) {
                        if (row.offsetTop < $("headlines-frame").scrollTop)
                                scrollToRowId(row.id);
 
-                       Element.hide("floatingTitle");
+                       $("floatingTitle").style.visibility = "hidden";
                        $("floatingTitle").setAttribute("rowid", false);
                }
 
@@ -1763,7 +1802,8 @@ function cdmClicked(event, id) {
                                return !event.shiftKey;
                        }
 
-               } else {
+               } else if (event.target.parents(".cdmHeader").length > 0) {
+
                        toggleSelected(id, true);
 
                        var elem = $("RROW-" + id);
@@ -2156,6 +2196,7 @@ function initHeadlinesMenu() {
                        menu.addChild(new dijit.MenuItem({
                                label: __("Mark group as read"),
                                onClick: function(event) {
+                                       selectArticles("none");
                                        selectArticles("all",
                                                "#headlines-frame > div[id*=RROW]"+
                                                "[orig-feed-id='"+menu.callerRowId+"']");
@@ -2258,6 +2299,34 @@ function setSelectionScore() {
        }
 }
 
+function updateScore(id) {
+       try {
+               var pic = $$("#RROW-" + id + " .hlScorePic")[0];
+
+               if (pic) {
+
+                       var query = "op=article&method=getScore&id=" + param_escape(id);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       console.log(transport.responseText);
+
+                                       var reply = JSON.parse(transport.responseText);
+
+                                       if (reply) {
+                                               pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
+                                               pic.setAttribute("score", reply["score"]);
+                                               pic.setAttribute("title", reply["score"]);
+                                       }
+                               } });
+               }
+
+       } catch (e) {
+               exception_error("updateScore", e);
+       }
+}
+
 function changeScore(id, pic) {
        try {
                var score = pic.getAttribute("score");
@@ -2277,6 +2346,7 @@ function changeScore(id, pic) {
                                        if (reply) {
                                                pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
                                                pic.setAttribute("score", new_score);
+                                               pic.setAttribute("title", new_score);
                                        }
                                } });
                }
@@ -2322,7 +2392,7 @@ function scrollToRowId(id) {
                var row = $(id);
 
                if (row)
-                       $("headlines-frame").scrollTop = row.offsetTop;
+                       $("headlines-frame").scrollTop = row.offsetTop - 4;
 
        } catch (e) {
                exception_error("scrollToRowId", e);
@@ -2367,11 +2437,12 @@ function updateFloatingTitle(unread_only) {
                                        PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
                                }
 
-                               if (child.offsetTop < hf.scrollTop - header.offsetHeight &&
-                                               child.offsetTop + child.offsetHeight - hf.scrollTop > header.offsetHeight)
-                                       Element.show("floatingTitle");
+                               $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
+                               if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
+                                   child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
+                                       $("floatingTitle").style.visibility = "visible";
                                else
-                                       Element.hide("floatingTitle");
+                                       $("floatingTitle").style.visibility = "hidden";
 
                                return;
 
@@ -2382,3 +2453,7 @@ function updateFloatingTitle(unread_only) {
                exception_error("updateFloatingTitle", e);
        }
 }
+
+function cdmFooterClick(event) {
+       event.stopPropagation();
+}
\ No newline at end of file