2017-09-06 06:41:11 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const Mousetrap = require("mousetrap");
|
|
|
|
const input = $("#input");
|
|
|
|
const sidebar = $("#sidebar");
|
|
|
|
const windows = $("#windows");
|
|
|
|
const contextMenuContainer = $("#context-menu-container");
|
|
|
|
|
|
|
|
Mousetrap.bind([
|
|
|
|
"pageup",
|
2017-11-15 06:35:15 +00:00
|
|
|
"pagedown",
|
2017-09-06 06:41:11 +00:00
|
|
|
], function(e, key) {
|
|
|
|
let container = windows.find(".window.active");
|
|
|
|
|
|
|
|
// Chat windows scroll message container
|
2018-01-30 09:38:33 +00:00
|
|
|
if (container.prop("id") === "chat-container") {
|
2017-09-06 06:41:11 +00:00
|
|
|
container = container.find(".chan.active .chat");
|
|
|
|
}
|
|
|
|
|
|
|
|
container.finish();
|
|
|
|
|
|
|
|
const offset = container.get(0).clientHeight * 0.9;
|
|
|
|
let scrollTop = container.scrollTop();
|
|
|
|
|
|
|
|
if (key === "pageup") {
|
|
|
|
scrollTop = Math.floor(scrollTop - offset);
|
|
|
|
} else {
|
|
|
|
scrollTop = Math.ceil(scrollTop + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
container.animate({
|
2017-11-15 06:35:15 +00:00
|
|
|
scrollTop: scrollTop,
|
2017-09-06 06:41:11 +00:00
|
|
|
}, 200);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
Mousetrap.bind([
|
2017-12-16 21:14:12 +00:00
|
|
|
"mod+up",
|
|
|
|
"mod+down",
|
2017-09-06 06:41:11 +00:00
|
|
|
], function(e, keys) {
|
|
|
|
const channels = sidebar.find(".chan");
|
|
|
|
const index = channels.index(channels.filter(".active"));
|
|
|
|
const direction = keys.split("+").pop();
|
|
|
|
let target;
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
case "up":
|
|
|
|
target = (channels.length + (index - 1 + channels.length)) % channels.length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "down":
|
|
|
|
target = (channels.length + (index + 1 + channels.length)) % channels.length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
channels.eq(target).click();
|
|
|
|
});
|
|
|
|
|
|
|
|
Mousetrap.bind([
|
2017-11-15 06:35:15 +00:00
|
|
|
"escape",
|
2017-09-06 06:41:11 +00:00
|
|
|
], function() {
|
|
|
|
contextMenuContainer.hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
const colorsHotkeys = {
|
|
|
|
k: "\x03",
|
|
|
|
b: "\x02",
|
|
|
|
u: "\x1F",
|
|
|
|
i: "\x1D",
|
|
|
|
o: "\x0F",
|
2017-12-03 02:52:49 +00:00
|
|
|
s: "\x1e",
|
2017-12-03 15:00:35 +00:00
|
|
|
m: "\x11",
|
2017-09-06 06:41:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const hotkey in colorsHotkeys) {
|
2017-12-16 21:14:12 +00:00
|
|
|
Mousetrap.bind("mod+" + hotkey, function(e) {
|
2017-09-06 06:41:11 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const cursorPosStart = input.prop("selectionStart");
|
|
|
|
const cursorPosEnd = input.prop("selectionEnd");
|
|
|
|
const value = input.val();
|
|
|
|
let newValue = value.substring(0, cursorPosStart) + colorsHotkeys[e.key];
|
|
|
|
|
|
|
|
if (cursorPosStart === cursorPosEnd) {
|
|
|
|
// If no text is selected, insert at cursor
|
|
|
|
newValue += value.substring(cursorPosEnd, value.length);
|
|
|
|
} else {
|
|
|
|
// If text is selected, insert formatting character at start and the end
|
|
|
|
newValue += value.substring(cursorPosStart, cursorPosEnd) + colorsHotkeys[e.key] + value.substring(cursorPosEnd, value.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
input
|
|
|
|
.val(newValue)
|
|
|
|
.get(0).setSelectionRange(cursorPosStart + 1, cursorPosEnd + 1);
|
|
|
|
});
|
|
|
|
}
|