]> git.wh0rd.org Git - tt-rss.git/commitdiff
rework hideOrShowFeeds(): now hides empty categories should be compatible with brows...
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 8 Jun 2006 04:05:11 +0000 (05:05 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 8 Jun 2006 04:05:11 +0000 (05:05 +0100)
functions.js

index 8401a0ff37cd009d34417c0a8c74867a3fe2e3c5..9757eca802f4711c386a6c30609f19affb86f7fe 100644 (file)
@@ -594,7 +594,9 @@ function all_counters_callback() {
                        if (getInitParam("feeds_sort_by_unread") == 1) {
                                resort_feedlist();              
                        }       
-       
+
+                       hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
+
                } catch (e) {
                        exception_error("all_counters_callback", e);
                }
@@ -726,25 +728,67 @@ function popupHelp(tid) {
 
 function hideOrShowFeeds(doc, hide) {
 
-       if (!doc.styleSheets) return;
+       var fd = getFeedsContext().document;
+
+       var list = fd.getElementById("feedList");
+
+       if (fd.getElementById("feedCatHolder")) {
+
+               var feeds = fd.getElementById("feedList");
+               var child = feeds.firstChild;
+
+               while (child) {
 
-       var css_rules = doc.styleSheets[0].cssRules;
+                       if (child.id == "feedCatHolder") {
+                               hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
+                       }
+       
+                       child = child.nextSibling;
+               }
 
-       if (!css_rules || !css_rules.length) return;
+       } else {
+               hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
+       }
+}
 
-       for (i = 0; i < css_rules.length; i++) {
-               var rule = css_rules[i];
+function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
+
+//     debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
+
+       var cat_unread = 0;
+
+       if (node.hasChildNodes() && node.firstChild.nextSibling != false) {  
+               for (i = 0; i < node.childNodes.length; i++) {
+                       if (node.childNodes[i].nodeName != "LI") { continue; }
+
+                       var has_unread = (node.childNodes[i].className != "feed");
+
+//                     debug(node.childNodes[i].id + " --> " + has_unread);
+
+                       if (hide && !has_unread) {
+                               node.childNodes[i].style.display = "none";
+                       }
 
-               if (rule.selectorText == "ul.feedList li.feed") {
                        if (!hide) {
-                               rule.style.display = "block";
-                       } else {
-                               rule.style.display = "none";
+                               node.childNodes[i].style.display = "list-item";
+                       }
+
+                       if (has_unread) {
+                               cat_unread++;
                        }
+
                }
+       }
 
-       } 
+       if (cat_unread == 0) {
+               if (hide) {
+                       cat_node.style.display = "none";
+               } else {
+                       cat_node.style.display = "list-item";
+               }
+       }
 
+//     debug("unread for category: " + cat_unread);
 }
 
 function selectTableRow(r, do_select) {