]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
Merge pull request #176 from ArmyOfPirates/master
[tt-rss.git] / js / viewfeed.js
index da474a2c00fcee4267ac90ba4fa5cde7ccddeaf1..3e78f4ca9decf5b12863b33bf3dab236ae05385b 100644 (file)
@@ -12,6 +12,7 @@ var catchup_timeout_id = false;
 
 var cids_requested = [];
 var loaded_article_ids = [];
+var _last_headlines_update = 0;
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -19,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;
@@ -42,17 +41,16 @@ 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(
+                       /* dijit.getEnclosingWidget(
                                document.forms["main_toolbar_form"].update).attr('disabled',
-                                       is_cat || feed_id <= 0);
+                                       is_cat || feed_id <= 0); */
 
                        try {
                                if (infscroll_req == false) {
@@ -64,7 +62,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                        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;
@@ -91,11 +89,9 @@ 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();
 
@@ -158,16 +154,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 {
@@ -204,6 +194,19 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                }
 
                _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("");
 
@@ -223,6 +226,8 @@ function render_article(article) {
                        c.domNode.scrollTop = 0;
                } catch (e) { };
 
+               PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, article);
+
                c.attr('content', article);
 
                correctHeadlinesOffset(getActiveArticleId());
@@ -236,10 +241,9 @@ function render_article(article) {
        }
 }
 
-function showArticleInHeadlines(id) {
+function showArticleInHeadlines(id, noexpand) {
 
        try {
-
                selectArticles("none");
 
                var crow = $("RROW-" + id);
@@ -248,7 +252,9 @@ function showArticleInHeadlines(id) {
 
                var article_is_unread = crow.hasClassName("Unread");
 
-               crow.removeClassName("Unread");
+               if (!noexpand)
+                       crow.removeClassName("Unread");
+               crow.addClassName("active");
 
                selectArticles('none');
 
@@ -263,7 +269,7 @@ function showArticleInHeadlines(id) {
 
                markHeadline(id);
 
-               if (article_is_unread)
+               if (article_is_unread && !noexpand)
                        _force_scheduled_update = true;
 
        } catch (e) {
@@ -313,7 +319,7 @@ function article_callback2(transport, id) {
                var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
                request_counters(unread_in_buffer == 0);
 
-               headlines_scroll_handler($("headlines-frame"));
+               //headlines_scroll_handler($("headlines-frame"));
 
 /*             try {
                        if (!_infscroll_disable &&
@@ -331,11 +337,19 @@ function article_callback2(transport, id) {
        }
 }
 
-function view(id) {
+function view(id, activefeed, noexpand) {
        try {
+               var oldrow = $("RROW-" + getActiveArticleId());
+               if (oldrow) oldrow.removeClassName("active");
+
                var crow = $("RROW-" + id);
 
                if (!crow) return;
+               if (noexpand) {
+                       setActiveArticleId(id);
+                       showArticleInHeadlines(id, noexpand);
+                       return;
+               }
 
                console.log("loading article: " + id);
 
@@ -343,8 +357,6 @@ function view(id) {
 
                console.log("cache check result: " + (cached_article != false));
 
-               hideAuxDlg();
-
                var query = "?op=article&method=view&id=" + param_escape(id);
 
                var neighbor_ids = getRelativePostIds(id);
@@ -395,7 +407,7 @@ function view(id) {
                                        console.warn(e);
                                } */
 
-                               headlines_scroll_handler($("headlines-frame"));
+                               //headlines_scroll_handler($("headlines-frame"));
 
                                return;
                        }
@@ -426,21 +438,27 @@ 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 = row.getElementsByClassName("markedPic");
 
-               if (img.src.match("mark_unset")) {
-                       img.src = img.src.replace("mark_unset", "mark_set");
-                       img.alt = __("Unstar article");
-                       query = query + "&mark=1";
+               for (i = 0; i < imgs.length; i++) {
+                       var img = imgs[i];
 
-               } else {
-                       img.src = img.src.replace("mark_set", "mark_unset");
-                       img.alt = __("Star article");
-                       query = query + "&mark=0";
+                       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,
@@ -464,22 +482,30 @@ function togglePub(id, client_only, no_effects, note) {
                        query = query + "&note=undefined";
                }
 
-               var img = $("FPPIC-" + id);
-
-               if (!img) return;
+               var row = $("RROW-" + id);
+               if (!row) return;
 
-               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 imgs = row.getElementsByClassName("pubPic");
 
-               } else {
-                       img.src = img.src.replace("pub_set", "pub_unset");
-                       img.alt = __("Publish article");
+               for (i = 0; i < imgs.length; i++) {
+                       var img = imgs[i];
 
-                       query = query + "&pub=0";
+                       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,
@@ -493,7 +519,7 @@ function togglePub(id, client_only, no_effects, note) {
        }
 }
 
-function moveToPost(mode, noscroll) {
+function moveToPost(mode, noscroll, noexpand) {
 
        try {
 
@@ -537,16 +563,16 @@ function moveToPost(mode, noscroll) {
                                        if (!noscroll && article && article.offsetTop + article.offsetHeight >
                                                        ctr.scrollTop + ctr.offsetHeight) {
 
-                                               scrollArticle(ctr.offsetHeight/2);
+                                               scrollArticle(ctr.offsetHeight/4);
 
                                        } else if (next_id) {
-                                               cdmExpandArticle(next_id);
-                                               cdmScrollToArticleId(next_id, noscroll);
+                                               cdmExpandArticle(next_id, noexpand);
+                                               cdmScrollToArticleId(next_id, true);
                                        }
 
                                } else if (next_id) {
                                        correctHeadlinesOffset(next_id);
-                                       view(next_id, getActiveFeedId());
+                                       view(next_id, getActiveFeedId(), noexpand);
                                }
                        }
                }
@@ -559,19 +585,31 @@ function moveToPost(mode, noscroll) {
                                        var prev_article = $("RROW-" + prev_id);
                                        var ctr = $("headlines-frame");
 
-                                       if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
-                                               scrollArticle(-ctr.offsetHeight/3);
-                                       } else if (!noscroll && prev_article &&
-                                                       prev_article.offsetTop < ctr.scrollTop) {
-                                               cdmExpandArticle(prev_id);
-                                               scrollArticle(-ctr.offsetHeight/3);
-                                       } else if (prev_id) {
-                                               cdmExpandArticle(prev_id);
-                                               cdmScrollToArticleId(prev_id, noscroll);
+                                       if (!getInitParam("cdm_expanded")) {
+
+                                               if (!noscroll && article.offsetTop < ctr.scrollTop) {
+                                                       scrollArticle(-ctr.offsetHeight/4);
+                                               } else {
+                                                       cdmExpandArticle(prev_id, noexpand);
+                                                       cdmScrollToArticleId(prev_id, true);
+                                               }
+                                       } else {
+
+                                               if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
+                                                       scrollArticle(-ctr.offsetHeight/3);
+                                               } else if (!noscroll && prev_article &&
+                                                               prev_article.offsetTop < ctr.scrollTop) {
+                                                       cdmExpandArticle(prev_id, noexpand);
+                                                       scrollArticle(-ctr.offsetHeight/4);
+                                               } else if (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);
                                }
                        }
                }
@@ -583,11 +621,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);
@@ -596,11 +635,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 {
 
@@ -621,12 +682,6 @@ function toggleUnread(id, cmode, effect) {
                                if (row.hasClassName("Unread")) {
                                        row.removeClassName("Unread");
 
-                                       if (effect) {
-                                               new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
-                                                       afterFinish: toggleUnread_afh,
-                                                       queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
-                                       }
-
                                } else {
                                        row.addClassName("Unread");
                                }
@@ -635,12 +690,6 @@ function toggleUnread(id, cmode, effect) {
 
                                row.removeClassName("Unread");
 
-                               if (effect) {
-                                       new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
-                                               afterFinish: toggleUnread_afh,
-                                               queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
-                               }
-
                        } else if (cmode == 1) {
                                row.addClassName("Unread");
                        }
@@ -675,7 +724,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);
@@ -703,7 +752,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);
@@ -721,9 +770,9 @@ function selectionAssignLabel(id, ids) {
        }
 }
 
-function selectionToggleUnread(set_state, callback, no_error) {
+function selectionToggleUnread(set_state, callback, no_error, ids) {
        try {
-               var rows = getSelectedArticleIds2();
+               var rows = ids ? ids : getSelectedArticleIds2();
 
                if (rows.length == 0 && !no_error) {
                        alert(__("No articles are selected."));
@@ -782,12 +831,13 @@ function selectionToggleUnread(set_state, callback, no_error) {
        }
 }
 
-function selectionToggleMarked() {
+// sel_state ignored
+function selectionToggleMarked(sel_state, callback, no_error, ids) {
        try {
 
-               var rows = getSelectedArticleIds2();
+               var rows = ids ? ids : getSelectedArticleIds2();
 
-               if (rows.length == 0) {
+               if (rows.length == 0 && !no_error) {
                        alert(__("No articles are selected."));
                        return;
                }
@@ -805,6 +855,7 @@ function selectionToggleMarked() {
                                parameters: query,
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
+                                       if (callback) callback(transport);
                                } });
 
                }
@@ -814,12 +865,13 @@ function selectionToggleMarked() {
        }
 }
 
-function selectionTogglePublished() {
+// sel_state ignored
+function selectionTogglePublished(sel_state, callback, no_error, ids) {
        try {
 
-               var rows = getSelectedArticleIds2();
+               var rows = ids ? ids : getSelectedArticleIds2();
 
-               if (rows.length == 0) {
+               if (rows.length == 0 && !no_error) {
                        alert(__("No articles are selected."));
                        return;
                }
@@ -879,7 +931,9 @@ function selectArticles(mode) {
 
                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");
@@ -893,9 +947,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 {
@@ -903,9 +955,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 {
@@ -928,28 +978,13 @@ function selectArticles(mode) {
                        }
                });
 
+               updateSelectedPrompt();
+
        } catch (e) {
                exception_error("selectArticles", e);
        }
 }
 
-function catchupPage() {
-
-       var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
-
-       var str = __("Mark all visible articles in %s as read?");
-
-       str = str.replace("%s", fn);
-
-       if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
-               return;
-       }
-
-       selectArticles('all');
-       selectionToggleUnread(false, 'viewCurrentFeed()', true);
-       selectArticles('none');
-}
-
 function deleteSelection() {
 
        try {
@@ -965,9 +1000,9 @@ function deleteSelection() {
                var str;
 
                if (getActiveFeedId() != 0) {
-                       str = __("Delete %d selected articles in %s?");
+                       str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows.length);
                } else {
-                       str = __("Delete %d selected articles?");
+                       str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
                }
 
                str = str.replace("%d", rows.length);
@@ -1009,10 +1044,13 @@ function archiveSelection() {
                var op;
 
                if (getActiveFeedId() != 0) {
-                       str = __("Archive %d selected articles in %s?");
+                       str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
                        op = "archive";
                } else {
-                       str = __("Move %d archived articles back?");
+                       str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
+
+                       str += " " + __("Please note that unstarred articles might get purged on next feed update.");
+
                        op = "unarchive";
                }
 
@@ -1056,7 +1094,7 @@ function catchupSelection() {
 
                var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
 
-               var str = __("Mark %d selected articles in %s as read?");
+               var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
 
                str = str.replace("%d", rows.length);
                str = str.replace("%s", fn);
@@ -1073,7 +1111,7 @@ function catchupSelection() {
 }
 
 function editArticleTags(id) {
-               var query = "backend.php?op=dlg&method=editArticleTags&param=" + param_escape(id);
+               var query = "backend.php?op=article&method=editArticleTags&param=" + param_escape(id);
 
                if (dijit.byId("editTagsDlg"))
                        dijit.byId("editTagsDlg").destroyRecursive();
@@ -1091,22 +1129,25 @@ function editArticleTags(id) {
                                        new Ajax.Request("backend.php", {
                                        parameters: query,
                                        onComplete: function(transport) {
-                                               notify('');
-                                               dialog.hide();
+                                               try {
+                                                       notify('');
+                                                       dialog.hide();
 
-                                               var data = JSON.parse(transport.responseText);
+                                                       var data = JSON.parse(transport.responseText);
 
-                                               if (data) {
-                                                       var tags_str = article.tags;
-                                                       var id = tags_str.id;
+                                                       if (data) {
+                                                               var id = data.id;
 
-                                                       var tags = $("ATSTR-" + id);
-                                                       var tooltip = dijit.byId("ATSTRTIP-" + id);
+                                                               console.log(id);
 
-                                                       if (tags) tags.innerHTML = tags_str.content;
-                                                       if (tooltip) tooltip.attr('label', tags_str.content_full);
+                                                               var tags = $("ATSTR-" + id);
+                                                               var tooltip = dijit.byId("ATSTRTIP-" + id);
 
-                                                       cache_delete("article:" + id);
+                                                               if (tags) tags.innerHTML = data.content;
+                                                               if (tooltip) tooltip.attr('label', data.content_full);
+                                                       }
+                                               } catch (e) {
+                                                       exception_error("editArticleTags/inner", e);
                                                }
 
                                        }});
@@ -1119,7 +1160,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" });
                });
 
@@ -1136,7 +1177,9 @@ function cdmScrollToArticleId(id, force) {
 
                if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
                                e.offsetTop < ctr.scrollTop) {
-                       ctr.scrollTop = e.offsetTop;
+
+                       // expanded cdm has a 4px margin now
+                       ctr.scrollTop = parseInt(e.offsetTop) - 4;
                }
 
        } catch (e) {
@@ -1146,13 +1189,14 @@ function cdmScrollToArticleId(id, force) {
 
 function setActiveArticleId(id) {
        _active_article_id = id;
+       PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
 }
 
 function getActiveArticleId() {
        return _active_article_id;
 }
 
-function postMouseIn(id) {
+function postMouseIn(e, id) {
        post_under_pointer = id;
 }
 
@@ -1160,10 +1204,39 @@ function postMouseOut(id) {
        post_under_pointer = false;
 }
 
+function unpackVisibleHeadlines() {
+       try {
+               if (!isCdmMode()) return;
+
+               $$("#headlines-frame > div[id*=RROW]").each(
+                       function(child) {
+                               if (child.offsetTop <= $("headlines-frame").scrollTop +
+                                       $("headlines-frame").offsetHeight) {
+
+                                       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);
+                                       }
+                               }
+                       }
+               );
+
+       } catch (e) {
+               exception_error("unpackVisibleHeadlines", e);
+       }
+}
+
 function headlines_scroll_handler(e) {
        try {
                var hsp = $("headlines-spacer");
 
+               unpackVisibleHeadlines();
+
                if (!_infscroll_disable) {
                        if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
                                        (e.scrollHeight != 0 &&
@@ -1183,9 +1256,13 @@ function headlines_scroll_handler(e) {
 
                if (getInitParam("cdm_auto_catchup") == 1) {
 
+                       // let's get DOM some time to settle down
+                       var ts = new Date().getTime();
+                       if (ts - _last_headlines_update < 100) return;
+
                        $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
                                function(child) {
-                                       if ($("headlines-frame").scrollTop >
+                                       if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
                                                        (child.offsetTop + child.offsetHeight/2)) {
 
                                                var id = child.id.replace("RROW-", "");
@@ -1202,7 +1279,7 @@ function headlines_scroll_handler(e) {
 
                                if (!_infscroll_request_sent) {
                                        catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
-                                               2000);
+                                               500);
                                }
                        }
                }
@@ -1228,7 +1305,11 @@ function catchupBatchedArticles() {
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
 
+                                       reply = JSON.parse(transport.responseText);
+                                       var batch = reply.ids;
+
                                        batch.each(function(id) {
+                                               console.log(id);
                                                var elem = $("RROW-" + id);
                                                if (elem) elem.removeClassName("Unread");
                                                catchup_id_batch.remove(id);
@@ -1286,7 +1367,7 @@ function catchupRelativeToArticle(below, id) {
                if (ids_to_mark.length == 0) {
                        alert(__("No articles found to mark"));
                } else {
-                       var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
+                       var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
 
                        if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
 
@@ -1312,14 +1393,14 @@ 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);
 
                if (elem && row) {
-                       row.removeClassName("Selected");
-
                        var collapse = $$("div#RROW-" + id +
                                " span[class='collapseBtn']")[0];
 
@@ -1327,13 +1408,19 @@ function cdmCollapseArticle(event, id) {
                        Element.show("CEXC-" + id);
                        Element.hide(collapse);
 
-                       markHeadline(id, false);
+                       if (unmark) {
+                               row.removeClassName("active");
 
-                       if (id == getActiveArticleId()) {
-                               setActiveArticleId(0);
+                               markHeadline(id, false);
+
+                               if (id == getActiveArticleId()) {
+                                       setActiveArticleId(0);
+                               }
                        }
 
                        if (event) Event.stop(event);
+
+                       PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
                }
 
        } catch (e) {
@@ -1341,10 +1428,13 @@ function cdmCollapseArticle(event, id) {
        }
 }
 
-function cdmExpandArticle(id) {
+function cdmExpandArticle(id, noexpand) {
        try {
+               console.log("cdmExpandArticle " + id);
+
+               if (!$("RROW-" + id)) return false;
 
-               hideAuxDlg();
+               var oldrow = $("RROW-" + getActiveArticleId());
 
                var elem = $("CICD-" + getActiveArticleId());
 
@@ -1364,22 +1454,40 @@ function cdmExpandArticle(id) {
                        Element.hide(collapse);
                }
 
+               if (oldrow) oldrow.removeClassName("active");
+
                setActiveArticleId(id);
-               cdmScrollToArticleId(id, true);
 
                elem = $("CICD-" + id);
 
                var collapse = $$("div#RROW-" + id +
                                " span[class='collapseBtn']")[0];
 
-               if (!Element.visible(elem)) {
+               var cencw = $("CENCW-" + id);
+
+               if (!Element.visible(elem) && !noexpand) {
+                       if (cencw) {
+                               cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
+                               cencw.setAttribute('id', '');
+                               Element.show(cencw);
+                       }
+
                        Element.show(elem);
                        Element.hide("CEXC-" + id);
                        Element.show(collapse);
                }
 
-               toggleUnread(id, 0, true);
+               var new_offset = $("RROW-" + id).offsetTop;
+
+               if (old_offset > new_offset)
+                       $("headlines-frame").scrollTop -= (old_offset-new_offset);
+
+               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);
@@ -1451,6 +1559,8 @@ function dismissArticle(id) {
        try {
                var elem = $("RROW-" + id);
 
+               if (!elem) return;
+
                toggleUnread(id, 0, true);
 
                new Effect.Fade(elem, {duration : 0.5});
@@ -1540,23 +1650,24 @@ function cdmClicked(event, id) {
        try {
                //var shift_key = event.shiftKey;
 
-               hideAuxDlg();
-
                if (!event.ctrlKey) {
 
                        if (!getInitParam("cdm_expanded")) {
-                               if (event) Event.stop(event);
                                return cdmExpandArticle(id);
                        } else {
 
+                               var elem = $("RROW-" + getActiveArticleId());
+
+                               if (elem) elem.removeClassName("active");
+
                                selectArticles("none");
                                toggleSelected(id);
 
                                var elem = $("RROW-" + id);
                                var article_is_unread = elem.hasClassName("Unread");
 
-                               if (elem)
-                                       elem.removeClassName("Unread");
+                               elem.removeClassName("Unread");
+                               elem.addClassName("active");
 
                                setActiveArticleId(id);
 
@@ -1646,13 +1757,17 @@ 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);
                }
 
-               row.addClassName("Selected");
+               if (marked)
+                       row.addClassName("Selected");
+               else
+                       row.removeClassName("Selected");
        }
 }
 
@@ -1780,6 +1895,47 @@ function initHeadlinesMenu() {
                                openArticleInNewWindow(this.getParent().callerRowId);
                        }}));
 
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Display article URL"),
+                       onClick: function(event) {
+                               displayArticleUrl(this.getParent().callerRowId);
+                       }}));
+
+               menu.addChild(new dijit.MenuSeparator());
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Toggle unread"),
+                       onClick: function(event) {
+                               var ids = getSelectedArticleIds2();
+                               // cast to string
+                               var 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"),
+                       onClick: function(event) {
+                               var ids = getSelectedArticleIds2();
+                               // cast to string
+                               var id = this.getParent().callerRowId + "";
+                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                               selectionToggleMarked(undefined, false, true, ids);
+                               }}));
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Toggle published"),
+                       onClick: function(event) {
+                               var ids = getSelectedArticleIds2();
+                               // cast to string
+                               var id = this.getParent().callerRowId + "";
+                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                               selectionTogglePublished(undefined, false, true, ids);
+                               }}));
+
                menu.addChild(new dijit.MenuSeparator());
 
                menu.addChild(new dijit.MenuItem({
@@ -1809,7 +1965,7 @@ function initHeadlinesMenu() {
                                var bare_id = id.substr(id.indexOf(":")+1);
                                var name = label.name[0];
 
-                               bare_id = -11-bare_id;
+                               bare_id = feed_to_label_id(bare_id);
 
                                labelAddMenu.addChild(new dijit.MenuItem({
                                        label: name,
@@ -1858,34 +2014,6 @@ function initHeadlinesMenu() {
        }
 }
 
-
-function player(elem) {
-       var aid = elem.getAttribute("audio-id");
-       var status = elem.getAttribute("status");
-
-       var audio = $(aid);
-
-       if (audio) {
-               if (status == 0) {
-                       audio.play();
-                       status = 1;
-                       elem.innerHTML = __("Playing...");
-                       elem.title = __("Click to pause");
-                       elem.addClassName("playing");
-               } else {
-                       audio.pause();
-                       status = 0;
-                       elem.innerHTML = __("Play");
-                       elem.title = __("Click to play");
-                       elem.removeClassName("playing");
-               }
-
-               elem.setAttribute("status", status);
-       } else {
-               alert("Your browser doesn't seem to support HTML5 audio.");
-       }
-}
-
 function cache_set(id, obj) {
        //console.log("cache_set: " + id);
        if (has_storage)
@@ -1930,7 +2058,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", {
@@ -1973,7 +2101,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", {
@@ -1991,3 +2119,35 @@ function changeScore(id, pic) {
                exception_error("changeScore", e);
        }
 }
+
+function displayArticleUrl(id) {
+       try {
+               var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       var reply = JSON.parse(transport.responseText);
+
+                                       if (reply && reply.link) {
+                                               prompt(__("Article URL:"), reply.link);
+                                       }
+                               } });
+       } catch (e) {
+               exception_error("changeScore", e);
+       }
+}
+
+function openSelectedAttachment(elem) {
+       try {
+               var url = elem[elem.selectedIndex].value;
+
+               if (url) {
+                       window.open(url);
+                       elem.selectedIndex = 0;
+               }
+
+       } catch (e) {
+               exception_error("openSelectedAttachment", e);
+       }
+}