From 30be2dbbcff4b01869bbb0120eb6679cc4b55cd0 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 31 May 2013 16:32:34 +0200 Subject: Navigate through unread messages with 'j' and 'k' --- hyperkitty/static/js/hyperkitty.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'hyperkitty/static/js/hyperkitty.js') diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index 5fcb539..4b64b91 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -263,6 +263,31 @@ function setup_replies(baseElem) { }).change(); } +function setup_navkeys() { + var current_index; + function scroll(e) { + var inc; + var unreads = $(".email.unread"); + if (unreads.length == 0) { return; } + if (e.data == "j") { inc = 1; } + if (e.data == "k") { inc = -1; } + if (typeof current_index == "undefined") { + if (inc == 1) { current_index = -1; } + if (inc == -1) { current_index = unreads.length; } + } + current_index = current_index + inc; + if (current_index < 0) { current_index = unreads.length - 1; } + if (current_index >= unreads.length) { current_index = 0; } + // compensate for the fixed banner at the top + var target = unreads.eq(current_index).offset().top - 70; + $("html,body").animate({ + scrollTop: target + }, 500); + } + $(document).bind("keydown", "j", scroll); + $(document).bind("keydown", "k", scroll); +} + /* * Recent activity graph -- cgit