allow j/k hotkeys select categories (getRelativeFeedId2())

master
Andrew Dolgov 17 years ago
parent ee4a98124e
commit ec37f4f112

@ -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) { function get_feed_entry_unread(elem) {
var id = elem.id.replace("FEEDR-", ""); 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) { function getRelativeFeedId(list, id, direction, unread_only) {
var rows = list.getElementsByTagName("LI"); var rows = list.getElementsByTagName("LI");
var feeds = new Array(); var feeds = new Array();

@ -1055,15 +1055,33 @@ function hotkey_handler(e) {
if (keycode == 74) { // j if (keycode == 74) { // j
var feed = getActiveFeedId(); var feed = getActiveFeedId();
var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'prev');
if (new_feed) viewfeed(new_feed, ''); // 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; return;
} }
if (keycode == 75) { // k if (keycode == 75) { // k
var feed = getActiveFeedId(); var feed = getActiveFeedId();
var new_feed = getRelativeFeedId(feedlist, feed, 'next'); var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'next');
if (new_feed) viewfeed(new_feed, ''); // 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; return;
} }

Loading…
Cancel
Save