Fix join channel form not working

Fixes #2329
This commit is contained in:
Pavel Djundik 2018-05-02 16:57:19 +03:00
parent 5e1beb5b46
commit f23c063b71
5 changed files with 34 additions and 28 deletions

View File

@ -48,7 +48,7 @@ function openForm(network) {
} }
sidebar.on("click", ".add-channel", function(e) { 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 joinForm = $(`#join-channel-${id}`);
const network = joinForm.closest(".network"); const network = joinForm.closest(".network");
@ -61,30 +61,36 @@ sidebar.on("click", ".add-channel", function(e) {
return false; return false;
}); });
sidebar.on("submit", ".join-form", function() { function handleKeybinds(networks) {
const form = $(this); for (const network of networks) {
const channel = form.find("input[name='channel']"); const form = $(`.network[data-uuid="${network.uuid}"] .join-form`);
const channelString = channel.val();
const key = form.find("input[name='key']");
const keyString = key.val();
const chan = utils.findCurrentNetworkChan(channelString);
if (chan.length) { form.find("input, button").each(function() {
chan.trigger("click"); 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 { } else {
socket.emit("input", { socket.emit("input", {
text: `/join ${channelString} ${keyString}`, text: `/join ${channel} ${key}`,
target: form.prev().data("id"), target: networkElement.find(".lobby").data("id"),
}); });
} }
closeForm(form.closest(".network")); closeForm(networkElement);
return false;
});
function handleKeybinds() { return false;
sidebar.find(".join-form input, .join-form button").each(function() {
const network = $(this).closest(".network");
Mousetrap(this).bind("esc", () => closeForm(network));
}); });
}
} }

View File

@ -164,7 +164,7 @@ $(function() {
const target = self.attr("data-target"); const target = self.attr("data-target");
if (!target) { if (!target) {
return false; return;
} }
// This is a rather gross hack to account for sources that are in the // This is a rather gross hack to account for sources that are in the

View File

@ -210,7 +210,7 @@ function renderNetworks(data, singleNetwork) {
}); });
// Add keyboard handlers to the "Join a channel…" form inputs/button // Add keyboard handlers to the "Join a channel…" form inputs/button
JoinChannel.handleKeybinds(); JoinChannel.handleKeybinds(data.networks);
let newChannels; let newChannels;
const channels = $.map(data.networks, function(n) { const channels = $.map(data.networks, function(n) {

View File

@ -23,7 +23,7 @@
<span class="badge{{#if highlight}} highlight{{/if}}">{{#if unread}}{{roundBadgeNumber unread}}{{/if}}</span> <span class="badge{{#if highlight}} highlight{{/if}}">{{#if unread}}{{roundBadgeNumber unread}}{{/if}}</span>
</div> </div>
<span class="add-channel-tooltip tooltipped tooltipped-w tooltipped-no-touch" aria-label="Join a channel…" data-alt-label="Cancel"> <span class="add-channel-tooltip tooltipped tooltipped-w tooltipped-no-touch" aria-label="Join a channel…" data-alt-label="Cancel">
<button class="add-channel" aria-label="Join a channel…" data-id="{{id}}"></button> <button class="add-channel" aria-label="Join a channel…" aria-controls="join-channel-{{id}}"></button>
</span> </span>
{{/equal}} {{/equal}}
{{#notEqual type "lobby"}} {{#notEqual type "lobby"}}

View File

@ -1,5 +1,5 @@
<form id="join-channel-{{id}}" class="join-form" method="post" action="" autocomplete="off"> <form id="join-channel-{{id}}" class="join-form" method="post" action="" autocomplete="off">
<input type="text" class="input" name="channel" placeholder="Channel" pattern="[^\s]+" maxlength="200" title="The channel name may not contain spaces" required> <input type="text" class="input" name="channel" placeholder="Channel" pattern="[^\s]+" maxlength="200" title="The channel name may not contain spaces" required>
<input type="password" class="input" name="key" placeholder="Password (optional)" pattern="[^\s]+" maxlength="200" title="The channel password may not contain spaces" autocomplete="new-password"> <input type="password" class="input" name="key" placeholder="Password (optional)" pattern="[^\s]+" maxlength="200" title="The channel password may not contain spaces" autocomplete="new-password">
<button type="submit" class="btn btn-small" data-id="{{id}}">Join</button> <button type="submit" class="btn btn-small">Join</button>
</form> </form>