Fix incorrect target in (dis)connect context menu

This commit is contained in:
Pavel Djundik 2018-07-06 21:21:57 +03:00
parent d5f0a2481f
commit 9447b4894d

View File

@ -127,57 +127,35 @@ function addCloseItem() {
} }
function addConnectItem() { function addConnectItem() {
let clickedNetwork; function connect(itemData) {
function isDisconnected(target) {
return target.parent().hasClass("not-connected");
}
function connect() {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number(itemData),
text: "/connect", text: "/connect",
}); });
} }
function check(target) {
clickedNetwork = target;
return target.hasClass("lobby") && isDisconnected(target);
}
addContextMenuItem({ addContextMenuItem({
check: check, check: (target) => target.hasClass("lobby") && target.parent().hasClass("not-connected"),
className: "connect", className: "connect",
displayName: "Connect", displayName: "Connect",
data: () => clickedNetwork.data("id"), data: (target) => target.data("id"),
callback: connect, callback: connect,
}); });
} }
function addDisconnectItem() { function addDisconnectItem() {
let clickedNetwork; function disconnect(itemData) {
function isConnected(target) {
return !target.parent().hasClass("not-connected");
}
function disconnect() {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number(itemData),
text: "/disconnect", text: "/disconnect",
}); });
} }
function check(target) {
clickedNetwork = target;
return target.hasClass("lobby") && isConnected(target);
}
addContextMenuItem({ addContextMenuItem({
check: check, check: (target) => target.hasClass("lobby") && !target.parent().hasClass("not-connected"),
className: "disconnect", className: "disconnect",
displayName: "Disconnect", displayName: "Disconnect",
data: () => clickedNetwork.data("id"), data: (target) => target.data("id"),
callback: disconnect, callback: disconnect,
}); });
} }