Move the join channel form to its own component
This commit is contained in:
parent
522bba694b
commit
9ea3966140
37
client/js/join-channel.js
Normal file
37
client/js/join-channel.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const $ = require("jquery");
|
||||||
|
|
||||||
|
const socket = require("./socket");
|
||||||
|
const utils = require("./utils");
|
||||||
|
|
||||||
|
const sidebar = $("#sidebar");
|
||||||
|
|
||||||
|
sidebar.on("click", ".add-channel", (e) => {
|
||||||
|
const id = $(e.target).data("id");
|
||||||
|
const joinForm = $(`#join-channel-${id}`);
|
||||||
|
joinForm.toggle();
|
||||||
|
joinForm.find(".input[name='channel']").focus();
|
||||||
|
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);
|
||||||
|
if (chan.length) {
|
||||||
|
chan.click();
|
||||||
|
} else {
|
||||||
|
socket.emit("input", {
|
||||||
|
text: `/join ${channelString} ${keyString}`,
|
||||||
|
target: form.prev().data("id"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
channel.val("");
|
||||||
|
key.val("");
|
||||||
|
form.hide();
|
||||||
|
return false;
|
||||||
|
});
|
@ -483,35 +483,6 @@ $(function() {
|
|||||||
closeChan($(this).closest(".chan"));
|
closeChan($(this).closest(".chan"));
|
||||||
});
|
});
|
||||||
|
|
||||||
sidebar.on("click", ".add-channel", (e) => {
|
|
||||||
const id = $(e.target).data("id");
|
|
||||||
const joinForm = $(`#join-channel-${id}`);
|
|
||||||
joinForm.toggle();
|
|
||||||
joinForm.find(".input[name='channel']").focus();
|
|
||||||
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);
|
|
||||||
if (chan.length) {
|
|
||||||
chan.click();
|
|
||||||
} else {
|
|
||||||
socket.emit("input", {
|
|
||||||
text: `/join ${channelString} ${keyString}`,
|
|
||||||
target: form.prev().data("id"),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
channel.val("");
|
|
||||||
key.val("");
|
|
||||||
form.hide();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const contextMenuActions = {
|
const contextMenuActions = {
|
||||||
join: function(itemData) {
|
join: function(itemData) {
|
||||||
$(`#join-channel-${itemData}`).show();
|
$(`#join-channel-${itemData}`).show();
|
||||||
|
Loading…
Reference in New Issue
Block a user