From 9ea39661409fc2b8851500f164e13b1b42047205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Thu, 21 Dec 2017 13:17:10 -0500 Subject: [PATCH] Move the join channel form to its own component --- client/js/join-channel.js | 37 +++++++++++++++++++++++++++++++++++++ client/js/lounge.js | 29 ----------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 client/js/join-channel.js diff --git a/client/js/join-channel.js b/client/js/join-channel.js new file mode 100644 index 00000000..738bf9e9 --- /dev/null +++ b/client/js/join-channel.js @@ -0,0 +1,37 @@ +"use strict"; + +const $ = require("jquery"); + +const socket = require("./socket"); +const utils = require("./utils"); + +const sidebar = $("#sidebar"); + +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"), + }); + } + channel.val(""); + key.val(""); + form.hide(); + return false; +}); diff --git a/client/js/lounge.js b/client/js/lounge.js index 8c1f1241..52703016 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -483,35 +483,6 @@ $(function() { closeChan($(this).closest(".chan")); }); - 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"), - }); - } - channel.val(""); - key.val(""); - form.hide(); - return false; - }); - const contextMenuActions = { join: function(itemData) { $(`#join-channel-${itemData}`).show();