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) {
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));
});
}

View file

@ -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

View file

@ -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) {

View file

@ -23,7 +23,7 @@
<span class="badge{{#if highlight}} highlight{{/if}}">{{#if unread}}{{roundBadgeNumber unread}}{{/if}}</span>
</div>
<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>
{{/equal}}
{{#notEqual type "lobby"}}

View file

@ -1,5 +1,5 @@
<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="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>