From 61a20560f235c85c2ffc9d1556908a4421ab31e6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 20 May 2008 13:04:30 +0100 Subject: [PATCH] add hotkey f w: resort feedlist by name or unread count --- functions.js | 19 +++++++++++++++---- help/3.php | 1 + tt-rss.js | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/functions.js b/functions.js index a27336d6d..962ddc652 100644 --- a/functions.js +++ b/functions.js @@ -618,9 +618,9 @@ function parse_counters_reply(transport, scheduled_call) { parse_runtime_info(runtime_info); - if (getInitParam("feeds_sort_by_unread") == 1) { - resort_feedlist(); - } + if (feedsSortByUnread()) { + resort_feedlist(); + } hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); @@ -661,9 +661,17 @@ function get_feed_entry_unread(elem) { } } +function get_feed_entry_name(elem) { + var id = elem.id.replace("FEEDR-", ""); + return getFeedName(id); +} + + function resort_category(node) { debug("resort_category: " + node); + var by_unread = feedsSortByUnread(); + if (node.hasChildNodes() && node.firstChild.nextSibling != false) { for (i = 0; i < node.childNodes.length; i++) { if (node.childNodes[i].nodeName != "LI") { continue; } @@ -678,7 +686,10 @@ function resort_category(node) { var tmp_val = get_feed_entry_unread(node.childNodes[i]); var cur_val = get_feed_entry_unread(node.childNodes[j]); - if (cur_val > tmp_val) { + var tmp_name = get_feed_entry_name(node.childNodes[i]); + var cur_name = get_feed_entry_name(node.childNodes[j]); + + if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) { tempnode_i = node.childNodes[i].cloneNode(true); tempnode_j = node.childNodes[j].cloneNode(true); node.replaceChild(tempnode_i, node.childNodes[j]); diff --git a/help/3.php b/help/3.php index 633f5c903..fa65df2cc 100644 --- a/help/3.php +++ b/help/3.php @@ -41,6 +41,7 @@ f a f s f e + f w q Q diff --git a/tt-rss.js b/tt-rss.js index e81987ef7..4b0b694fc 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -17,6 +17,7 @@ var hotkey_prefix = false; var init_params = new Object(); var ver_offset = 0; var hor_offset = 0; +var feeds_sort_by_unread = false; function tagsAreDisplayed() { return display_tags; @@ -451,6 +452,7 @@ function init_second_stage() { daemon_enabled = getInitParam("daemon_enabled") == 1; daemon_refresh_only = getInitParam("daemon_refresh_only") == 1; + feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; setTimeout('updateFeedList(false, false)', 50); @@ -1220,6 +1222,7 @@ function hotkey_handler(e) { } if (keycode == 87) { // w + feeds_sort_by_unread = !feeds_sort_by_unread; return resort_feedlist(); } @@ -1288,3 +1291,7 @@ function hotkey_handler(e) { exception_error("hotkey_handler", e); } } + +function feedsSortByUnread() { + return feeds_sort_by_unread; +}