diff --git a/client/js/join-channel.js b/client/js/join-channel.js index b21a67eb..c59b7808 100644 --- a/client/js/join-channel.js +++ b/client/js/join-channel.js @@ -48,7 +48,7 @@ function openForm(network) { } sidebar.on("click", ".add-channel", function(e) { - const id = $(e.target).data("id"); + const id = $(e.target).closest(".lobby").data("id"); const joinForm = $(`#join-channel-${id}`); const network = joinForm.closest(".network"); @@ -61,30 +61,36 @@ sidebar.on("click", ".add-channel", function(e) { 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); +function handleKeybinds(networks) { + for (const network of networks) { + const form = $(`.network[data-uuid="${network.uuid}"] .join-form`); - if (chan.length) { - chan.trigger("click"); - } else { - socket.emit("input", { - text: `/join ${channelString} ${keyString}`, - target: form.prev().data("id"), + form.find("input, button").each(function() { + Mousetrap(this).bind("esc", () => { + closeForm(form.closest(".network")); + + return false; + }); + }); + + form.on("submit", () => { + const networkElement = form.closest(".network"); + const channel = form.find("input[name='channel']").val(); + const key = form.find("input[name='key']").val(); + const existingChannel = utils.findCurrentNetworkChan(channel); + + if (existingChannel.length) { + existingChannel.trigger("click"); + } else { + socket.emit("input", { + text: `/join ${channel} ${key}`, + target: networkElement.find(".lobby").data("id"), + }); + } + + closeForm(networkElement); + + return false; }); } - - closeForm(form.closest(".network")); - return false; -}); - -function handleKeybinds() { - sidebar.find(".join-form input, .join-form button").each(function() { - const network = $(this).closest(".network"); - Mousetrap(this).bind("esc", () => closeForm(network)); - }); } diff --git a/client/js/lounge.js b/client/js/lounge.js index 25302198..2f9a033f 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -163,7 +163,7 @@ $(function() { const target = self.attr("data-target"); if (!target) { - return false; + return; } // This is a rather gross hack to account for sources that are in the diff --git a/client/js/render.js b/client/js/render.js index a8363382..9836faf7 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -210,7 +210,7 @@ function renderNetworks(data, singleNetwork) { }); // Add keyboard handlers to the "Join a channel…" form inputs/button - JoinChannel.handleKeybinds(); + JoinChannel.handleKeybinds(data.networks); let newChannels; const channels = $.map(data.networks, function(n) { diff --git a/client/views/chan.tpl b/client/views/chan.tpl index 71f5322c..93bc5712 100644 --- a/client/views/chan.tpl +++ b/client/views/chan.tpl @@ -23,7 +23,7 @@ {{#if unread}}{{roundBadgeNumber unread}}{{/if}} - + {{/equal}} {{#notEqual type "lobby"}} diff --git a/client/views/join_channel.tpl b/client/views/join_channel.tpl index 53c6b828..be1ae9f4 100644 --- a/client/views/join_channel.tpl +++ b/client/views/join_channel.tpl @@ -1,5 +1,5 @@