]> git.wh0rd.org Git - tt-rss.git/commitdiff
j,k navigate between feeds
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 28 Nov 2005 06:28:33 +0000 (07:28 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 28 Nov 2005 06:28:33 +0000 (07:28 +0100)
README
functions.js
tt-rss.js

diff --git a/README b/README
index 5aa84c53b5463edc96b93f40df174efe163a4c83..55ce000e67aab70f3355da64bcbd8b2d8373ed6f 100644 (file)
--- a/README
+++ b/README
@@ -30,6 +30,8 @@ Interface:
        "r" refreshes feed list;
        "u" refreshes currently selected feed;
        "a" hides or shows only unread feeds in the feedlist;
+       "j" move to previous feed
+       "k" move to next feed
 
 Requirements:
        
index 3aef7befafbdb446c96da512c533247abdf981b5..c696ae3e8f84e74887aaa8dfda75dbead8101300 100644 (file)
@@ -130,7 +130,11 @@ function hotkey_handler(e) {
        }
        
        if (typeof localHotkeyHandler != 'undefined') {
-               localHotkeyHandler(keycode);
+               try {
+                       localHotkeyHandler(keycode);
+               } catch (e) {
+                       exception_error(e);
+               }
        }
 
 }
@@ -545,3 +549,126 @@ function openExternalUrl(url) {
        var w = window.open(url);
 }
 
+
+function getRelativeFeedId(list, id, direction) {      
+       if (!id) {
+               if (direction == "next") {
+                       for (i = 0; i < list.childNodes.length; i++) {
+                               var child = list.childNodes[i];
+                               if (child.id == "feedCatHolder") {
+                                       if (child.firstChild) {
+                                               var cr = getRelativeFeedId(child.firstChild, id, direction);
+                                               if (cr) return cr;                                      
+                                       }
+                               } else if (child.id.match("FEEDR-")) {
+                                       return child.id.replace('FEEDR-', '');
+                               }                               
+                       }
+               }
+
+               // FIXME select last feed doesn't work when only unread feeds are visible
+
+               if (direction == "prev") {
+                       for (i = list.childNodes.length-1; i >= 0; i--) {
+                               var child = list.childNodes[i];                         
+                               if (child.id == "feedCatHolder") {
+                                       if (child.firstChild) {
+                                               var cr = getRelativeFeedId(child.firstChild, id, direction);
+                                               if (cr) return cr;                                      
+                                       }
+                               } else if (child.id.match("FEEDR-")) {
+                               
+                                       if (getCookie("ttrss_vf_hreadf") == 1) {
+                                               if (child.className != "feed") {
+                                                       alert(child.className);
+                                                       return child.id.replace('FEEDR-', '');                                          
+                                               }                                                       
+                                       } else {
+                                                       return child.id.replace('FEEDR-', '');                                          
+                                       }                               
+                               }                               
+                       }
+               }
+       } else {
+       
+               var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
+               
+               if (direction == "next") {
+
+                       if (feed.nextSibling) {
+
+                               var next_feed = feed.nextSibling;
+
+                               while (!next_feed.id && next_feed.nextSibling) {
+                                       next_feed = next_feed.nextSibling;
+                               }
+
+                               if (getCookie("ttrss_vf_hreadf") == 1) {
+                                               while (next_feed && next_feed.className == "feed") {
+                                                       next_feed = next_feed.nextSibling;
+                                               }
+                                       }
+
+                               if (next_feed && next_feed.id.match("FEEDR-")) {
+                                       return next_feed.id.replace("FEEDR-", "");
+                               }                               
+                       }
+
+                       var this_cat = feed.parentNode.parentNode;
+                       
+                       if (this_cat && this_cat.nextSibling) {
+                               while (this_cat = this_cat.nextSibling) {
+                                       if (this_cat.firstChild && this_cat.firstChild.firstChild) {
+                                               var next_feed = this_cat.firstChild.firstChild;
+                                                       if (getCookie("ttrss_vf_hreadf") == 1) {
+                                                       while (next_feed && next_feed.className == "feed") {
+                                                               next_feed = next_feed.nextSibling;
+                                                       }
+                                               }
+                                               if (next_feed && next_feed.id.match("FEEDR-")) {
+                                                       return next_feed.id.replace("FEEDR-", "");
+                                               }
+                                       }
+                               }                               
+                       }
+               } else if (direction == "prev") {
+
+                       if (feed.previousSibling) {
+                       
+                               var prev_feed = feed.previousSibling;
+
+                               if (getCookie("ttrss_vf_hreadf") == 1) {
+                                               while (prev_feed && prev_feed.className == "feed") {
+                                                       prev_feed = prev_feed.previousSibling;
+                                               }
+                                       }
+
+                               while (!prev_feed.id && prev_feed.previousSibling) {
+                                       prev_feed = prev_feed.previousSibling;
+                               }
+
+                               if (prev_feed && prev_feed.id.match("FEEDR-")) {
+                                       return prev_feed.id.replace("FEEDR-", "");
+                               }                               
+                       }
+
+                       var this_cat = feed.parentNode.parentNode;
+                       
+                       if (this_cat && this_cat.previousSibling) {
+                               while (this_cat = this_cat.previousSibling) {
+                                       if (this_cat.lastChild && this_cat.firstChild.lastChild) {
+                                               var prev_feed = this_cat.firstChild.lastChild;
+                                                       if (getCookie("ttrss_vf_hreadf") == 1) {
+                                                       while (prev_feed && prev_feed.className == "feed") {
+                                                               prev_feed = prev_feed.previousSibling;
+                                                       }
+                                               }
+                                               if (prev_feed && prev_feed.id.match("FEEDR-")) {
+                                                       return prev_feed.id.replace("FEEDR-", "");
+                                               }
+                                       }
+                               }                               
+                       }       
+               }
+       }
+}
index 795c16453c22ed4fb10c69e139d880d79d46c20e..a2910451eee79fb16052688c8066f813ba124594 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -299,6 +299,21 @@ function localHotkeyHandler(keycode) {
                return toggleDispRead();
        }
 
+       var f_doc = window.frames["feeds-frame"].document;
+       var feedlist = f_doc.getElementById('feedList');
+
+       if (keycode == 74) { // j
+               var feed = getActiveFeedId();
+               var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
+               if (new_feed) viewfeed(new_feed, 0, '');
+       }
+
+       if (keycode == 75) { // k
+               var feed = getActiveFeedId();
+               var new_feed = getRelativeFeedId(feedlist, feed, 'next');
+               if (new_feed) viewfeed(new_feed, 0, '');
+       }
+
 //     notify("KC: " + keycode);
 
 }