From: Andrew Dolgov Date: Wed, 4 Jun 2008 13:57:29 +0000 (+0100) Subject: allow j/k hotkeys select categories (getRelativeFeedId2()) X-Git-Tag: 1.2.24~10 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ec37f4f112acbe917b7343fdc3a43b4d1bccd16e;p=tt-rss.git allow j/k hotkeys select categories (getRelativeFeedId2()) --- diff --git a/functions.js b/functions.js index 456b65af..ffc0168b 100644 --- a/functions.js +++ b/functions.js @@ -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(); diff --git a/tt-rss.js b/tt-rss.js index a8dd16e8..2373826f 100644 --- 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; }