]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
add net-alert icon
[tt-rss.git] / js / viewfeed.js
index d267c7693e02ea821e30dbca7f940cbd69818db8..d6801a186a1e8a201e63a91397d26d9a785b7311 100644 (file)
@@ -13,6 +13,7 @@ var feed_precache_timeout_id = false;
 var precache_idle_timeout_id = false;
 
 var cids_requested = [];
+var loaded_article_ids = [];
 
 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
 
@@ -53,6 +54,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                        setActiveFeedId(feed_id, is_cat);
 
+                       dijit.getEnclosingWidget(
+                               document.forms["main_toolbar_form"].update).attr('disabled',
+                                       is_cat || feed_id <= 0);
+
                        try {
                                if (offset == 0 && infscroll_req == false) {
                                        $("headlines-frame").scrollTop = 0;
@@ -74,12 +79,21 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        //var runtime_info = reply['runtime-info'];
 
                        if (offset == 0 && infscroll_req == false) {
+                               loaded_article_ids = [];
+
                                dijit.byId("headlines-frame").attr('content',
                                        reply['headlines']['content']);
 
                                dijit.byId("headlines-toolbar").attr('content',
                                        reply['headlines']['toolbar']);
 
+                               $$("#headlines-frame > div[id*=RROW]").each(function(row) {
+                                       if (loaded_article_ids.indexOf(row.id) != -1) {
+                                               row.parentNode.removeChild(row);
+                                       } else {
+                                               loaded_article_ids.push(row.id);
+                                       }
+                               });
 
                                if (getInitParam("cdm_auto_catchup") == 1) {
                                        var hsp = $("headlines-spacer");
@@ -89,13 +103,20 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                initHeadlinesMenu();
 
+                               if (_search_query) {
+                                       $("feed_title").innerHTML += "<span id='cancel_search'>" +
+                                               " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
+                                               "</span>";
+                               }
+
                        } else {
 
                                if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
-                                       console.log("adding some more headlines...");
+                                       console.log("adding some more headlines: " + headlines_count);
 
                                        var c = dijit.byId("headlines-frame");
                                        var ids = getSelectedArticleIds2();
+                                       var new_elems = [];
 
                                        $("headlines-tmp").innerHTML = reply['headlines']['content'];
 
@@ -105,9 +126,15 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                c.domNode.removeChild(hsp);
 
                                        $$("#headlines-tmp > div").each(function(row) {
-                                               if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
+                                               if (row.className == 'cdmFeedTitle') {
                                                        row.style.display = 'none';
                                                        c.domNode.appendChild(row);
+                                                       new_elems.push(row);
+                                               } else if (loaded_article_ids.indexOf(row.id) == -1) {
+                                                       row.style.display = 'none';
+                                                       c.domNode.appendChild(row);
+                                                       new_elems.push(row);
+                                                       loaded_article_ids.push(row.id);
                                                } else {
                                                        row.parentNode.removeChild(row);
                                                }
@@ -121,6 +148,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                c.domNode.appendChild(hsp);
                                        }
 
+                                       console.log("added " + new_elems.size() + " headlines");
+
+                                       if (new_elems.size() == 0)
+                                               _infscroll_disable = true;
+
                                        console.log("restore selected ids: " + ids);
 
                                        for (var i = 0; i < ids.length; i++) {
@@ -129,10 +161,17 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                                        initHeadlinesMenu();
 
-                                       $$("#headlines-frame > div[id*=RROW]").each(
-                                       function(child) {
-                                               if (!Element.visible(child))
-                                                       new Effect.Appear(child, { duration : 0.5 });
+                                       new_elems.each(function(child) {
+                                               var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
+
+                                               if (!cb) {
+                                                       dojo.parser.parse(child);
+
+                                                       if (!Element.visible(child))
+                                                               new Effect.Appear(child, { duration : 0.5 });
+                                               } else {
+                                                       c.domNode.removeChild(child);
+                                               }
                                        });
 
                                } else {
@@ -165,11 +204,14 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                        else
                                request_counters();
 
-               } else {
+               } else if (transport.responseText) {
                        console.error("Invalid object received: " + transport.responseText);
                        dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
                                        __('Could not update headlines (invalid object received - see error console for details)') +
                                        "</div>");
+               } else {
+                       //notify_error("Error communicating with server.");
+                       Element.show("net-alert");
                }
 
                _infscroll_request_sent = 0;
@@ -221,8 +263,6 @@ function showArticleInHeadlines(id) {
 
                selectArticles('none');
 
-               var upd_img_pic = $("FUPDPIC-" + id);
-
                var view_mode = false;
 
                try {
@@ -232,14 +272,7 @@ function showArticleInHeadlines(id) {
                        //
                }
 
-               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                                       upd_img_pic.src.match("fresh_sign.png"))) {
-
-                       upd_img_pic.src = "images/blank_icon.gif";
-
-                       cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
-               } else if (article_is_unread && view_mode == "all_articles") {
+               if (article_is_unread && view_mode == "all_articles") {
                        cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
                }
 
@@ -269,10 +302,6 @@ function article_callback2(transport, id) {
 
                if (reply) {
 
-                       var upic = $('FUPDPIC-' + id);
-
-                       if (upic) upic.src = 'images/blank_icon.gif';
-
                        reply.each(function(article) {
                                if (active_post_id == article['id']) {
                                        render_article(article['content']);
@@ -287,16 +316,20 @@ function article_callback2(transport, id) {
 //                             return;
 //                     }
 
-               } else {
+               } else if (transport.responseText) {
                        console.error("Invalid object received: " + transport.responseText);
 
                        render_article("<div class='whiteBox'>" +
                                        __('Could not display article (invalid object received - see error console for details)') + "</div>");
+               } else {
+                       Element.show("net-alert");
                }
 
                request_counters();
 
-               try {
+               headlines_scroll_handler($("headlines-frame"));
+
+/*             try {
                        if (!_infscroll_disable &&
                                        $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
 
@@ -304,7 +337,7 @@ function article_callback2(transport, id) {
                        }
                } catch (e) {
                        console.warn(e);
-               }
+               } */
 
                notify("");
        } catch (e) {
@@ -350,15 +383,7 @@ function view(id) {
 
                precache_headlines();
 
-               if (!cached_article) {
-
-                       var upic = $('FUPDPIC-' + id);
-
-                       if (upic) {
-                               upic.src = getInitParam("sign_progress");
-                       }
-
-               } else if (cached_article && article_is_unread) {
+               if (cached_article && article_is_unread) {
 
                        query = query + "&mode=prefetch";
 
@@ -373,7 +398,7 @@ function view(id) {
                        // the server roundtrip altogether
                        if (cids_to_request.length == 0) {
 
-                               try {
+/*                             try {
                                        if (!_infscroll_disable &&
                                                $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
 
@@ -381,7 +406,9 @@ function view(id) {
                                        }
                                } catch (e) {
                                        console.warn(e);
-                               }
+                               } */
+
+                               headlines_scroll_handler($("headlines-frame"));
 
                                return;
                        }
@@ -391,6 +418,10 @@ function view(id) {
 
                console.log(query);
 
+               if (article_is_unread) {
+                       decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
+               }
+
                new Ajax.Request("backend.php", {
                        parameters: query,
                        onComplete: function(transport) {
@@ -493,13 +524,22 @@ function moveToPost(mode) {
                }
 
                if (active_post_id == false) {
-                       next_id = getFirstVisibleHeadlineId();
-                       prev_id = getLastVisibleHeadlineId();
+                       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) {
-                                       prev_id = rows[i-1];
-                                       next_id = rows[i+1];
+
+                                       // 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) {
+                                                       next_id = rows[j];
+                                                       break;
+                                               }
+                                       }
+                                       break;
                                }
                        }
                }
@@ -538,16 +578,16 @@ function moveToPost(mode) {
 function toggleSelected(id, force_on) {
        try {
 
-               var cb = $("RCHK-" + id);
+               var cb = dijit.byId("RCHK-" + id);
                var row = $("RROW-" + id);
 
                if (row) {
                        if (row.hasClassName('Selected') && !force_on) {
                                row.removeClassName('Selected');
-                               if (cb) cb.checked = false;
+                               if (cb) cb.attr("checked", false);
                        } else {
                                row.addClassName('Selected');
-                               if (cb) cb.checked = true;
+                               if (cb) cb.attr("checked", true);
                        }
                }
        } catch (e) {
@@ -825,7 +865,7 @@ function getLoadedArticleIds() {
 
 }
 
-// mode = all,none,unread,invert
+// mode = all,none,unread,invert,marked,published
 function selectArticles(mode) {
        try {
 
@@ -833,31 +873,52 @@ function selectArticles(mode) {
 
                children.each(function(child) {
                        var id = child.id.replace("RROW-", "");
-                       var cb = $("RCHK-" + id);
+                       var cb = dijit.byId("RCHK-" + id);
 
                        if (mode == "all") {
                                child.addClassName("Selected");
-                               cb.checked = true;
+                               if (cb) cb.attr("checked", true);
                        } else if (mode == "unread") {
                                if (child.hasClassName("Unread")) {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
+                               } else {
+                                       child.removeClassName("Selected");
+                                       if (cb) cb.attr("checked", false);
+                               }
+                       } else if (mode == "marked") {
+                               var img = $("FMPIC-" + child.id.replace("RROW-", ""));
+
+                               if (img && img.src.match("mark_set")) {
+                                       child.addClassName("Selected");
+                                       if (cb) cb.attr("checked", true);
+                               } else {
+                                       child.removeClassName("Selected");
+                                       if (cb) cb.attr("checked", false);
+                               }
+                       } else if (mode == "published") {
+                               var img = $("FPPIC-" + child.id.replace("RROW-", ""));
+
+                               if (img && img.src.match("pub_set")) {
+                                       child.addClassName("Selected");
+                                       if (cb) cb.attr("checked", true);
                                } else {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                }
+
                        } else if (mode == "invert") {
                                if (child.hasClassName("Selected")) {
                                        child.removeClassName("Selected");
-                                       cb.checked = false;
+                                       if (cb) cb.attr("checked", false);
                                } else {
                                        child.addClassName("Selected");
-                                       cb.checked = true;
+                                       if (cb) cb.attr("checked", true);
                                }
 
                        } else {
                                child.removeClassName("Selected");
-                               cb.checked = false;
+                               if (cb) cb.attr("checked", false);
                        }
                });
 
@@ -1091,8 +1152,9 @@ function headlines_scroll_handler(e) {
                var hsp = $("headlines-spacer");
 
                if (!_infscroll_disable) {
-                       if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
-                                       e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
+                       if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
+                                       (e.scrollHeight != 0 &&
+                                               ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
 
                                if (hsp)
                                        hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
@@ -1141,20 +1203,24 @@ function catchupBatchedArticles() {
        try {
                if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
 
+                       // make a copy of the array
+                       var batch = catchup_id_batch.slice();
                        var query = "?op=rpc&method=catchupSelected" +
-                               "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
+                               "&cmode=0&ids=" + param_escape(batch.toString());
+
+                       console.log(query);
 
                        new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
                                        handle_rpc_json(transport);
 
-                                       catchup_id_batch.each(function(id) {
+                                       batch.each(function(id) {
                                                var elem = $("RROW-" + id);
                                                if (elem) elem.removeClassName("Unread");
+                                               catchup_id_batch.remove(id);
                                        });
 
-                                       catchup_id_batch = [];
                                } });
                }
 
@@ -1240,14 +1306,6 @@ function cdmExpandArticle(id) {
 
                var elem = $("CICD-" + active_post_id);
 
-               var upd_img_pic = $("FUPDPIC-" + id);
-
-               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                               upd_img_pic.src.match("fresh_sign.png"))) {
-
-                       upd_img_pic.src = "images/blank_icon.gif";
-               }
-
                if (id == active_post_id && Element.visible(elem))
                        return true;
 
@@ -1267,52 +1325,6 @@ function cdmExpandArticle(id) {
                if (!Element.visible(elem)) {
                        Element.show(elem);
                        Element.hide("CEXC-" + id);
-
-                       if ($("CWRAP-" + id).innerHTML == "") {
-
-                               $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
-
-                               $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
-                                       __("Loading, please wait...") + "</div>";
-
-                               var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
-
-                               var neighbor_ids = getRelativePostIds(id);
-
-                               /* only request uncached articles */
-                               var cids_to_request = [];
-
-                               for (var i = 0; i < neighbor_ids.length; i++) {
-                                       if (cids_requested.indexOf(neighbor_ids[i]) == -1)
-                                               if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
-                                                       cids_to_request.push(neighbor_ids[i]);
-                                                       cids_requested.push(neighbor_ids[i]);
-                                               }
-                               }
-
-                               console.log("additional ids: " + cids_to_request.toString());
-
-                               query = query + "&cids=" + cids_to_request.toString();
-
-                               console.log(query);
-
-                               new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function(transport) {
-
-                                               $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
-
-                                               handle_rpc_json(transport);
-
-                                               var reply = JSON.parse(transport.responseText);
-
-                                               reply.each(function(article) {
-                                                       $("CWRAP-" + article['id']).innerHTML = article['content'];
-                                                       cids_requested.remove(article['id']);
-                                               });
-                               }});
-
-                       }
                }
 
                var new_offset = $("RROW-" + id).offsetTop;
@@ -1498,76 +1510,6 @@ function show_labels_in_headlines(transport) {
        }
 } */
 
-function emailArticle(id) {
-       try {
-               if (!id) {
-                       var ids = getSelectedArticleIds2();
-
-                       if (ids.length == 0) {
-                               alert(__("No articles are selected."));
-                               return;
-                       }
-
-                       id = ids.toString();
-               }
-
-               if (dijit.byId("emailArticleDlg"))
-                       dijit.byId("emailArticleDlg").destroyRecursive();
-
-               var query = "backend.php?op=dlg&method=emailArticle&param=" + param_escape(id);
-
-               dialog = new dijit.Dialog({
-                       id: "emailArticleDlg",
-                       title: __("Forward article by email"),
-                       style: "width: 600px",
-                       execute: function() {
-                               if (this.validate()) {
-
-                                       new Ajax.Request("backend.php", {
-                                               parameters: dojo.objectToQuery(this.attr('value')),
-                                               onComplete: function(transport) {
-
-                                                       var reply = JSON.parse(transport.responseText);
-
-                                                       var error = reply['error'];
-
-                                                       if (error) {
-                                                               alert(__('Error sending email:') + ' ' + error);
-                                                       } else {
-                                                               notify_info('Your message has been sent.');
-                                                               dialog.hide();
-                                                       }
-
-                                       } });
-                               }
-                       },
-                       href: query});
-
-               var tmph = dojo.connect(dialog, 'onLoad', function() {
-               dojo.disconnect(tmph);
-
-                  new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
-                          "backend.php?op=rpc&method=completeEmails",
-                          { tokens: '', paramName: "search" });
-               });
-
-               dialog.show();
-
-               /* displayDlg('emailArticle', id,
-                  function () {
-                               document.forms['article_email_form'].destination.focus();
-
-                          new Ajax.Autocompleter('destination', 'destination_choices',
-                                  "backend.php?op=rpc&method=completeEmails",
-                                  { tokens: '', paramName: "search" });
-
-                       }); */
-
-       } catch (e) {
-               exception_error("emailArticle", e);
-       }
-}
-
 function dismissArticle(id) {
        try {
                var elem = $("RROW-" + id);
@@ -1671,20 +1613,17 @@ function cdmClicked(event, id) {
                                toggleSelected(id);
 
                                var elem = $("RROW-" + id);
+                               var article_is_unread = elem.hasClassName("Unread");
 
                                if (elem)
                                        elem.removeClassName("Unread");
 
-                               var upd_img_pic = $("FUPDPIC-" + id);
-
-                               if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
-                                               upd_img_pic.src.match("fresh_sign.png"))) {
+                               active_post_id = id;
 
-                                       upd_img_pic.src = "images/blank_icon.gif";
+                               if (article_is_unread) {
+                                       decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
                                }
 
-                               active_post_id = id;
-
                                var query = "?op=rpc&method=catchupSelected" +
                                        "&cmode=0&ids=" + param_escape(id);
 
@@ -1699,6 +1638,14 @@ function cdmClicked(event, id) {
 
                } else {
                        toggleSelected(id, true);
+
+                       var elem = $("RROW-" + id);
+                       var article_is_unread = elem.hasClassName("Unread");
+
+                       if (article_is_unread) {
+                               decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
+                       }
+
                        toggleUnread(id, 0, false);
                        zoomToArticle(event, id);
                }
@@ -1780,10 +1727,10 @@ function isCdmMode() {
 function markHeadline(id) {
        var row = $("RROW-" + id);
        if (row) {
-               var check = $("RCHK-" + id);
+               var check = dijit.byId("RCHK-" + id);
 
                if (check) {
-                       check.checked = true;
+                       check.attr("checked", true);
                }
 
                row.addClassName("Selected");
@@ -1824,6 +1771,8 @@ function correctHeadlinesOffset(id) {
                var container = $("headlines-frame");
                var row = $("RROW-" + id);
 
+               if (!container || !row) return;
+
                var viewport = container.offsetHeight;
 
                var rel_offset_top = row.offsetTop - container.scrollTop;
@@ -1961,16 +1910,26 @@ function initHeadlinesMenu() {
                                        label: name,
                                        labelId: bare_id,
                                        onClick: function(event) {
-                                               selectionAssignLabel(this.labelId,
-                                                       [this.getParent().ownerMenu.callerRowId]);
+                                               var ids = getSelectedArticleIds2();
+                                               // cast to string
+                                               var id = this.getParent().ownerMenu.callerRowId + "";
+
+                                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                                               selectionAssignLabel(this.labelId, ids);
                                }}));
 
                                labelDelMenu.addChild(new dijit.MenuItem({
                                        label: name,
                                        labelId: bare_id,
                                        onClick: function(event) {
-                                               selectionRemoveLabel(this.labelId,
-                                                       [this.getParent().ownerMenu.callerRowId]);
+                                               var ids = getSelectedArticleIds2();
+                                               // cast to string
+                                               var id = this.getParent().ownerMenu.callerRowId + "";
+
+                                               ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+                                               selectionRemoveLabel(this.labelId, ids);
                                }}));
 
                        });
@@ -1994,87 +1953,6 @@ function initHeadlinesMenu() {
        }
 }
 
-function tweetArticle(id) {
-       try {
-               var query = "?op=rpc&method=getTweetInfo&id=" + param_escape(id);
-
-               console.log(query);
-
-               var d = new Date();
-      var ts = d.getTime();
-
-               var w = window.open('backend.php?op=backend&method=loading', 'ttrss_tweet',
-                       "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               var ti = JSON.parse(transport.responseText);
-
-                               var share_url = "http://twitter.com/share?_=" + ts +
-                                       "&text=" + param_escape(ti.title) +
-                                       "&url=" + param_escape(ti.link);
-
-                               w.location.href = share_url;
-
-                       } });
-
-
-       } catch (e) {
-               exception_error("tweetArticle", e);
-       }
-}
-
-function editArticleNote(id) {
-       try {
-
-               var query = "backend.php?op=dlg&method=editArticleNote&param=" + param_escape(id);
-
-               if (dijit.byId("editNoteDlg"))
-                       dijit.byId("editNoteDlg").destroyRecursive();
-
-               dialog = new dijit.Dialog({
-                       id: "editNoteDlg",
-                       title: __("Edit article note"),
-                       style: "width: 600px",
-                       execute: function() {
-                               if (this.validate()) {
-                                       var query = dojo.objectToQuery(this.attr('value'));
-
-                                       notify_progress("Saving article note...", true);
-
-                                       new Ajax.Request("backend.php", {
-                                       parameters: query,
-                                       onComplete: function(transport) {
-                                               notify('');
-                                               dialog.hide();
-
-                                               var reply = JSON.parse(transport.responseText);
-
-                                               cache_delete("article:" + id);
-
-                                               var elem = $("POSTNOTE-" + id);
-
-                                               if (elem) {
-                                                       Element.hide(elem);
-                                                       elem.innerHTML = reply.note;
-
-                                                       if (reply.raw_length != 0)
-                                                               new Effect.Appear(elem);
-                                               }
-
-                                       }});
-                               }
-                       },
-                       href: query,
-               });
-
-               dialog.show();
-
-       } catch (e) {
-               exception_error("editArticleNote", e);
-       }
-}
 
 function player(elem) {
        var aid = elem.getAttribute("audio-id");
@@ -2167,6 +2045,10 @@ function render_local_headlines(feed, is_cat, obj) {
                setActiveFeedId(feed, is_cat);
                initHeadlinesMenu();
 
+               dijit.getEnclosingWidget(
+                       document.forms["main_toolbar_form"].update).attr('disabled',
+                               is_cat || feed <= 0);
+
                precache_headlines();
 
        } catch (e) {
@@ -2177,17 +2059,20 @@ function render_local_headlines(feed, is_cat, obj) {
 function precache_headlines_idle() {
        try {
                if (!feed_precache_timeout_id) {
-                       var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
-                       var uncached = [];
+                       if (get_timestamp() - _viewfeed_last > 120) {
 
-                       feeds.each(function(item) {
-                               if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
-                                       uncached.push(item);
-                       });
+                               var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
+                               var uncached = [];
 
-                       if (uncached.length > 0) {
-                               var rf = uncached[Math.floor(Math.random()*uncached.length)];
-                               viewfeed(rf[0], '', rf[1], 0, true);
+                               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);
@@ -2208,7 +2093,7 @@ function precache_headlines() {
                                if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
                                        viewfeed(nuf, '', activeFeedIsCat(), 0, true);
 
-                               if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
+                               if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
                                        viewfeed(nf[0], '', nf[1], 0, true);
 
                                window.setTimeout(function() {
@@ -2222,24 +2107,83 @@ function precache_headlines() {
        }
 }
 
-function shareArticle(id) {
+function cancelSearch() {
        try {
-               if (dijit.byId("shareArticleDlg"))
-                       dijit.byId("shareArticleDlg").destroyRecursive();
+               _search_query = "";
+               viewCurrentFeed();
+       } catch (e) {
+               exception_error("cancelSearch", e);
+       }
+}
 
-               var query = "backend.php?op=dlg&method=shareArticle&param=" + param_escape(id);
+function setSelectionScore() {
+       try {
+               var ids = getSelectedArticleIds2();
 
-               dialog = new dijit.Dialog({
-                       id: "shareArticleDlg",
-                       title: __("Share article by URL"),
-                       style: "width: 600px",
-                       href: query});
+               if (ids.length > 0) {
+                       console.log(ids);
 
-               dialog.show();
+                       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()) +
+                                       "&score=" + param_escape(score);
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               var reply = JSON.parse(transport.responseText);
+                                               if (reply) {
+                                                       console.log(ids);
+
+                                                       ids.each(function(id) {
+                                                               var row = $("RROW-" + id);
+
+                                                               if (row) {
+                                                                       var pic = row.getElementsByClassName("hlScorePic")[0];
+
+                                                                       if (pic) {
+                                                                               pic.src = pic.src.replace(/score_.*?\.png/,
+                                                                                       reply["score_pic"]);
+                                                                               pic.setAttribute("score", score);
+                                                                       }
+                                                               }
+                                                       });
+                                               }
+                                       } });
+                       }
+
+               } else {
+                       alert(__("No articles are selected."));
+               }
        } catch (e) {
-               exception_error("emailArticle", e);
+               exception_error("setSelectionScore", e);
        }
 }
 
+function changeScore(id, pic) {
+       try {
+               var score = pic.getAttribute("score");
+
+               var new_score = prompt(__("Please enter new score for this article:"), score);
 
+               if (new_score != undefined) {
+
+                       var query = "op=rpc&method=setScore&id=" + param_escape(id) +
+                               "&score=" + param_escape(new_score);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       var reply = JSON.parse(transport.responseText);
+
+                                       if (reply) {
+                                               pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
+                                               pic.setAttribute("score", new_score);
+                                       }
+                               } });
+               }
+       } catch (e) {
+               exception_error("changeScore", e);
+       }
+}