From 65ab368ff08daa61ffe91fa05f32832987649f54 Mon Sep 17 00:00:00 2001 From: Brock Whittaker Date: Tue, 27 Sep 2016 16:19:20 -0700 Subject: [PATCH] Add arrow tab sections to home page. This lets you use up and down arrows in certain sections on the site to navigate lists. It also prevents potentially unwanted actions caused by using up/down arrows in those sections. Fixes: #1696. --- static/js/hotkey.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/static/js/hotkey.js b/static/js/hotkey.js index 56b832a94c..0c50cd8a86 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -61,6 +61,25 @@ var hotkeys_shift_insensitive = { 119: {name: 'query_streams', message_view_only: false} // 'w' }; +var tab_up_down = (function () { + var list = ["#group-pm-list", "#stream_filters", "#global_filters", "#user_presences"]; + + return function (e) { + var $target = $(e.target); + var flag = $target.closest(list.join(", ")); + + return { + flag: flag, + next: function () { + return $target.closest("li").next().find("a"); + }, + prev: function () { + return $target.closest("li").prev().find("a"); + } + }; + }; +}()); + function get_hotkey_from_event(e) { // We're in the middle of a combo; stop processing because @@ -95,6 +114,17 @@ function process_hotkey(e) { return false; } + var tab_list = tab_up_down(e); + if (tab_list.flag) { + if (hotkey.name === "up_arrow") { + tab_list.prev().focus(); + return true; + } else if (hotkey.name === "down_arrow") { + tab_list.next().focus(); + return true; + } + } + if (event_name === 'ignore') { return false; }