Merge pull request #2414 from thelounge/xpaw/fix-2329

Fix join channel form not working
This commit is contained in:
Jérémie Astori 2018-05-15 01:19:38 -04:00 committed by GitHub
commit 8edc1be7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {
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")); closeForm(form.closest(".network"));
return false; return false;
}); });
});
function handleKeybinds() { form.on("submit", () => {
sidebar.find(".join-form input, .join-form button").each(function() { const networkElement = form.closest(".network");
const network = $(this).closest(".network"); const channel = form.find("input[name='channel']").val();
Mousetrap(this).bind("esc", () => closeForm(network)); 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;
});
}
}

View File

@ -163,7 +163,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>