From 9447b4894d9b1d74ab2fc95f9348914422ceb855 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 6 Jul 2018 21:21:57 +0300 Subject: [PATCH] Fix incorrect target in (dis)connect context menu --- client/js/contextMenuFactory.js | 38 +++++++-------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/client/js/contextMenuFactory.js b/client/js/contextMenuFactory.js index 52538ad5..1287c02a 100644 --- a/client/js/contextMenuFactory.js +++ b/client/js/contextMenuFactory.js @@ -127,57 +127,35 @@ function addCloseItem() { } function addConnectItem() { - let clickedNetwork; - - function isDisconnected(target) { - return target.parent().hasClass("not-connected"); - } - - function connect() { + function connect(itemData) { socket.emit("input", { - target: $("#chat").data("id"), + target: Number(itemData), text: "/connect", }); } - function check(target) { - clickedNetwork = target; - return target.hasClass("lobby") && isDisconnected(target); - } - addContextMenuItem({ - check: check, + check: (target) => target.hasClass("lobby") && target.parent().hasClass("not-connected"), className: "connect", displayName: "Connect", - data: () => clickedNetwork.data("id"), + data: (target) => target.data("id"), callback: connect, }); } function addDisconnectItem() { - let clickedNetwork; - - function isConnected(target) { - return !target.parent().hasClass("not-connected"); - } - - function disconnect() { + function disconnect(itemData) { socket.emit("input", { - target: $("#chat").data("id"), + target: Number(itemData), text: "/disconnect", }); } - function check(target) { - clickedNetwork = target; - return target.hasClass("lobby") && isConnected(target); - } - addContextMenuItem({ - check: check, + check: (target) => target.hasClass("lobby") && !target.parent().hasClass("not-connected"), className: "disconnect", displayName: "Disconnect", - data: () => clickedNetwork.data("id"), + data: (target) => target.data("id"), callback: disconnect, }); }