-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhip-slack-addon.js
43 lines (40 loc) · 1.47 KB
/
hip-slack-addon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function native_click(el)
{
var els_anchor = el.children('a')[0];
var clickEvent = document.createEvent("HTMLEvents");
clickEvent.initEvent("click", true, true);
els_anchor.dispatchEvent(clickEvent);
}
function step(current, list, step) {
var current_index = list.index(current);
var new_index = (current_index + step + list.length) % list.length
return $(list[new_index]);
}
$(document).keydown(function(event) {
if (event.altKey === true && event.shiftKey === true &&
(event.key == 'ArrowUp' || event.key == 'ArrowDown'))
{
var target_list = $('.hc-tab.aui-nav-selected, .hc-has-badge');
if (target_list.length > 1) {
if (event.key == 'ArrowUp') {
var next = step($('.hc-tab.aui-nav-selected')[0], target_list, -1)
}
else if (event.key == 'ArrowDown') {
var next = step($('.hc-tab.aui-nav-selected')[0], target_list, 1)
}
native_click(next);
}
}
else if (event.altKey === true && event.shiftKey === false &&
(event.key == 'ArrowUp' || event.key == 'ArrowDown'))
{
var target_list = $('.hc-room, .hc-person');
if (event.key == 'ArrowUp') {
var next = step($('.hc-tab.aui-nav-selected')[0], target_list, -1)
}
else if (event.key == 'ArrowDown') {
var next = step($('.hc-tab.aui-nav-selected')[0], target_list, 1)
}
native_click(next);
}
})