]> git.wh0rd.org Git - tt-rss.git/commitdiff
allow j/k hotkeys select categories (getRelativeFeedId2())
authorAndrew Dolgov <fox@bah.spb.su>
Wed, 4 Jun 2008 13:57:29 +0000 (14:57 +0100)
committerAndrew Dolgov <fox@bah.spb.su>
Wed, 4 Jun 2008 13:57:29 +0000 (14:57 +0100)
functions.js
tt-rss.js

index 456b65af758a321a557a933daabb6db784df36e4..ffc0168bcde1901694b379f1d978044f2bf2038e 100644 (file)
@@ -649,6 +649,18 @@ function get_feed_unread(id) {
        }
 }
 
+function get_cat_unread(id) {
+       try {
+               var ctr = document.getElementById("FCATCTR-" + id).innerHTML;
+               ctr = ctr.replace("(", "");
+               ctr = ctr.replace(")", "");
+               return parseInt(ctr);
+       } catch (e) {
+               exception_error("get_feed_unread", e, true);
+               return -1;
+       }
+}
+
 function get_feed_entry_unread(elem) {
 
        var id = elem.id.replace("FEEDR-", "");
@@ -1023,6 +1035,76 @@ function toggleSelectRow(sender) {
        }
 }
 
+
+function getRelativeFeedId2(id, is_cat, direction, unread_only) {      
+       try {
+
+//             alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
+
+               var rows = document.getElementById("feedList").getElementsByTagName("LI");
+               var feeds = new Array();
+       
+               for (var i = 0; i < rows.length; i++) {
+                       if (rows[i].id.match("FEEDR-")) {
+       
+                               if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
+       
+                                       if (!unread_only || 
+                                                       (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
+                                               feeds.push(rows[i].id.replace("FEEDR-", ""));
+                                       }
+                               }
+                       }
+
+                       if (rows[i].id.match("FCAT-")) {
+                               if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
+
+                                       var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
+
+                                       if (cat_id >= 0) {
+                                               if (!unread_only || get_cat_unread(cat_id) > 0) {
+                                                       feeds.push("CAT:"+cat_id);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       
+//             alert(feeds.toString());
+
+               if (!id) {
+                       if (direction == "next") {
+                               return feeds.shift();
+                       } else {
+                               return feeds.pop();
+                       }
+               } else {
+                       if (direction == "next") {
+                               if (is_cat) id = "CAT:" + id;
+                               var idx = feeds.indexOf(id);
+                               if (idx != -1 && idx < feeds.length) {
+                                       return feeds[idx+1];                                    
+                               } else {
+                                       return getRelativeFeedId2(false, is_cat, direction, unread_only);
+                               }
+                       } else {
+                               if (is_cat) id = "CAT:" + id;
+                               var idx = feeds.indexOf(id);
+                               if (idx > 0) {
+                                       return feeds[idx-1];
+                               } else {
+                                       return getRelativeFeedId2(false, is_cat, direction, unread_only);
+                               }
+                       }
+       
+               }
+
+       } catch (e) {
+               exception_error("getRelativeFeedId2", e);
+       }
+}
+
+
 function getRelativeFeedId(list, id, direction, unread_only) { 
        var rows = list.getElementsByTagName("LI");
        var feeds = new Array();
index a8dd16e88457b81152360afb38b18056cd8f6ce9..2373826f770405ffce10726f16d970e9787c54ba 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1055,15 +1055,33 @@ function hotkey_handler(e) {
 
                        if (keycode == 74) { // j
                                var feed = getActiveFeedId();
-                               var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
-                               if (new_feed) viewfeed(new_feed, '');
+                               var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'prev');
+//                             alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
+                               if (new_feed) {
+                                       var is_cat = new_feed.match("CAT:");
+                                       if (is_cat) {
+                                               new_feed = new_feed.replace("CAT:", "");
+                                               viewCategory(new_feed);
+                                       } else {
+                                               viewfeed(new_feed, '', false);
+                                       }
+                               }
                                return;
                        }
        
                        if (keycode == 75) { // k
                                var feed = getActiveFeedId();
-                               var new_feed = getRelativeFeedId(feedlist, feed, 'next');
-                               if (new_feed) viewfeed(new_feed, '');
+                               var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'next');
+//                             alert(feed + " IC: " + activeFeedIsCat() + " => " + new_feed);
+                               if (new_feed) {
+                                       var is_cat = new_feed.match("CAT:");
+                                       if (is_cat == "CAT:") {
+                                               new_feed = new_feed.replace("CAT:", "");
+                                               viewCategory(new_feed);
+                                       } else {
+                                               viewfeed(new_feed, '', false);
+                                       }
+                               }
                                return;
                        }