]> 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 c24dec62eb3d9ad8a22e81665037784022e78eb1..76248415aef7f07a10e92a57813701bc4590a35f 100644 (file)
@@ -12,8 +12,7 @@ var catchup_timeout_id = false;
 
 var cids_requested = [];
 var loaded_article_ids = [];
-
-var _post_preview_timeout = false;
+var _last_headlines_update = 0;
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -21,8 +20,6 @@ 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 + " I:" + infscroll_req);
 
                var is_cat = false;
@@ -44,13 +41,12 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        if (background) {
                                var content = reply['headlines']['content'];
 
-                               if (getInitParam("cdm_auto_catchup") == 1) {
-                                       content = content + "<div id='headlines-spacer'></div>";
-                               }
+                               content = content + "<div id='headlines-spacer'></div>";
                                return;
                        }
 
-                       setActiveFeedId(feed_id, is_cat);
+                       if (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat())
+                               return;
 
                        /* dijit.getEnclosingWidget(
                                document.forms["main_toolbar_form"].update).attr('disabled',
@@ -59,14 +55,23 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        try {
                                if (infscroll_req == false) {
                                        $("headlines-frame").scrollTop = 0;
+
+                                       Element.hide("floatingTitle");
+                                       $("floatingTitle").setAttribute("rowid", 0);
+                                       $("floatingTitle").innerHTML = "";
                                }
                        } catch (e) { };
 
+                       $("headlines-frame").removeClassName("cdm");
+                       $("headlines-frame").removeClassName("normal");
+
+                       $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
+
                        var headlines_count = reply['headlines-info']['count'];
 
                        vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
 
-                       if (parseInt(headlines_count) < getInitParam("default_article_limit")) {
+                       if (parseInt(headlines_count) < 30) {
                                _infscroll_disable = 1;
                        } else {
                                _infscroll_disable = 0;
@@ -82,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) {
@@ -93,14 +102,16 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        }
                                });
 
-                               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);
-                               }
+                               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>)" +
@@ -140,8 +151,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
 
-                                       fixHeadlinesOrder(getLoadedArticleIds());
-
                                        if (getInitParam("cdm_auto_catchup") == 1) {
                                                c.domNode.appendChild(hsp);
                                        }
@@ -160,16 +169,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        initHeadlinesMenu();
 
                                        new_elems.each(function(child) {
-                                               var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
+                                               dojo.parser.parse(child);
 
-                                               if (!cb) {
-                                                       dojo.parser.parse(child);
-
-                                                       if (!Element.visible(child))
-                                                               new Effect.Appear(child, { duration : 0.5 });
-                                               } else {
-                                                       c.domNode.removeChild(child);
-                                               }
+                                               if (!Element.visible(child))
+                                                       new Effect.Appear(child, { duration : 0.5 });
                                        });
 
                                } else {
@@ -177,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.";
                                }
                        }
 
@@ -195,20 +198,28 @@ 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;
+               _last_headlines_update = new Date().getTime();
 
                unpackVisibleHeadlines();
 
+               // if we have some more space in the buffer, why not try to fill it
+
+               if (!_infscroll_disable && $("headlines-spacer") &&
+                               $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
+
+                       window.setTimeout(function() {
+                               loadMoreHeadlines();
+                       }, 250);
+               }
+
                notify("");
 
        } catch (e) {
@@ -227,6 +238,8 @@ function render_article(article) {
                        c.domNode.scrollTop = 0;
                } catch (e) { };
 
+               PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, article);
+
                c.attr('content', article);
 
                correctHeadlinesOffset(getActiveArticleId());
@@ -240,7 +253,7 @@ function render_article(article) {
        }
 }
 
-function showArticleInHeadlines(id) {
+function showArticleInHeadlines(id, noexpand) {
 
        try {
                selectArticles("none");
@@ -251,7 +264,8 @@ function showArticleInHeadlines(id) {
 
                var article_is_unread = crow.hasClassName("Unread");
 
-               crow.removeClassName("Unread");
+               if (!noexpand)
+                       crow.removeClassName("Unread");
                crow.addClassName("active");
 
                selectArticles('none');
@@ -267,7 +281,7 @@ function showArticleInHeadlines(id) {
 
                markHeadline(id);
 
-               if (article_is_unread)
+               if (article_is_unread && !noexpand)
                        _force_scheduled_update = true;
 
        } catch (e) {
@@ -305,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
@@ -335,7 +347,7 @@ function article_callback2(transport, id) {
        }
 }
 
-function view(id) {
+function view(id, activefeed, noexpand) {
        try {
                var oldrow = $("RROW-" + getActiveArticleId());
                if (oldrow) oldrow.removeClassName("active");
@@ -343,6 +355,11 @@ function view(id) {
                var crow = $("RROW-" + id);
 
                if (!crow) return;
+               if (noexpand) {
+                       setActiveArticleId(id);
+                       showArticleInHeadlines(id, noexpand);
+                       return;
+               }
 
                console.log("loading article: " + id);
 
@@ -431,21 +448,41 @@ function toggleMark(id, client_only) {
        try {
                var query = "?op=rpc&id=" + id + "&method=mark";
 
-               var img = $("FMPIC-" + id);
+               var row = $("RROW-" + id);
+               if (!row) return;
 
-               if (!img) return;
+               var imgs = [];
 
-               if (img.src.match("mark_unset")) {
-                       img.src = img.src.replace("mark_unset", "mark_set");
-                       img.alt = __("Unstar article");
-                       query = query + "&mark=1";
+               var row_imgs = row.getElementsByClassName("markedPic");
 
-               } else {
-                       img.src = img.src.replace("mark_set", "mark_unset");
-                       img.alt = __("Star article");
-                       query = query + "&mark=0";
+               for (var i = 0; i < row_imgs.length; i++)
+                       imgs.push(row_imgs[i]);
+
+               var ft = $("floatingTitle");
+
+               if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
+                       var fte = ft.getElementsByClassName("markedPic");
+
+                       for (var i = 0; i < fte.length; i++)
+                               imgs.push(fte[i]);
+               }
+
+               for (i = 0; i < imgs.length; i++) {
+                       var img = imgs[i];
+
+                       if (!row.hasClassName("marked")) {
+                               img.src = img.src.replace("mark_unset", "mark_set");
+                               img.alt = __("Unstar article");
+                               query = query + "&mark=1";
+                       } else {
+                               img.src = img.src.replace("mark_set", "mark_unset");
+                               img.alt = __("Star article");
+                               query = query + "&mark=0";
+                       }
                }
 
+               row.toggleClassName("marked");
+
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -469,22 +506,44 @@ function togglePub(id, client_only, no_effects, note) {
                        query = query + "&note=undefined";
                }
 
-               var img = $("FPPIC-" + id);
+               var row = $("RROW-" + id);
+               if (!row) return;
 
-               if (!img) return;
+               var imgs = [];
 
-               if (img.src.match("pub_unset") || note != undefined) {
-                       img.src = img.src.replace("pub_unset", "pub_set");
-                       img.alt = __("Unpublish article");
-                       query = query + "&pub=1";
+               var row_imgs = row.getElementsByClassName("pubPic");
 
-               } else {
-                       img.src = img.src.replace("pub_set", "pub_unset");
-                       img.alt = __("Publish article");
+               for (var i = 0; i < row_imgs.length; i++)
+                       imgs.push(row_imgs[i]);
+
+               var ft = $("floatingTitle");
+
+               if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
+                       var fte = ft.getElementsByClassName("pubPic");
 
-                       query = query + "&pub=0";
+                       for (var i = 0; i < fte.length; i++)
+                               imgs.push(fte[i]);
+               }
+
+               for (i = 0; i < imgs.length; i++) {
+                       var img = imgs[i];
+
+                       if (!row.hasClassName("published") || note != undefined) {
+                               img.src = img.src.replace("pub_unset", "pub_set");
+                               img.alt = __("Unpublish article");
+                               query = query + "&pub=1";
+                       } else {
+                               img.src = img.src.replace("pub_set", "pub_unset");
+                               img.alt = __("Publish article");
+                               query = query + "&pub=0";
+                       }
                }
 
+               if (note != undefined)
+                       row.addClassName("published");
+               else
+                       row.toggleClassName("published");
+
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -498,7 +557,7 @@ function togglePub(id, client_only, no_effects, note) {
        }
 }
 
-function moveToPost(mode, noscroll) {
+function moveToPost(mode, noscroll, noexpand) {
 
        try {
 
@@ -545,13 +604,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);
                                }
                        }
                }
@@ -566,10 +625,10 @@ function moveToPost(mode, noscroll) {
 
                                        if (!getInitParam("cdm_expanded")) {
 
-                                               if (!noscroll && article.offsetTop < ctr.scrollTop) {
+                                               if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
                                                        scrollArticle(-ctr.offsetHeight/4);
                                                } else {
-                                                       cdmExpandArticle(prev_id);
+                                                       cdmExpandArticle(prev_id, noexpand);
                                                        cdmScrollToArticleId(prev_id, true);
                                                }
                                        } else {
@@ -578,17 +637,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);
                                }
                        }
                }
@@ -600,11 +659,12 @@ function moveToPost(mode, noscroll) {
 
 function toggleSelected(id, force_on) {
        try {
-
-               var cb = dijit.byId("RCHK-" + id);
                var row = $("RROW-" + id);
 
                if (row) {
+                       var cb = dijit.getEnclosingWidget(
+                                       row.getElementsByClassName("rchk")[0]);
+
                        if (row.hasClassName('Selected') && !force_on) {
                                row.removeClassName('Selected');
                                if (cb) cb.attr("checked", false);
@@ -613,11 +673,33 @@ function toggleSelected(id, force_on) {
                                if (cb) cb.attr("checked", true);
                        }
                }
+
+               updateSelectedPrompt();
        } catch (e) {
                exception_error("toggleSelected", e);
        }
 }
 
+function updateSelectedPrompt() {
+       try {
+               var count = getSelectedArticleIds2().size();
+               var elem = $("selected_prompt");
+
+               if (elem) {
+                       elem.innerHTML = ngettext("%d article selected",
+                                       "%d articles selected", count).replace("%d", count);
+
+                       if (count > 0)
+                               Element.show(elem);
+                       else
+                               Element.hide(elem);
+               }
+
+       } catch (e) {
+               exception_error("updateSelectedPrompt", e);
+       }
+}
+
 function toggleUnread_afh(effect) {
        try {
 
@@ -680,7 +762,7 @@ function selectionRemoveLabel(id, ids) {
                        return;
                }
 
-               var query = "?op=rpc&method=removeFromLabel&ids=" +
+               var query = "?op=article&method=removeFromLabel&ids=" +
                        param_escape(ids.toString()) + "&lid=" + param_escape(id);
 
                console.log(query);
@@ -708,7 +790,7 @@ function selectionAssignLabel(id, ids) {
                        return;
                }
 
-               var query = "?op=rpc&method=assignToLabel&ids=" +
+               var query = "?op=article&method=assignToLabel&ids=" +
                        param_escape(ids.toString()) + "&lid=" + param_escape(id);
 
                console.log(query);
@@ -756,6 +838,8 @@ function selectionToggleUnread(set_state, callback, no_error, ids) {
                        }
                }
 
+               updateFloatingTitle(true);
+
                if (rows.length > 0) {
 
                        var cmode = "";
@@ -880,14 +964,18 @@ 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-", "");
-                       var cb = dijit.byId("RCHK-" + id);
+
+                       var cb = dijit.getEnclosingWidget(
+                                       child.getElementsByClassName("rchk")[0]);
 
                        if (mode == "all") {
                                child.addClassName("Selected");
@@ -901,9 +989,7 @@ function selectArticles(mode) {
                                        if (cb) cb.attr("checked", false);
                                }
                        } else if (mode == "marked") {
-                               var img = $("FMPIC-" + child.id.replace("RROW-", ""));
-
-                               if (img && img.src.match("mark_set")) {
+                               if (child.hasClassName("marked")) {
                                        child.addClassName("Selected");
                                        if (cb) cb.attr("checked", true);
                                } else {
@@ -911,9 +997,7 @@ function selectArticles(mode) {
                                        if (cb) cb.attr("checked", false);
                                }
                        } else if (mode == "published") {
-                               var img = $("FPPIC-" + child.id.replace("RROW-", ""));
-
-                               if (img && img.src.match("pub_set")) {
+                               if (child.hasClassName("published")) {
                                        child.addClassName("Selected");
                                        if (cb) cb.attr("checked", true);
                                } else {
@@ -936,6 +1020,8 @@ function selectArticles(mode) {
                        }
                });
 
+               updateSelectedPrompt();
+
        } catch (e) {
                exception_error("selectArticles", e);
        }
@@ -1116,7 +1202,7 @@ function editArticleTags(id) {
                dojo.disconnect(tmph);
 
                        new Ajax.Autocompleter('tags_str', 'tags_choices',
-                          "backend.php?op=rpc&method=completeTags",
+                          "backend.php?op=article&method=completeTags",
                           { tokens: ',', paramName: "search" });
                });
 
@@ -1145,6 +1231,7 @@ function cdmScrollToArticleId(id, force) {
 
 function setActiveArticleId(id) {
        _active_article_id = id;
+       PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
 }
 
 function getActiveArticleId() {
@@ -1153,59 +1240,15 @@ function getActiveArticleId() {
 
 function postMouseIn(e, id) {
        post_under_pointer = id;
-
-       if (_post_preview_timeout) window.clearTimeout(_post_preview_timeout);
-
-       /* if (!isCdmMode() || !getInitParam("cdm_expanded")) {
-               _post_preview_timeout = window.setTimeout(function() {
-                       displaySmallArticlePreview(e, id);
-               }, 1000);
-       } */
-}
-
-function displaySmallArticlePreview(e, id) {
-       try {
-               var query = "?op=rpc&method=cdmarticlepreview&id=" + id;
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               cexc = $("CEXC-" + id);
-                               preview = $("small_article_preview");
-                               row = $("RROW-" + id);
-                               ctr = $("headlines-frame");
-
-                               if (id != getActiveArticleId() && (!isCdmMode() || (cexc && Element.visible(cexc))) && row && preview) {
-                                       preview.innerHTML = transport.responseText;
-                                       new Effect.Appear(preview, {duration:0.2});
-
-                                       preview.setStyle({
-                                               left: (e.clientX + 20) + 'px',
-                                               top: (row.offsetTop + row.offsetHeight*2 + 20 - ctr.scrollTop) + 'px' });
-
-                               }
-
-                       } });
-
-
-       } catch (e) {
-               exception_error("displaySmallArticlePreview", e);
-       }
 }
 
 function postMouseOut(id) {
        post_under_pointer = false;
-
-       if (_post_preview_timeout) window.clearTimeout(_post_preview_timeout);
-
-       if (Element.visible("small_article_preview"))
-               Element.hide("small_article_preview");
 }
 
 function unpackVisibleHeadlines() {
        try {
-
-               if (!isCdmMode()) return;
+               if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
 
                $$("#headlines-frame > div[id*=RROW]").each(
                        function(child) {
@@ -1215,6 +1258,8 @@ function unpackVisibleHeadlines() {
                                        var cencw = $("CENCW-" + child.id.replace("RROW-", ""));
 
                                        if (cencw) {
+                                               PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, child);
+
                                                cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
                                                cencw.setAttribute('id', '');
                                                Element.show(cencw);
@@ -1223,7 +1268,6 @@ function unpackVisibleHeadlines() {
                        }
                );
 
-
        } catch (e) {
                exception_error("unpackVisibleHeadlines", e);
        }
@@ -1235,6 +1279,32 @@ function headlines_scroll_handler(e) {
 
                unpackVisibleHeadlines();
 
+               // set topmost child in the buffer as active
+               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 &&
+                                       child.id.replace("RROW-", "") != _active_article_id) {
+
+                                       if (_active_article_id) {
+                                               var row = $("RROW-" + _active_article_id);
+                                               if (row) row.removeClassName("active");
+                                       }
+
+                                       _active_article_id = child.id.replace("RROW-", "");
+                                       showArticleInHeadlines(_active_article_id, true);
+                                       updateSelectedPrompt();
+                                       break;
+                               }
+                       }
+               }
+
                if (!_infscroll_disable) {
                        if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
                                        (e.scrollHeight != 0 &&
@@ -1249,11 +1319,24 @@ 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 (isCdmMode()) {
+                       updateFloatingTitle();
                }
 
                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 >
@@ -1266,6 +1349,7 @@ function headlines_scroll_handler(e) {
 
                                                //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
                                        }
+
                                });
 
                        if (catchup_id_batch.length > 0) {
@@ -1276,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) {
@@ -1283,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) {
@@ -1299,12 +1407,18 @@ 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);
                                        });
 
+                                       updateFloatingTitle(true);
+
                                } });
                }
 
@@ -1383,8 +1497,10 @@ function catchupRelativeToArticle(below, id) {
        }
 }
 
-function cdmCollapseArticle(event, id) {
+function cdmCollapseArticle(event, id, unmark) {
        try {
+               if (unmark == undefined) unmark = true;
+
                var row = $("RROW-" + id);
                var elem = $("CICD-" + id);
 
@@ -1395,15 +1511,28 @@ function cdmCollapseArticle(event, id) {
                        Element.hide(elem);
                        Element.show("CEXC-" + id);
                        Element.hide(collapse);
-                       row.removeClassName("active");
 
-                       markHeadline(id, false);
+                       if (unmark) {
+                               row.removeClassName("active");
+
+                               markHeadline(id, false);
 
-                       if (id == getActiveArticleId()) {
-                               setActiveArticleId(0);
+                               if (id == getActiveArticleId()) {
+                                       setActiveArticleId(0);
+                               }
+
+                               updateSelectedPrompt();
                        }
 
                        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) {
@@ -1411,7 +1540,7 @@ function cdmCollapseArticle(event, id) {
        }
 }
 
-function cdmExpandArticle(id) {
+function cdmExpandArticle(id, noexpand) {
        try {
                console.log("cdmExpandArticle " + id);
 
@@ -1448,7 +1577,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', '');
@@ -1465,10 +1594,13 @@ 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");
 
+               PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id);
+
        } catch (e) {
                exception_error("cdmExpandArticle", e);
        }
@@ -1476,26 +1608,6 @@ function cdmExpandArticle(id) {
        return false;
 }
 
-function fixHeadlinesOrder(ids) {
-       try {
-               for (var i = 0; i < ids.length; i++) {
-                       var e = $("RROW-" + ids[i]);
-
-                       if (e) {
-                               if (i % 2 == 0) {
-                                       e.removeClassName("even");
-                                       e.addClassName("odd");
-                               } else {
-                                       e.removeClassName("odd");
-                                       e.addClassName("even");
-                               }
-                       }
-               }
-       } catch (e) {
-               exception_error("fixHeadlinesOrder", e);
-       }
-}
-
 function getArticleUnderPointer() {
        return post_under_pointer;
 }
@@ -1525,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) {
@@ -1545,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);
                }
@@ -1568,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]);
                        }
@@ -1576,7 +1700,6 @@ function dismissSelectedArticles() {
                if (sel.length > 0)
                        selectionToggleUnread(false);
 
-               fixHeadlinesOrder(tmp);
 
        } catch (e) {
                exception_error("dismissSelectedArticles", e);
@@ -1596,15 +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]);
                        }
                }
 
-               fixHeadlinesOrder(tmp);
-
        } catch (e) {
-               exception_error("dismissSelectedArticles", e);
+               exception_error("dismissReadArticles", e);
        }
 }
 
@@ -1653,6 +1780,7 @@ function cdmClicked(event, id) {
 
                                if (article_is_unread) {
                                        decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
+                                       updateFloatingTitle(true);
                                }
 
                                var query = "?op=rpc&method=catchupSelected" +
@@ -1667,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);
@@ -1737,7 +1866,8 @@ function markHeadline(id, marked) {
 
        var row = $("RROW-" + id);
        if (row) {
-               var check = dijit.byId("RCHK-" + id);
+               var check = dijit.getEnclosingWidget(
+                               row.getElementsByClassName("rchk")[0]);
 
                if (check) {
                        check.attr("checked", marked);
@@ -1826,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);
-               });
+               if (dijit.byId("floatingMenu"))
+                       dijit.byId("floatingMenu").destroyRecursive();
 
-               var menu = new dijit.Menu({
-                       id: "headlinesMenu",
-                       targetNodeIds: ids,
-               });
+                       var menu = new dijit.Menu({
+                               id: "floatingMenu",
+                               targetNodeIds: ["floatingTitle"]
+                       });
 
-               var tmph = dojo.connect(menu, '_openMyself', function (event) {
-                       var callerNode = event.target, match = null, tries = 0;
+                       var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
 
-                       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, 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());
@@ -1887,18 +1998,18 @@ 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);
                                }}));
 
                menu.addChild(new dijit.MenuItem({
-                       label: __("Toggle marked"),
+                       label: __("Toggle starred"),
                        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);
@@ -1909,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);
@@ -1920,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);
                                }}));
 
 
@@ -1952,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];
 
@@ -1965,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];
 
@@ -1986,38 +2097,119 @@ function initHeadlinesMenu() {
 
                }
 
-               menu.startup();
 
        } catch (e) {
-               exception_error("initHeadlinesMenu", e);
+               exception_error("headlinesMenuCommon", e);
        }
 }
 
+function initHeadlinesMenu() {
+       try {
+               if (dijit.byId("headlinesMenu"))
+                       dijit.byId("headlinesMenu").destroyRecursive();
 
-function player(elem) {
-       var aid = elem.getAttribute("audio-id");
-       var status = elem.getAttribute("status");
-
-       var audio = $(aid);
+               var ids = [];
 
-       if (audio) {
-               if (status == 0) {
-                       audio.play();
-                       status = 1;
-                       elem.innerHTML = __("Playing...");
-                       elem.title = __("Click to pause");
-                       elem.addClassName("playing");
+               if (!isCdmMode()) {
+                       nodes = $$("#headlines-frame > div[id*=RROW]");
                } else {
-                       audio.pause();
-                       status = 0;
-                       elem.innerHTML = __("Play");
-                       elem.title = __("Click to play");
-                       elem.removeClassName("playing");
+                       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();
+
                }
 
-               elem.setAttribute("status", status);
-       } else {
-               alert("Your browser doesn't seem to support HTML5 audio.");
+       } catch (e) {
+               exception_error("initHeadlinesMenu", e);
        }
 }
 
@@ -2065,7 +2257,7 @@ function setSelectionScore() {
                        var score = prompt(__("Please enter new score for selected articles:"), score);
 
                        if (score != undefined) {
-                               var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
+                               var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
                                        "&score=" + param_escape(score);
 
                                new Ajax.Request("backend.php", {
@@ -2108,7 +2300,7 @@ function changeScore(id, pic) {
 
                if (new_score != undefined) {
 
-                       var query = "op=rpc&method=setScore&id=" + param_escape(id) +
+                       var query = "op=article&method=setScore&id=" + param_escape(id) +
                                "&score=" + param_escape(new_score);
 
                        new Ajax.Request("backend.php", {
@@ -2158,3 +2350,69 @@ function openSelectedAttachment(elem) {
                exception_error("openSelectedAttachment", e);
        }
 }
+
+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 && child.offsetTop + child.offsetHeight > hf.scrollTop) {
+
+                               var header = child.getElementsByClassName("cdmHeader")[0];
+
+                               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();
+
+                                               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");
+
+                               return;
+
+                       }
+               }
+
+       } catch (e) {
+               exception_error("updateFloatingTitle", e);
+       }
+}