2017-12-21 18:17:10 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
2017-12-21 20:40:50 +00:00
|
|
|
const Mousetrap = require("mousetrap");
|
2017-12-21 18:17:10 +00:00
|
|
|
|
|
|
|
const socket = require("./socket");
|
|
|
|
const utils = require("./utils");
|
|
|
|
|
|
|
|
const sidebar = $("#sidebar");
|
|
|
|
|
2017-12-21 20:40:50 +00:00
|
|
|
function closeForm(network) {
|
|
|
|
const form = network.find(".join-form");
|
|
|
|
form.find("input[name='channel']").val("");
|
|
|
|
form.find("input[name='key']").val("");
|
|
|
|
form.hide();
|
|
|
|
}
|
|
|
|
|
2017-12-21 18:17:10 +00:00
|
|
|
sidebar.on("click", ".add-channel", (e) => {
|
|
|
|
const id = $(e.target).data("id");
|
|
|
|
const joinForm = $(`#join-channel-${id}`);
|
|
|
|
joinForm.toggle();
|
|
|
|
joinForm.find(".input[name='channel']").focus();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
sidebar.on("submit", ".join-form", function() {
|
|
|
|
const form = $(this);
|
|
|
|
const channel = form.find("input[name='channel']");
|
|
|
|
const channelString = channel.val();
|
|
|
|
const key = form.find("input[name='key']");
|
|
|
|
const keyString = key.val();
|
|
|
|
const chan = utils.findCurrentNetworkChan(channelString);
|
|
|
|
if (chan.length) {
|
|
|
|
chan.click();
|
|
|
|
} else {
|
|
|
|
socket.emit("input", {
|
|
|
|
text: `/join ${channelString} ${keyString}`,
|
|
|
|
target: form.prev().data("id"),
|
|
|
|
});
|
|
|
|
}
|
2017-12-21 20:40:50 +00:00
|
|
|
closeForm(form.closest(".network"));
|
2017-12-21 18:17:10 +00:00
|
|
|
return false;
|
|
|
|
});
|
2017-12-21 20:40:50 +00:00
|
|
|
|
|
|
|
exports.handleKeybinds = function() {
|
|
|
|
sidebar.find(".join-form input, .join-form button").each(function() {
|
|
|
|
const network = $(this).closest(".network");
|
|
|
|
Mousetrap(this).bind("esc", () => closeForm(network));
|
|
|
|
});
|
|
|
|
};
|