]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
cdmExpandArticle: bail out if id not present in buffer (closes #628)
[tt-rss.git] / js / viewfeed.js
index a557b1b183a7c850e63bd5e72bc65746304b3010..ece1f1394e08c3a7bb737a1fe8cb6ec5e1dec35a 100644 (file)
@@ -205,6 +205,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
 
                _infscroll_request_sent = 0;
 
+               headlines_scroll_handler($("headlines-frame"));
+
                notify("");
 
        } catch (e) {
@@ -541,7 +543,7 @@ function moveToPost(mode, noscroll) {
 
                                        } else if (next_id) {
                                                cdmExpandArticle(next_id);
-                                               cdmScrollToArticleId(next_id, noscroll);
+                                               cdmScrollToArticleId(next_id, true);
                                        }
 
                                } else if (next_id) {
@@ -560,8 +562,13 @@ function moveToPost(mode, noscroll) {
                                        var ctr = $("headlines-frame");
 
                                        if (!getInitParam("cdm_expanded")) {
-                                               cdmExpandArticle(prev_id);
-                                               cdmScrollToArticleId(prev_id, true);
+
+                                               if (!noscroll && article.offsetTop < ctr.scrollTop) {
+                                                       scrollArticle(-ctr.offsetHeight/3);
+                                               } else {
+                                                       cdmExpandArticle(prev_id);
+                                                       cdmScrollToArticleId(prev_id, true);
+                                               }
                                        } else {
 
                                                if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
@@ -972,9 +979,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);
@@ -1016,10 +1023,10 @@ 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);
                        op = "unarchive";
                }
 
@@ -1063,7 +1070,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);
@@ -1171,6 +1178,23 @@ function headlines_scroll_handler(e) {
        try {
                var hsp = $("headlines-spacer");
 
+               $$("#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);
+                                       }
+                               }
+                       }
+               );
+
+
                if (!_infscroll_disable) {
                        if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
                                        (e.scrollHeight != 0 &&
@@ -1192,7 +1216,7 @@ function headlines_scroll_handler(e) {
 
                        $$("#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-", "");
@@ -1293,7 +1317,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)) {
 
@@ -1350,6 +1374,8 @@ function cdmExpandArticle(id) {
        try {
                console.log("cdmExpandArticle " + id);
 
+               if (!$("RROW-" + id)) return false;
+
                hideAuxDlg();
 
                var elem = $("CICD-" + getActiveArticleId());
@@ -1368,6 +1394,7 @@ function cdmExpandArticle(id) {
                        Element.hide(elem);
                        Element.show("CEXC-" + getActiveArticleId());
                        Element.hide(collapse);
+                       $("RROW-" + getActiveArticleId()).removeClassName("active");
                }
 
                setActiveArticleId(id);
@@ -1383,19 +1410,19 @@ function cdmExpandArticle(id) {
                        if (cencw) {
                                cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
                                cencw.setAttribute('id', '');
+                               Element.show(cencw);
                        }
 
                        Element.show(elem);
                        Element.hide("CEXC-" + id);
                        Element.show(collapse);
+                       $("RROW-" + id).addClassName("active");
                }
 
                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);
@@ -1801,6 +1828,12 @@ 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({
@@ -2012,3 +2045,21 @@ 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);
+       }
+}