2017-09-06 06:41:11 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const Mousetrap = require("mousetrap");
|
2018-03-20 17:44:27 +00:00
|
|
|
const utils = require("./utils");
|
2017-09-06 06:41:11 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
Mousetrap.bind(["alt+up", "alt+down"], function(e, keys) {
|
2018-07-09 18:51:27 +00:00
|
|
|
const sidebar = $("#sidebar");
|
2018-04-26 08:10:41 +00:00
|
|
|
const channels = sidebar.find(".chan").not(".network.collapsed :not(.lobby)");
|
2017-09-06 06:41:11 +00:00
|
|
|
const index = channels.index(channels.filter(".active"));
|
|
|
|
const direction = keys.split("+").pop();
|
|
|
|
let target;
|
|
|
|
|
|
|
|
switch (direction) {
|
2019-07-17 09:33:59 +00:00
|
|
|
case "up":
|
|
|
|
target = (channels.length + (index - 1 + channels.length)) % channels.length;
|
|
|
|
break;
|
2017-09-06 06:41:11 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
case "down":
|
|
|
|
target = (channels.length + (index + 1 + channels.length)) % channels.length;
|
|
|
|
break;
|
2017-09-06 06:41:11 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 17:44:27 +00:00
|
|
|
target = channels.eq(target).click();
|
|
|
|
utils.scrollIntoViewNicely(target[0]);
|
2018-03-20 19:00:03 +00:00
|
|
|
|
|
|
|
return false;
|
2017-09-06 06:41:11 +00:00
|
|
|
});
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
Mousetrap.bind(["alt+shift+up", "alt+shift+down"], function(e, keys) {
|
2018-07-09 18:51:27 +00:00
|
|
|
const sidebar = $("#sidebar");
|
2018-03-15 14:10:20 +00:00
|
|
|
const lobbies = sidebar.find(".lobby");
|
|
|
|
const direction = keys.split("+").pop();
|
|
|
|
let index = lobbies.index(lobbies.filter(".active"));
|
|
|
|
let target;
|
|
|
|
|
|
|
|
switch (direction) {
|
2019-07-17 09:33:59 +00:00
|
|
|
case "up":
|
|
|
|
if (index < 0) {
|
|
|
|
target = lobbies.index(
|
|
|
|
sidebar
|
|
|
|
.find(".channel")
|
|
|
|
.filter(".active")
|
|
|
|
.siblings(".lobby")[0]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
target = (lobbies.length + (index - 1 + lobbies.length)) % lobbies.length;
|
|
|
|
}
|
2018-03-15 14:10:20 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
break;
|
2018-03-15 14:10:20 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
case "down":
|
|
|
|
if (index < 0) {
|
|
|
|
index = lobbies.index(
|
|
|
|
sidebar
|
|
|
|
.find(".channel")
|
|
|
|
.filter(".active")
|
|
|
|
.siblings(".lobby")[0]
|
|
|
|
);
|
|
|
|
}
|
2018-03-15 14:10:20 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
target = (lobbies.length + (index + 1 + lobbies.length)) % lobbies.length;
|
2018-03-15 14:10:20 +00:00
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
break;
|
2018-03-15 14:10:20 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 17:44:27 +00:00
|
|
|
target = lobbies.eq(target).click();
|
|
|
|
utils.scrollIntoViewNicely(target[0]);
|
2018-03-20 19:00:03 +00:00
|
|
|
|
|
|
|
return false;
|
2018-03-15 14:10:20 +00:00
|
|
|
});
|
|
|
|
|
2018-03-13 08:32:15 +00:00
|
|
|
// Ignored keys which should not automatically focus the input bar
|
|
|
|
const ignoredKeys = {
|
|
|
|
8: true, // Backspace
|
|
|
|
9: true, // Tab
|
|
|
|
12: true, // Clear
|
|
|
|
16: true, // Shift
|
|
|
|
17: true, // Control
|
|
|
|
18: true, // Alt
|
|
|
|
19: true, // Pause
|
|
|
|
20: true, // CapsLock
|
|
|
|
27: true, // Escape
|
|
|
|
35: true, // End
|
|
|
|
36: true, // Home
|
|
|
|
37: true, // ArrowLeft
|
|
|
|
38: true, // ArrowUp
|
|
|
|
39: true, // ArrowRight
|
|
|
|
40: true, // ArrowDown
|
|
|
|
45: true, // Insert
|
|
|
|
46: true, // Delete
|
|
|
|
112: true, // F1
|
|
|
|
113: true, // F2
|
|
|
|
114: true, // F3
|
|
|
|
115: true, // F4
|
|
|
|
116: true, // F5
|
|
|
|
117: true, // F6
|
|
|
|
118: true, // F7
|
|
|
|
119: true, // F8
|
|
|
|
120: true, // F9
|
|
|
|
121: true, // F10
|
|
|
|
122: true, // F11
|
|
|
|
123: true, // F12
|
|
|
|
144: true, // NumLock
|
|
|
|
145: true, // ScrollLock
|
|
|
|
224: true, // Meta
|
|
|
|
};
|
|
|
|
|
2018-06-10 10:46:00 +00:00
|
|
|
$(document).on("keydown", (e) => {
|
2018-05-03 12:51:40 +00:00
|
|
|
// Ignore any key that uses alt modifier
|
|
|
|
// Ignore keys defined above
|
2018-06-10 10:46:00 +00:00
|
|
|
if (e.altKey || ignoredKeys[e.which]) {
|
2018-05-03 12:51:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-13 08:32:15 +00:00
|
|
|
|
2018-05-03 12:51:40 +00:00
|
|
|
// Ignore all ctrl keys except for ctrl+v to allow pasting
|
|
|
|
if ((e.ctrlKey || e.metaKey) && e.which !== 86) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-13 08:32:15 +00:00
|
|
|
|
2019-02-13 08:19:29 +00:00
|
|
|
// Redirect pagedown/pageup keys to messages container so it scrolls
|
|
|
|
if (e.which === 33 || e.which === 34) {
|
|
|
|
$("#windows .window.active .chan.active .chat").trigger("focus");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-10 10:46:00 +00:00
|
|
|
const tagName = e.target.tagName;
|
|
|
|
|
|
|
|
// Ignore if we're already typing into <input> or <textarea>
|
|
|
|
if (tagName === "INPUT" || tagName === "TEXTAREA") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:51:27 +00:00
|
|
|
const input = $("#input");
|
|
|
|
|
2018-05-03 12:51:40 +00:00
|
|
|
// On enter, focus the input but do not propagate the event
|
|
|
|
// This way, a new line is not inserted
|
|
|
|
if (e.which === 13) {
|
2018-03-13 08:32:15 +00:00
|
|
|
input.trigger("focus");
|
2018-05-03 12:51:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
input.trigger("focus");
|
|
|
|
});
|