]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
add a link to headlines-spacer to open next unread feed
[tt-rss.git] / js / viewfeed.js
index c20c5a39b30aa6a9c84638fd565d2ebd409d7836..76248415aef7f07a10e92a57813701bc4590a35f 100644 (file)
@@ -87,8 +87,12 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                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) {
@@ -104,6 +108,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                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>)" +
@@ -172,7 +180,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        var hsp = $("headlines-spacer");
 
-                                       if (hsp) hsp.innerHTML = "";
+                                       if (hsp) hsp.innerHTML = "Click to open next unread feed.";
                                }
                        }
 
@@ -190,14 +198,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 +319,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
@@ -835,6 +838,8 @@ function selectionToggleUnread(set_state, callback, no_error, ids) {
                        }
                }
 
+               updateFloatingTitle(true);
+
                if (rows.length > 0) {
 
                        var cmode = "";
@@ -959,10 +964,12 @@ function getLoadedArticleIds() {
 }
 
 // mode = all,none,unread,invert,marked,published
-function selectArticles(mode) {
+function selectArticles(mode, query) {
        try {
 
-               var children = $$("#headlines-frame > div[id*=RROW]");
+               if (!query) query = "#headlines-frame > div[id*=RROW]";
+
+               var children = $$(query);
 
                children.each(function(child) {
                        var id = child.id.replace("RROW-", "");
@@ -1241,7 +1248,7 @@ function postMouseOut(id) {
 
 function unpackVisibleHeadlines() {
        try {
-               if (!isCdmMode()) return;
+               if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
 
                $$("#headlines-frame > div[id*=RROW]").each(
                        function(child) {
@@ -1273,15 +1280,17 @@ function headlines_scroll_handler(e) {
                unpackVisibleHeadlines();
 
                // set topmost child in the buffer as active
-               if (getInitParam("cdm_auto_catchup") == 1 &&
-                               (!isCdmMode() || getInitParam("cdm_expanded"))) {
+               if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
+                               getSelectedArticleIds2().length <= 1 &&
+                               getInitParam("cdm_expanded")) {
                        var rows = $$("#headlines-frame > div[id*=RROW]");
 
                        for (var i = 0; i < rows.length; i++) {
                                var child = rows[i];
 
-                               if ($("headlines-frame").scrollTop < child.offsetTop &&
-                                       child.offsetTop - $("headlines-frame").scrollTop < 100) {
+                               if ($("headlines-frame").scrollTop <= child.offsetTop &&
+                                       child.offsetTop - $("headlines-frame").scrollTop < 100 &&
+                                       child.id.replace("RROW-", "") != _active_article_id) {
 
                                        if (_active_article_id) {
                                                var row = $("RROW-" + _active_article_id);
@@ -1310,10 +1319,15 @@ function headlines_scroll_handler(e) {
 
                        }
                } 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 (getInitParam("cdm_expanded") && isCdmMode()) {
+               if (isCdmMode()) {
                        updateFloatingTitle();
                }
 
@@ -1346,6 +1360,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/2)) {
+
+                                       console.log("we seem to be at an end");
+
+                                       if (getInitParam("on_catchup_show_next_feed") == "1") {
+                                               openNextUnreadFeed();
+                                       }
+                               }
+                       }
                }
 
        } catch (e) {
@@ -1353,6 +1381,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) {
@@ -1379,6 +1417,8 @@ function catchupBatchedArticles() {
                                                catchup_id_batch.remove(id);
                                        });
 
+                                       updateFloatingTitle(true);
+
                                } });
                }
 
@@ -1487,6 +1527,12 @@ function cdmCollapseArticle(event, id, unmark) {
                        if (event) Event.stop(event);
 
                        PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
+
+                       if (row.offsetTop < $("headlines-frame").scrollTop)
+                               scrollToRowId(row.id);
+
+                       Element.hide("floatingTitle");
+                       $("floatingTitle").setAttribute("rowid", false);
                }
 
        } catch (e) {
@@ -1591,9 +1637,9 @@ function show_labels_in_headlines(transport) {
 
                if (data) {
                        data['info-for-headlines'].each(function(elem) {
-                               var ctr = $("HLLCTR-" + elem.id);
-
-                               if (ctr) ctr.innerHTML = elem.labels;
+                               $$(".HLLCTR-" + elem.id).each(function(ctr) {
+                                       ctr.innerHTML = elem.labels;
+                               });
                        });
                }
        } catch (e) {
@@ -1611,6 +1657,12 @@ function dismissArticle(id) {
 
                new Effect.Fade(elem, {duration : 0.5});
 
+               // Remove the content, too
+               var elem_content = $("CICD-" + id);
+               if (elem_content) {
+                       Element.remove(elem_content);
+               }
+
                if (id == getActiveArticleId()) {
                        setActiveArticleId(0);
                }
@@ -1634,6 +1686,12 @@ function dismissSelectedArticles() {
                                        ids[i] != getActiveArticleId()) {
                                new Effect.Fade(elem, {duration : 0.5});
                                sel.push(ids[i]);
+
+                               // Remove the content, too
+                               var elem_content = $("CICD-" + ids[i]);
+                               if (elem_content) {
+                                       Element.remove(elem_content);
+                               }
                        } else {
                                tmp.push(ids[i]);
                        }
@@ -1661,13 +1719,19 @@ function dismissReadArticles() {
                                        !elem.hasClassName("Selected")) {
 
                                new Effect.Fade(elem, {duration : 0.5});
+
+                               // Remove the content, too
+                               var elem_content = $("CICD-" + ids[i]);
+                               if (elem_content) {
+                                       Element.remove(elem_content);
+                               }
                        } else {
                                tmp.push(ids[i]);
                        }
                }
 
        } catch (e) {
-               exception_error("dismissSelectedArticles", e);
+               exception_error("dismissReadArticles", e);
        }
 }
 
@@ -1716,6 +1780,7 @@ function cdmClicked(event, id) {
 
                                if (article_is_unread) {
                                        decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
+                                       updateFloatingTitle(true);
                                }
 
                                var query = "?op=rpc&method=catchupSelected" +
@@ -1730,7 +1795,8 @@ function cdmClicked(event, id) {
                                return !event.shiftKey;
                        }
 
-               } else {
+               } else if (event.target.parents(".cdmHeader").length > 0) {
+
                        toggleSelected(id, true);
 
                        var elem = $("RROW-" + id);
@@ -1890,58 +1956,39 @@ function closeArticlePanel() {
                        dijit.byId("content-insert"));
 }
 
-function initHeadlinesMenu() {
+function initFloatingMenu() {
        try {
-               if (dijit.byId("headlinesMenu"))
-                       dijit.byId("headlinesMenu").destroyRecursive();
-
-               var ids = [];
-
-               if (!isCdmMode()) {
-                       nodes = $$("#headlines-frame > div[id*=RROW]");
-               } else {
-                       nodes = $$("#headlines-frame span[id*=RTITLE]");
-               }
-
-               nodes.each(function(node) {
-                       ids.push(node.id);
-               });
-
-               var menu = new dijit.Menu({
-                       id: "headlinesMenu",
-                       targetNodeIds: ids,
-               });
+               if (dijit.byId("floatingMenu"))
+                       dijit.byId("floatingMenu").destroyRecursive();
 
-               var tmph = dojo.connect(menu, '_openMyself', function (event) {
-                       var callerNode = event.target, match = null, tries = 0;
+                       var menu = new dijit.Menu({
+                               id: "floatingMenu",
+                               targetNodeIds: ["floatingTitle"]
+                       });
 
-                       while (match == null && callerNode && tries <= 3) {
-                               match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
-                               callerNode = callerNode.parentNode;
-                               ++tries;
-                       }
+                       var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
 
-                       if (match) this.callerRowId = parseInt(match[1]);
+                       headlinesMenuCommon(menu, id);
 
-               });
+                       menu.startup();
+       } catch (e) {
+               exception_error("initFloatingMenu", e);
+       }
+}
 
-/*             if (!isCdmMode())
-                       menu.addChild(new dijit.MenuItem({
-                               label: __("View article"),
-                               onClick: function(event) {
-                                       view(this.getParent().callerRowId);
-                               }})); */
+function headlinesMenuCommon(menu, base_id) {
+       try {
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Open original article"),
                        onClick: function(event) {
-                               openArticleInNewWindow(this.getParent().callerRowId);
+                               openArticleInNewWindow(base_id ? base_id : this.getParent().callerRowId);
                        }}));
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Display article URL"),
                        onClick: function(event) {
-                               displayArticleUrl(this.getParent().callerRowId);
+                               displayArticleUrl(base_id ? base_id : this.getParent().callerRowId);
                        }}));
 
                menu.addChild(new dijit.MenuSeparator());
@@ -1951,7 +1998,7 @@ function initHeadlinesMenu() {
                        onClick: function(event) {
                                var ids = getSelectedArticleIds2();
                                // cast to string
-                               var id = this.getParent().callerRowId + "";
+                               var id = (base_id ? base_id : this.getParent().callerRowId) + "";
                                ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                                selectionToggleUnread(undefined, false, true, ids);
@@ -1962,7 +2009,7 @@ function initHeadlinesMenu() {
                        onClick: function(event) {
                                var ids = getSelectedArticleIds2();
                                // cast to string
-                               var id = this.getParent().callerRowId + "";
+                               var id = (base_id ? base_id : this.getParent().callerRowId) + "";
                                ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                                selectionToggleMarked(undefined, false, true, ids);
@@ -1973,7 +2020,7 @@ function initHeadlinesMenu() {
                        onClick: function(event) {
                                var ids = getSelectedArticleIds2();
                                // cast to string
-                               var id = this.getParent().callerRowId + "";
+                               var id = (base_id ? base_id : this.getParent().callerRowId) + "";
                                ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
                                selectionTogglePublished(undefined, false, true, ids);
@@ -1984,13 +2031,13 @@ function initHeadlinesMenu() {
                menu.addChild(new dijit.MenuItem({
                        label: __("Mark above as read"),
                        onClick: function(event) {
-                               catchupRelativeToArticle(0, this.getParent().callerRowId);
+                               catchupRelativeToArticle(0, base_id ? base_id : this.getParent().callerRowId);
                                }}));
 
                menu.addChild(new dijit.MenuItem({
                        label: __("Mark below as read"),
                        onClick: function(event) {
-                               catchupRelativeToArticle(1, this.getParent().callerRowId);
+                               catchupRelativeToArticle(1, base_id ? base_id : this.getParent().callerRowId);
                                }}));
 
 
@@ -2016,7 +2063,7 @@ function initHeadlinesMenu() {
                                        onClick: function(event) {
                                                var ids = getSelectedArticleIds2();
                                                // cast to string
-                                               var id = this.getParent().ownerMenu.callerRowId + "";
+                                               var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
 
                                                ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
@@ -2029,7 +2076,7 @@ function initHeadlinesMenu() {
                                        onClick: function(event) {
                                                var ids = getSelectedArticleIds2();
                                                // cast to string
-                                               var id = this.getParent().ownerMenu.callerRowId + "";
+                                               var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
 
                                                ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
 
@@ -2050,8 +2097,117 @@ function initHeadlinesMenu() {
 
                }
 
+
+       } catch (e) {
+               exception_error("headlinesMenuCommon", e);
+       }
+}
+
+function initHeadlinesMenu() {
+       try {
+               if (dijit.byId("headlinesMenu"))
+                       dijit.byId("headlinesMenu").destroyRecursive();
+
+               var ids = [];
+
+               if (!isCdmMode()) {
+                       nodes = $$("#headlines-frame > div[id*=RROW]");
+               } else {
+                       nodes = $$("#headlines-frame span[id*=RTITLE]");
+               }
+
+               nodes.each(function(node) {
+                       ids.push(node.id);
+               });
+
+               var menu = new dijit.Menu({
+                       id: "headlinesMenu",
+                       targetNodeIds: ids,
+               });
+
+               var tmph = dojo.connect(menu, '_openMyself', function (event) {
+                       var callerNode = event.target, match = null, tries = 0;
+
+                       while (match == null && callerNode && tries <= 3) {
+                               match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
+                               callerNode = callerNode.parentNode;
+                               ++tries;
+                       }
+
+                       if (match) this.callerRowId = parseInt(match[1]);
+
+               });
+
+               headlinesMenuCommon(menu, false);
+
                menu.startup();
 
+               /* vgroup feed title menu */
+
+               var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']");
+               var ids = [];
+
+               nodes.each(function(node) {
+                       ids.push(node.id);
+               });
+
+               if (ids.length > 0) {
+                       if (dijit.byId("headlinesFeedTitleMenu"))
+                               dijit.byId("headlinesFeedTitleMenu").destroyRecursive();
+
+                       var menu = new dijit.Menu({
+                               id: "headlinesFeedTitleMenu",
+                               targetNodeIds: ids,
+                       });
+
+                       var tmph = dojo.connect(menu, '_openMyself', function (event) {
+                               var callerNode = event.target, match = null, tries = 0;
+
+                               while (match == null && callerNode && tries <= 3) {
+                                       console.log(callerNode.id);
+
+                                       match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
+                                       callerNode = callerNode.parentNode;
+                                       ++tries;
+
+                                       console.log(match[1]);
+                               }
+
+                               if (match) this.callerRowId = parseInt(match[1]);
+
+                       });
+
+                       menu.addChild(new dijit.MenuItem({
+                               label: __("Select articles in group"),
+                               onClick: function(event) {
+                                       selectArticles("all",
+                                               "#headlines-frame > div[id*=RROW]"+
+                                               "[orig-feed-id='"+menu.callerRowId+"']");
+
+                               }}));
+
+                       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+"']");
+
+                                       catchupSelection();
+                               }}));
+
+
+                       menu.addChild(new dijit.MenuItem({
+                               label: __("Mark feed as read"),
+                               onClick: function(event) {
+                                       catchupFeedInGroup(menu.callerRowId);
+                               }}));
+
+                       menu.startup();
+
+               }
+
        } catch (e) {
                exception_error("initHeadlinesMenu", e);
        }
@@ -2195,32 +2351,67 @@ function openSelectedAttachment(elem) {
        }
 }
 
-function updateFloatingTitle() {
+function scrollToRowId(id) {
        try {
+               var row = $(id);
+
+               if (row)
+                       $("headlines-frame").scrollTop = row.offsetTop;
+
+       } catch (e) {
+               exception_error("scrollToRowId", e);
+       }
+}
+
+function updateFloatingTitle(unread_only) {
+       try {
+               if (!isCdmMode()) return;
+
                var hf = $("headlines-frame");
 
                var elems = $$("#headlines-frame > div[id*=RROW]");
 
                for (var i = 0; i < elems.length; i++) {
+
                        var child = elems[i];
 
-                       if (child.offsetTop + child.offsetHeight > hf.scrollTop) {
+                       if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
 
                                var header = child.getElementsByClassName("cdmHeader")[0];
 
-                               $("floatingTitle").setAttribute("rowid", child.id);
-                               $("floatingTitle").innerHTML =
-                                       header.innerHTML;
+                               if (unread_only || child.id != $("floatingTitle").getAttribute("rowid")) {
+                                       if (child.id != $("floatingTitle").getAttribute("rowid")) {
+                                               $("floatingTitle").setAttribute("rowid", child.id);
+                                               $("floatingTitle").innerHTML = header.innerHTML;
+                                               $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child.id+"')\">" + $("floatingTitle").firstChild.innerHTML;
+
+                                               initFloatingMenu();
 
-                               if (child.offsetTop < hf.scrollTop - header.offsetHeight - 100 &&
-                                               child.offsetTop + child.offsetHeight - hf.scrollTop > 100)
+                                               var cb = $$("#floatingTitle .dijitCheckBox")[0];
+
+                                               if (cb)
+                                                       cb.parentNode.removeChild(cb);
+                                       }
+
+                                       if (child.hasClassName("Unread"))
+                                               $("floatingTitle").addClassName("Unread");
+                                       else
+                                               $("floatingTitle").removeClassName("Unread");
+
+                                       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");
                                else
                                        Element.hide("floatingTitle");
 
-                               break;
+                               return;
+
                        }
                }
+
        } catch (e) {
                exception_error("updateFloatingTitle", e);
        }