Call the openForm function specifically when clicking on the context menu instead of relying on click handler

Not defining a `toggleForm` function has the advantage of "fixing" the fact that clicking "Join a channel..." from the context menu would close it when it was already open
This commit is contained in:
Jérémie Astori 2017-12-22 12:18:10 -05:00
parent 1063d7b1d6
commit 47f95c234d
No known key found for this signature in database
GPG key ID: B9A4F245CD67BDE8
2 changed files with 29 additions and 10 deletions

View file

@ -8,6 +8,11 @@ const utils = require("./utils");
const sidebar = $("#sidebar");
module.exports = {
handleKeybinds,
openForm,
};
function toggleButton(network) {
// Transform the + button to a ×
network.find("button.add-channel").toggleClass("opened");
@ -21,11 +26,25 @@ function toggleButton(network) {
function closeForm(network) {
const form = network.find(".join-form");
form.find("input[name='channel']").val("");
form.find("input[name='key']").val("");
form.hide();
toggleButton(network);
if (form.is(":visible")) {
form.find("input[name='channel']").val("");
form.find("input[name='key']").val("");
form.hide();
toggleButton(network);
}
}
function openForm(network) {
const form = network.find(".join-form");
if (form.is(":hidden")) {
form.show();
toggleButton(network);
}
// Focus the "Channel" field even if the form was already open
form.find(".input[name='channel']").focus();
}
sidebar.on("click", ".add-channel", function(e) {
@ -36,9 +55,7 @@ sidebar.on("click", ".add-channel", function(e) {
if (joinForm.is(":visible")) {
closeForm(network);
} else {
joinForm.show();
joinForm.find(".input[name='channel']").focus();
toggleButton(network);
openForm(network);
}
return false;
@ -63,9 +80,9 @@ sidebar.on("submit", ".join-form", function() {
return false;
});
exports.handleKeybinds = function() {
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

@ -20,6 +20,7 @@ const utils = require("./utils");
require("./webpush");
require("./keybinds");
require("./clipboard");
const JoinChannel = require("./join-channel");
$(function() {
var sidebar = $("#sidebar, #footer");
@ -485,7 +486,8 @@ $(function() {
const contextMenuActions = {
join: function(itemData) {
$(`#join-channel-${itemData}`).closest(".network").find("button.add-channel").click();
const network = $(`#join-channel-${itemData}`).closest(".network");
JoinChannel.openForm(network);
},
close: function(itemData) {
closeChan($(`.networks .chan[data-target="${itemData}"]`));