]> git.wh0rd.org - tt-rss.git/blobdiff - js/viewfeed.js
feed tree: only run animation for appearing unread counters to prevent clashes with...
[tt-rss.git] / js / viewfeed.js
index e6b708a2d6c051e62ff6ff9e0c47922aef024424..ac9d4225569e3fb77a0aa66d92aeae96e79075f9 100755 (executable)
@@ -61,7 +61,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        $("headlines-frame").scrollTop = 0;
 
                                        $("floatingTitle").style.visibility = "hidden";
-                                       $("floatingTitle").setAttribute("rowid", 0);
+                                       $("floatingTitle").setAttribute("data-article-id", 0);
                                        $("floatingTitle").innerHTML = "";
                                }
                        } catch (e) { };
@@ -150,6 +150,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                        tmp.innerHTML = reply['headlines']['content'];
                                        dojo.parser.parse(tmp);
 
+                                       var new_rows = [];
+
                                        while (tmp.hasChildNodes()) {
                                                var row = tmp.removeChild(tmp.firstChild);
 
@@ -157,6 +159,16 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                        dijit.byId("headlines-frame").domNode.appendChild(row);
 
                                                        loaded_article_ids.push(row.id);
+
+                                                       if (!isCdmMode() || row.hasClassName("cdmFeedTitle")) {
+                                                               new_rows.push(row);
+                                                       } else if (isCdmMode()) {
+                                                               var titleWrap = $$("#" + row.id + " .titleWrap")[0];
+
+                                                               if (titleWrap) {
+                                                                       new_rows.push(titleWrap);
+                                                               }
+                                                       }
                                                }
                                        }
 
@@ -171,7 +183,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) {
                                                markHeadline(ids[i]);
                                        }
 
-                                       initHeadlinesMenu();
+                                       initHeadlinesMenu(new_rows);
 
                                        if (_infscroll_disable) {
                                                hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
@@ -273,34 +285,18 @@ function render_article(article) {
 function showArticleInHeadlines(id, noexpand) {
 
        try {
-               selectArticles("none");
-
-               var crow = $("RROW-" + id);
-
-               if (!crow) return;
-
-               var article_is_unread = crow.hasClassName("Unread");
+               var row = $("RROW-" + id);
+               if (!row) return;
 
                if (!noexpand)
-                       crow.removeClassName("Unread");
-               crow.addClassName("active");
-
-               selectArticles('none');
+                       row.removeClassName("Unread");
 
-               var view_mode = false;
+               row.addClassName("active");
 
-               try {
-                       view_mode = document.forms['main_toolbar_form'].view_mode;
-                       view_mode = view_mode[view_mode.selectedIndex].value;
-               } catch (e) {
-                       //
-               }
+               selectArticles('none');
 
                markHeadline(id);
 
-               if (article_is_unread && !noexpand)
-                       _force_scheduled_update = true;
-
        } catch (e) {
                exception_error("showArticleInHeadlines", e);
        }
@@ -452,7 +448,7 @@ function toggleMark(id, client_only) {
 
                var ft = $("floatingTitle");
 
-               if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
+               if (ft && ft.getAttribute("data-article-id") == id) {
                        var fte = ft.getElementsByClassName("markedPic");
 
                        for (var i = 0; i < fte.length; i++)
@@ -510,7 +506,7 @@ function togglePub(id, client_only, no_effects, note) {
 
                var ft = $("floatingTitle");
 
-               if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
+               if (ft && ft.getAttribute("data-article-id") == id) {
                        var fte = ft.getElementsByClassName("pubPic");
 
                        for (var i = 0; i < fte.length; i++)
@@ -932,7 +928,7 @@ function getSelectedArticleIds2() {
 
        $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
                function(child) {
-                       rv.push(child.id.replace("RROW-", ""));
+                       rv.push(child.getAttribute("data-article-id"));
                });
 
        return rv;
@@ -944,8 +940,10 @@ function getLoadedArticleIds() {
        var children = $$("#headlines-frame > div[id*=RROW-]");
 
        children.each(function(child) {
-                       rv.push(child.id.replace("RROW-", ""));
-               });
+               if (Element.visible(child)) {
+                       rv.push(child.getAttribute("data-article-id"));
+               }
+       });
 
        return rv;
 
@@ -960,7 +958,7 @@ function selectArticles(mode, query) {
                var children = $$(query);
 
                children.each(function(child) {
-                       var id = child.id.replace("RROW-", "");
+                       var id = child.getAttribute("data-article-id");
 
                        var cb = dijit.getEnclosingWidget(
                                        child.getElementsByClassName("rchk")[0]);
@@ -1187,7 +1185,7 @@ function editArticleTags(id) {
                });
 
                var tmph = dojo.connect(dialog, 'onLoad', function() {
-               dojo.disconnect(tmph);
+                       dojo.disconnect(tmph);
 
                        new Ajax.Autocompleter('tags_str', 'tags_choices',
                           "backend.php?op=article&method=completeTags",
@@ -1245,7 +1243,7 @@ function unpackVisibleHeadlines() {
                                if (child.offsetTop <= $("headlines-frame").scrollTop +
                                        $("headlines-frame").offsetHeight) {
 
-                                       var cencw = $("CENCW-" + child.id.replace("RROW-", ""));
+                                       var cencw = $("CENCW-" + child.getAttribute("data-article-id"));
 
                                        if (cencw) {
                                                cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
@@ -1290,14 +1288,14 @@ function headlines_scroll_handler(e) {
 
                                if ($("headlines-frame").scrollTop <= child.offsetTop &&
                                        child.offsetTop - $("headlines-frame").scrollTop < 100 &&
-                                       child.id.replace("RROW-", "") != _active_article_id) {
+                                       child.getAttribute("data-article-id") != _active_article_id) {
 
                                        if (_active_article_id) {
                                                var row = $("RROW-" + _active_article_id);
                                                if (row) row.removeClassName("active");
                                        }
 
-                                       _active_article_id = child.id.replace("RROW-", "");
+                                       _active_article_id = child.getAttribute("data-article-id");
                                        showArticleInHeadlines(_active_article_id, true);
                                        updateSelectedPrompt();
                                        break;
@@ -1334,7 +1332,7 @@ function headlines_scroll_handler(e) {
                                        if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
                                                        (child.offsetTop + child.offsetHeight/2)) {
 
-                                               var id = child.id.replace("RROW-", "");
+                                               var id = child.getAttribute("data-article-id")
 
                                                if (catchup_id_batch.indexOf(id) == -1)
                                                        catchup_id_batch.push(id);
@@ -1521,7 +1519,7 @@ function cdmCollapseArticle(event, id, unmark) {
                                scrollToRowId(row.id);
 
                        $("floatingTitle").style.visibility = "hidden";
-                       $("floatingTitle").setAttribute("rowid", false);
+                       $("floatingTitle").setAttribute("data-article-id", 0);
                }
 
        } catch (e) {
@@ -1846,12 +1844,12 @@ function initFloatingMenu() {
                                var callerNode = event.target, match = null, tries = 0;
 
                                while (match == null && callerNode && tries <= 3) {
-                                       match = callerNode.getAttribute("rowid").match("^[A-Z]+[-]([0-9]+)$");
+                                       match = callerNode.getAttribute("data-article-id");
                                        callerNode = callerNode.parentNode;
                                        ++tries;
                                }
 
-                               if (match) this.callerRowId = parseInt(match[1]);
+                               if (match) this.callerRowId = match;
 
                        });
 
@@ -1992,60 +1990,27 @@ function headlinesMenuCommon(menu) {
        }
 }
 
-function initHeadlinesMenu() {
+function initHeadlinesMenu(append_rows) {
        try {
-               if (dijit.byId("headlinesMenu"))
-                       dijit.byId("headlinesMenu").destroyRecursive();
+               if (!append_rows) {
 
-               var ids = [];
+                       if (dijit.byId("headlinesMenu"))
+                               dijit.byId("headlinesMenu").destroyRecursive();
 
-               if (!isCdmMode()) {
-                       nodes = $$("#headlines-frame > div[id*=RROW]");
-               } else {
-                       nodes = $$("#headlines-frame span[id*=RTITLE]");
-               }
+                       var ids = [];
 
-               nodes.each(function(node) {
-                       ids.push(node.id);
-               });
-
-               var menu = new dijit.Menu({
-                       id: "headlinesMenu",
-                       targetNodeIds: ids
-               });
-
-               var tmph = dojo.connect(menu, '_openMyself', function (event) {
-                       var callerNode = event.target, match = null, tries = 0;
-
-                       while (match == null && callerNode && tries <= 3) {
-                               match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
-                               callerNode = callerNode.parentNode;
-                               ++tries;
+                       if (!isCdmMode()) {
+                               nodes = $$("#headlines-frame > div[id*=RROW]");
+                       } else {
+                               nodes = $$("#headlines-frame span[id*=RTITLE]");
                        }
 
-                       if (match) this.callerRowId = parseInt(match[1]);
-
-               });
-
-               headlinesMenuCommon(menu);
-
-               menu.startup();
-
-               /* vgroup feed title menu */
-
-               var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']");
-               var ids = [];
-
-               nodes.each(function(node) {
-                       ids.push(node.id);
-               });
-
-               if (ids.length > 0) {
-                       if (dijit.byId("headlinesFeedTitleMenu"))
-                               dijit.byId("headlinesFeedTitleMenu").destroyRecursive();
+                       nodes.each(function (node) {
+                               ids.push(node.id);
+                       });
 
                        var menu = new dijit.Menu({
-                               id: "headlinesFeedTitleMenu",
+                               id: "headlinesMenu",
                                targetNodeIds: ids
                        });
 
@@ -2053,50 +2018,109 @@ function initHeadlinesMenu() {
                                var callerNode = event.target, match = null, tries = 0;
 
                                while (match == null && callerNode && tries <= 3) {
-                                       match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
+
+                                       match = callerNode.getAttribute("data-article-id")
                                        callerNode = callerNode.parentNode;
                                        ++tries;
                                }
 
-                               if (match) this.callerRowId = parseInt(match[1]);
+                               if (match) this.callerRowId = match;
 
                        });
 
-                       menu.addChild(new dijit.MenuItem({
-                               label: __("Select articles in group"),
-                               onClick: function(event) {
-                                       selectArticles("all",
-                                               "#headlines-frame > div[id*=RROW]"+
-                                               "[orig-feed-id='"+menu.callerRowId+"']");
+                       headlinesMenuCommon(menu);
 
-                               }}));
+                       menu.startup();
 
-                       menu.addChild(new dijit.MenuItem({
-                               label: __("Mark group as read"),
-                               onClick: function(event) {
-                                       selectArticles("none");
-                                       selectArticles("all",
-                                               "#headlines-frame > div[id*=RROW]"+
-                                               "[orig-feed-id='"+menu.callerRowId+"']");
+               } else {
+                       var menu = dijit.byId("headlinesMenu");
 
-                                       catchupSelection();
-                               }}));
+                       append_rows.each(function (row) {
+                               if (!row.hasClassName("cdmFeedTitle")) {
+                                       menu.bindDomNode(row);
+                               }
+                       });
+               }
 
+               /* vgroup feed title menu */
 
-                       menu.addChild(new dijit.MenuItem({
-                               label: __("Mark feed as read"),
-                               onClick: function(event) {
-                                       catchupFeedInGroup(menu.callerRowId);
-                               }}));
+               if (!append_rows) {
 
-                       menu.addChild(new dijit.MenuItem({
-                               label: __("Edit feed"),
-                               onClick: function(event) {
-                                       editFeed(menu.callerRowId);
-                               }}));
+                       var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']");
+                       var ids = [];
 
-                       menu.startup();
+                       nodes.each(function(node) {
+                               ids.push(node.id);
+                       });
 
+                       if (ids.length > 0) {
+                               if (dijit.byId("headlinesFeedTitleMenu"))
+                                       dijit.byId("headlinesFeedTitleMenu").destroyRecursive();
+
+                               var menu = new dijit.Menu({
+                                       id: "headlinesFeedTitleMenu",
+                                       targetNodeIds: ids
+                               });
+
+                               var tmph = dojo.connect(menu, '_openMyself', function (event) {
+                                       var callerNode = event.target, match = null, tries = 0;
+
+                                       while (match == null && callerNode && tries <= 3) {
+                                               match = callerNode.getAttribute("data-feed-id")
+                                               callerNode = callerNode.parentNode;
+                                               ++tries;
+                                       }
+
+                                       if (match) this.callerRowId = match;
+
+                               });
+
+                               menu.addChild(new dijit.MenuItem({
+                                       label: __("Select articles in group"),
+                                       onClick: function (event) {
+                                               selectArticles("all",
+                                                       "#headlines-frame > div[id*=RROW]" +
+                                                       "[data-orig-feed-id='" + menu.callerRowId + "']");
+
+                                       }
+                               }));
+
+                               menu.addChild(new dijit.MenuItem({
+                                       label: __("Mark group as read"),
+                                       onClick: function (event) {
+                                               selectArticles("none");
+                                               selectArticles("all",
+                                                       "#headlines-frame > div[id*=RROW]" +
+                                                       "[data-orig-feed-id='" + menu.callerRowId + "']");
+
+                                               catchupSelection();
+                                       }
+                               }));
+
+                               menu.addChild(new dijit.MenuItem({
+                                       label: __("Mark feed as read"),
+                                       onClick: function (event) {
+                                               catchupFeedInGroup(menu.callerRowId);
+                                       }
+                               }));
+
+                               menu.addChild(new dijit.MenuItem({
+                                       label: __("Edit feed"),
+                                       onClick: function (event) {
+                                               editFeed(menu.callerRowId);
+                                       }
+                               }));
+
+                               menu.startup();
+                       }
+               } else {
+                       var menu = dijit.byId("headlinesFeedTitleMenu");
+
+                       append_rows.each(function (row) {
+                               if (row.hasClassName("cdmFeedTitle")) {
+                                       menu.bindDomNode(row);
+                               }
+                       });
                }
 
        } catch (e) {
@@ -2285,9 +2309,10 @@ function updateFloatingTitle(unread_only) {
 
                                var header = child.getElementsByClassName("cdmHeader")[0];
 
-                               if (unread_only || child.id != $("floatingTitle").getAttribute("rowid")) {
-                                       if (child.id != $("floatingTitle").getAttribute("rowid")) {
-                                               $("floatingTitle").setAttribute("rowid", child.id);
+                               if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
+                                       if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
+
+                                               $("floatingTitle").setAttribute("data-article-id", child.getAttribute("data-article-id"));
                                                $("floatingTitle").innerHTML = header.innerHTML;
                                                $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child.id+"')\">" + $("floatingTitle").firstChild.innerHTML;
 
@@ -2327,7 +2352,7 @@ function updateFloatingTitle(unread_only) {
 function catchupCurrentBatchIfNeeded() {
        if (catchup_id_batch.length > 0) {
                window.clearTimeout(catchup_timeout_id);
-               catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', 1000);
+               catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000);
 
                if (catchup_id_batch.length >= 10) {
                        catchupBatchedArticles();