]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
only unmark articles which had been processed when automarking (for realz)
[tt-rss.git] / js / viewfeed.js
index a950ec7a4b7d03d613f272fe1d5bd6d5ef9df1a5..7813ab7ef7f3c3f90e37b61198f235538fab5891 100644 (file)
@@ -1,7 +1,7 @@
-var active_post_id = false;
-
 var article_cache = new Array();
 
+var _active_article_id = 0;
+
 var vgroup_last_feed = false;
 var post_under_pointer = false;
 
@@ -9,11 +9,10 @@ var last_requested_article = false;
 
 var catchup_id_batch = [];
 var catchup_timeout_id = false;
-var feed_precache_timeout_id = false;
-var precache_idle_timeout_id = false;
 
 var cids_requested = [];
 var loaded_article_ids = [];
+var _last_headlines_update = 0;
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -47,19 +46,17 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                if (getInitParam("cdm_auto_catchup") == 1) {
                                        content = content + "<div id='headlines-spacer'></div>";
                                }
-
-                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], content);
                                return;
                        }
 
                        setActiveFeedId(feed_id, is_cat);
 
-                       dijit.getEnclosingWidget(
+                       /* dijit.getEnclosingWidget(
                                document.forms["main_toolbar_form"].update).attr('disabled',
-                                       is_cat || feed_id <= 0);
+                                       is_cat || feed_id <= 0); */
 
                        try {
-                               if (offset == 0 && infscroll_req == false) {
+                               if (infscroll_req == false) {
                                        $("headlines-frame").scrollTop = 0;
                                }
                        } catch (e) { };
@@ -68,7 +65,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;
@@ -78,7 +75,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        var articles = reply['articles'];
                        //var runtime_info = reply['runtime-info'];
 
-                       if (offset == 0 && infscroll_req == false) {
+                       if (infscroll_req == false) {
                                loaded_article_ids = [];
 
                                dijit.byId("headlines-frame").attr('content',
@@ -183,9 +180,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                }
                        }
 
-                       if (headlines_count > 0)
-                               cache_headlines(feed_id, is_cat, reply['headlines']['toolbar'], $("headlines-frame").innerHTML);
-
                        if (articles) {
                                for (var i = 0; i < articles.length; i++) {
                                        var a_id = articles[i]['id'];
@@ -195,10 +189,6 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                console.log("no cached articles received");
                        }
 
-                       // do not precache stuff after fresh feed
-                       if (feed_id != -3)
-                               precache_headlines();
-
                        if (counters)
                                parse_counters(counters);
                        else
@@ -211,10 +201,13 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        "</div>");
                } else {
                        //notify_error("Error communicating with server.");
-                       Element.show("net-alert");
+                       Element.show(dijit.byId("net-alert").domNode);
                }
 
                _infscroll_request_sent = 0;
+               _last_headlines_update = new Date().getTime();
+
+               unpackVisibleHeadlines();
 
                notify("");
 
@@ -250,7 +243,6 @@ function render_article(article) {
 function showArticleInHeadlines(id) {
 
        try {
-
                selectArticles("none");
 
                var crow = $("RROW-" + id);
@@ -260,6 +252,7 @@ function showArticleInHeadlines(id) {
                var article_is_unread = crow.hasClassName("Unread");
 
                crow.removeClassName("Unread");
+               crow.addClassName("active");
 
                selectArticles('none');
 
@@ -272,10 +265,6 @@ function showArticleInHeadlines(id) {
                        //
                }
 
-               if (article_is_unread && view_mode == "all_articles") {
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-               }
-
                markHeadline(id);
 
                if (article_is_unread)
@@ -303,7 +292,7 @@ function article_callback2(transport, id) {
                if (reply) {
 
                        reply.each(function(article) {
-                               if (active_post_id == article['id']) {
+                               if (getActiveArticleId() == article['id']) {
                                        render_article(article['content']);
                                }
                                cids_requested.remove(article['id']);
@@ -322,12 +311,13 @@ function article_callback2(transport, id) {
                        render_article("<div class='whiteBox'>" +
                                        __('Could not display article (invalid object received - see error console for details)') + "</div>");
                } else {
-                       Element.show("net-alert");
+                       Element.show(dijit.byId("net-alert").domNode);
                }
 
-               request_counters();
+               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 &&
@@ -347,14 +337,19 @@ function article_callback2(transport, id) {
 
 function view(id) {
        try {
+               var oldrow = $("RROW-" + getActiveArticleId());
+               if (oldrow) oldrow.removeClassName("active");
+
+               var crow = $("RROW-" + id);
+
+               if (!crow) return;
+
                console.log("loading article: " + id);
 
                var cached_article = cache_get("article:" + 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);
@@ -375,14 +370,11 @@ function view(id) {
 
                query = query + "&cids=" + cids_to_request.toString();
 
-               var crow = $("RROW-" + id);
                var article_is_unread = crow.hasClassName("Unread");
 
-               active_post_id = id;
+               setActiveArticleId(id);
                showArticleInHeadlines(id);
 
-               precache_headlines();
-
                if (cached_article && article_is_unread) {
 
                        query = query + "&mode=prefetch";
@@ -408,7 +400,7 @@ function view(id) {
                                        console.warn(e);
                                } */
 
-                               headlines_scroll_handler($("headlines-frame"));
+                               //headlines_scroll_handler($("headlines-frame"));
 
                                return;
                        }
@@ -454,8 +446,6 @@ function toggleMark(id, client_only) {
                        query = query + "&mark=0";
                }
 
-               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -495,8 +485,6 @@ function togglePub(id, client_only, no_effects, note) {
                        query = query + "&pub=0";
                }
 
-               cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                if (!client_only) {
                        new Ajax.Request("backend.php", {
                                parameters: query,
@@ -510,7 +498,7 @@ function togglePub(id, client_only, no_effects, note) {
        }
 }
 
-function moveToPost(mode) {
+function moveToPost(mode, noscroll) {
 
        try {
 
@@ -519,22 +507,22 @@ function moveToPost(mode) {
                var prev_id = false;
                var next_id = false;
 
-               if (!$('RROW-' + active_post_id)) {
-                       active_post_id = false;
+               if (!$('RROW-' + getActiveArticleId())) {
+                       setActiveArticleId(0);
                }
 
-               if (active_post_id == false) {
+               if (!getActiveArticleId()) {
                        next_id = rows[0];
                        prev_id = rows[rows.length-1]
                } else {
                        for (var i = 0; i < rows.length; i++) {
-                               if (rows[i] == active_post_id) {
+                               if (rows[i] == getActiveArticleId()) {
 
                                        // Account for adjacent identical article ids.
                                        if (i > 0) prev_id = rows[i-1];
 
                                        for (var j = i+1; j < rows.length; j++) {
-                                               if (rows[j] != active_post_id) {
+                                               if (rows[j] != getActiveArticleId()) {
                                                        next_id = rows[j];
                                                        break;
                                                }
@@ -545,13 +533,23 @@ function moveToPost(mode) {
                }
 
                if (mode == "next") {
-                       if (next_id) {
+                       if (next_id || getActiveArticleId()) {
                                if (isCdmMode()) {
 
-                                       cdmExpandArticle(next_id);
-                                       cdmScrollToArticleId(next_id);
+                                       var article = $("RROW-" + getActiveArticleId());
+                                       var ctr = $("headlines-frame");
 
-                               } else {
+                                       if (!noscroll && article && article.offsetTop + article.offsetHeight >
+                                                       ctr.scrollTop + ctr.offsetHeight) {
+
+                                               scrollArticle(ctr.offsetHeight/4);
+
+                                       } else if (next_id) {
+                                               cdmExpandArticle(next_id);
+                                               cdmScrollToArticleId(next_id, true);
+                                       }
+
+                               } else if (next_id) {
                                        correctHeadlinesOffset(next_id);
                                        view(next_id, getActiveFeedId());
                                }
@@ -559,11 +557,36 @@ function moveToPost(mode) {
                }
 
                if (mode == "prev") {
-                       if (prev_id) {
+                       if (prev_id || getActiveArticleId()) {
                                if (isCdmMode()) {
-                                       cdmExpandArticle(prev_id);
-                                       cdmScrollToArticleId(prev_id);
-                               } else {
+
+                                       var article = $("RROW-" + getActiveArticleId());
+                                       var prev_article = $("RROW-" + prev_id);
+                                       var ctr = $("headlines-frame");
+
+                                       if (!getInitParam("cdm_expanded")) {
+
+                                               if (!noscroll && article.offsetTop < ctr.scrollTop) {
+                                                       scrollArticle(-ctr.offsetHeight/4);
+                                               } else {
+                                                       cdmExpandArticle(prev_id);
+                                                       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);
+                                                       scrollArticle(-ctr.offsetHeight/4);
+                                               } else if (prev_id) {
+                                                       cdmExpandArticle(prev_id);
+                                                       cdmScrollToArticleId(prev_id, noscroll);
+                                               }
+                                       }
+
+                               } else if (prev_id) {
                                        correctHeadlinesOffset(prev_id);
                                        view(prev_id, getActiveFeedId());
                                }
@@ -615,12 +638,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");
                                }
@@ -629,12 +646,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");
                        }
@@ -669,7 +680,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);
@@ -697,7 +708,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);
@@ -715,9 +726,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."));
@@ -776,12 +787,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;
                }
@@ -799,6 +811,7 @@ function selectionToggleMarked() {
                                parameters: query,
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
+                                       if (callback) callback(transport);
                                } });
 
                }
@@ -808,12 +821,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;
                }
@@ -927,23 +941,6 @@ function selectArticles(mode) {
        }
 }
 
-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 {
@@ -959,9 +956,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);
@@ -1003,10 +1000,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";
                }
 
@@ -1050,7 +1050,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);
@@ -1067,7 +1067,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();
@@ -1085,22 +1085,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);
                                                }
 
                                        }});
@@ -1113,7 +1116,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" });
                });
 
@@ -1121,25 +1124,34 @@ function editArticleTags(id) {
 
 }
 
-function cdmScrollToArticleId(id) {
+function cdmScrollToArticleId(id, force) {
        try {
                var ctr = $("headlines-frame");
                var e = $("RROW-" + id);
 
                if (!e || !ctr) return;
 
-               ctr.scrollTop = e.offsetTop;
+               if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
+                               e.offsetTop < ctr.scrollTop) {
+
+                       // expanded cdm has a 4px margin now
+                       ctr.scrollTop = parseInt(e.offsetTop) - 4;
+               }
 
        } catch (e) {
                exception_error("cdmScrollToArticleId", e);
        }
 }
 
+function setActiveArticleId(id) {
+       _active_article_id = id;
+}
+
 function getActiveArticleId() {
-       return active_post_id;
+       return _active_article_id;
 }
 
-function postMouseIn(id) {
+function postMouseIn(e, id) {
        post_under_pointer = id;
 }
 
@@ -1147,10 +1159,37 @@ 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) {
+                                               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 &&
@@ -1170,9 +1209,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-", "");
@@ -1189,7 +1232,7 @@ function headlines_scroll_handler(e) {
 
                                if (!_infscroll_request_sent) {
                                        catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
-                                               2000);
+                                               500);
                                }
                        }
                }
@@ -1215,7 +1258,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);
@@ -1273,7 +1320,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)) {
 
@@ -1299,43 +1346,91 @@ function catchupRelativeToArticle(below, id) {
        }
 }
 
+function cdmCollapseArticle(event, id) {
+       try {
+               var row = $("RROW-" + id);
+               var elem = $("CICD-" + id);
+
+               if (elem && row) {
+                       var collapse = $$("div#RROW-" + id +
+                               " span[class='collapseBtn']")[0];
+
+                       Element.hide(elem);
+                       Element.show("CEXC-" + id);
+                       Element.hide(collapse);
+                       row.removeClassName("active");
+
+                       markHeadline(id, false);
+
+                       if (id == getActiveArticleId()) {
+                               setActiveArticleId(0);
+                       }
+
+                       if (event) Event.stop(event);
+               }
+
+       } catch (e) {
+               exception_error("cdmCollapseArticle", e);
+       }
+}
+
 function cdmExpandArticle(id) {
        try {
+               console.log("cdmExpandArticle " + id);
+
+               if (!$("RROW-" + id)) return false;
 
-               hideAuxDlg();
+               var oldrow = $("RROW-" + getActiveArticleId());
 
-               var elem = $("CICD-" + active_post_id);
+               var elem = $("CICD-" + getActiveArticleId());
 
-               if (id == active_post_id && Element.visible(elem))
+               if (id == getActiveArticleId() && Element.visible(elem))
                        return true;
 
                selectArticles("none");
 
                var old_offset = $("RROW-" + id).offsetTop;
 
-               if (active_post_id && elem && !getInitParam("cdm_expanded")) {
+               if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
+                       var collapse = $$("div#RROW-" + getActiveArticleId() +
+                               " span[class='collapseBtn']")[0];
+
                        Element.hide(elem);
-                       Element.show("CEXC-" + active_post_id);
+                       Element.show("CEXC-" + getActiveArticleId());
+                       Element.hide(collapse);
                }
 
-               active_post_id = id;
+               if (oldrow) oldrow.removeClassName("active");
+
+               setActiveArticleId(id);
 
                elem = $("CICD-" + id);
 
+               var collapse = $$("div#RROW-" + id +
+                               " span[class='collapseBtn']")[0];
+
+               var cencw = $("CENCW-" + id);
+
                if (!Element.visible(elem)) {
+                       if (cencw) {
+                               cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
+                               cencw.setAttribute('id', '');
+                               Element.show(cencw);
+                       }
+
                        Element.show(elem);
                        Element.hide("CEXC-" + id);
+                       Element.show(collapse);
                }
 
                var new_offset = $("RROW-" + id).offsetTop;
 
-               $("headlines-frame").scrollTop += (new_offset-old_offset);
-
-               if ($("RROW-" + id).offsetTop != old_offset)
-                       $("headlines-frame").scrollTop = new_offset;
+               if (old_offset > new_offset)
+                       $("headlines-frame").scrollTop -= (old_offset-new_offset);
 
                toggleUnread(id, 0, true);
                toggleSelected(id);
+               $("RROW-" + id).addClassName("active");
 
        } catch (e) {
                exception_error("cdmExpandArticle", e);
@@ -1368,61 +1463,6 @@ function getArticleUnderPointer() {
        return post_under_pointer;
 }
 
-function zoomToArticle(event, id) {
-       try {
-               var cached_article = cache_get("article: " + id);
-
-               if (dijit.byId("ATSTRTIP-" + id))
-                       dijit.byId("ATSTRTIP-" + id).destroyRecursive();
-
-               if (cached_article) {
-                       //closeArticlePanel();
-
-                       var article_pane = new dijit.layout.ContentPane({
-                               title: __("Loading...") , content: cached_article,
-                               style: 'padding : 0px;',
-                               id: 'ATAB-' + id,
-                               closable: true });
-
-                       if ($("PTITLE-" + id))
-                               article_pane.attr('title', $("PTITLE-" + id).innerHTML);
-
-               } else {
-
-                       var query = "?op=rpc&method=getArticles&ids=" + param_escape(id);
-
-                       notify_progress("Loading, please wait...", true);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) {
-                                       notify('');
-
-                                       var reply = JSON.parse(transport.responseText);
-
-                                       if (reply) {
-                                               //closeArticlePanel();
-
-                                               var content = reply[0]['content'];
-
-                                               var article_pane = new dijit.layout.ContentPane({
-                                                       title: "article-" + id , content: content,
-                                                       style: 'padding : 0px;',
-                                                       id: 'ATAB-' + id,
-                                                       closable: true });
-
-                                               if ($("PTITLE-" + id))
-                                                       article_pane.attr('title', $("PTITLE-" + id).innerHTML);
-                                       }
-
-                               } });
-                       }
-
-       } catch (e) {
-               exception_error("zoomToArticle", e);
-       }
-}
-
 function scrollArticle(offset) {
        try {
                if (!isCdmMode()) {
@@ -1452,9 +1492,6 @@ function show_labels_in_headlines(transport) {
 
                                if (ctr) ctr.innerHTML = elem.labels;
                        });
-
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
                }
        } catch (e) {
                exception_error("show_labels_in_headlines", e);
@@ -1465,11 +1502,15 @@ function dismissArticle(id) {
        try {
                var elem = $("RROW-" + id);
 
+               if (!elem) return;
+
                toggleUnread(id, 0, true);
 
                new Effect.Fade(elem, {duration : 0.5});
 
-               active_post_id = false;
+               if (id == getActiveArticleId()) {
+                       setActiveArticleId(0);
+               }
 
        } catch (e) {
                exception_error("dismissArticle", e);
@@ -1487,7 +1528,7 @@ function dismissSelectedArticles() {
                        var elem = $("RROW-" + ids[i]);
 
                        if (elem.className && elem.hasClassName("Selected") &&
-                                       ids[i] != active_post_id) {
+                                       ids[i] != getActiveArticleId()) {
                                new Effect.Fade(elem, {duration : 0.5});
                                sel.push(ids[i]);
                        } else {
@@ -1552,24 +1593,26 @@ function cdmClicked(event, id) {
        try {
                //var shift_key = event.shiftKey;
 
-               hideAuxDlg();
-
                if (!event.ctrlKey) {
 
                        if (!getInitParam("cdm_expanded")) {
                                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");
 
-                               active_post_id = id;
+                               setActiveArticleId(id);
 
                                if (article_is_unread) {
                                        decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
@@ -1584,7 +1627,7 @@ function cdmClicked(event, id) {
                                                handle_rpc_json(transport);
                                        } });
 
-                               return true;
+                               return !event.shiftKey;
                        }
 
                } else {
@@ -1602,7 +1645,8 @@ function cdmClicked(event, id) {
                        openArticleInNewWindow(id);
                }
 
-               request_counters();
+               var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
+               request_counters(unread_in_buffer == 0);
 
        } catch (e) {
                exception_error("cdmClicked");
@@ -1651,16 +1695,21 @@ function isCdmMode() {
        return getInitParam("combined_display_mode");
 }
 
-function markHeadline(id) {
+function markHeadline(id, marked) {
+       if (marked == undefined) marked = true;
+
        var row = $("RROW-" + id);
        if (row) {
                var check = dijit.byId("RCHK-" + id);
 
                if (check) {
-                       check.attr("checked", true);
+                       check.attr("checked", marked);
                }
 
-               row.addClassName("Selected");
+               if (marked)
+                       row.addClassName("Selected");
+               else
+                       row.removeClassName("Selected");
        }
 }
 
@@ -1788,6 +1837,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({
@@ -1817,7 +1907,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,
@@ -1919,107 +2009,6 @@ function cache_delete(id) {
                sessionStorage.removeItem(id);
 }
 
-function cache_headlines(feed, is_cat, toolbar_obj, content_obj) {
-       if (toolbar_obj && content_obj) {
-               cache_set("feed:" + feed + ":" + is_cat,
-                       JSON.stringify({toolbar: toolbar_obj, content: content_obj}));
-       } else {
-               try {
-                       obj =   cache_get("feed:" + feed + ":" + is_cat);
-
-                       if (obj) {
-                               obj = JSON.parse(obj);
-
-                               if (toolbar_obj) obj.toolbar = toolbar_obj;
-                               if (content_obj) obj.content = content_obj;
-
-                               cache_set("feed:" + feed + ":" + is_cat, JSON.stringify(obj));
-                       }
-
-               } catch (e) {
-                       console.warn("cache_headlines failed: " + e);
-               }
-       }
-}
-
-function render_local_headlines(feed, is_cat, obj) {
-       try {
-
-               dijit.byId("headlines-toolbar").attr('content',
-                       obj.toolbar);
-
-               dijit.byId("headlines-frame").attr('content',
-                       obj.content);
-
-               dojo.parser.parse('headlines-toolbar');
-
-               $("headlines-frame").scrollTop = 0;
-               selectArticles('none');
-               setActiveFeedId(feed, is_cat);
-               initHeadlinesMenu();
-
-               dijit.getEnclosingWidget(
-                       document.forms["main_toolbar_form"].update).attr('disabled',
-                               is_cat || feed <= 0);
-
-               precache_headlines();
-
-       } catch (e) {
-               exception_error("render_local_headlines", e);
-       }
-}
-
-function precache_headlines_idle() {
-       try {
-               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
-                       if (get_timestamp() - _viewfeed_last > 120) {
-
-                               var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
-                               var uncached = [];
-
-                               feeds.each(function(item) {
-                                       if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
-                                               uncached.push(item);
-                               });
-
-                               if (uncached.length > 0) {
-                                       var rf = uncached[Math.floor(Math.random()*uncached.length)];
-                                       viewfeed(rf[0], '', rf[1], 0, true);
-                               }
-                       }
-               }
-               precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
-
-       } catch (e) {
-               exception_error("precache_headlines_idle", e);
-       }
-}
-
-function precache_headlines() {
-       try {
-               if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id) {
-
-                       feed_precache_timeout_id = window.setTimeout(function() {
-                               var nuf = getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
-                               var nf = dijit.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
-
-                               if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
-                                       viewfeed(nuf, '', activeFeedIsCat(), 0, true);
-
-                               if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
-                                       viewfeed(nf[0], '', nf[1], 0, true);
-
-                               window.setTimeout(function() {
-                                       feed_precache_timeout_id = false;
-                                       }, 3000);
-                       }, 1000);
-               }
-
-       } catch (e) {
-               exception_error("precache_headlines", e);
-       }
-}
-
 function cancelSearch() {
        try {
                _search_query = "";
@@ -2039,7 +2028,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", {
@@ -2082,7 +2071,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", {
@@ -2100,3 +2089,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);
+       }
+}