From 3890aaad6bb4d207a7f5923a330a263da2009161 Mon Sep 17 00:00:00 2001 From: realies Date: Tue, 3 Oct 2017 23:29:19 +0300 Subject: [PATCH] Use jQuery for parsing, isolate user commands, remove /clear --- client/js/lounge.js | 13 ++++++------- client/js/utils.js | 12 +----------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 2ffa9f6d..b04471b3 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -185,19 +185,18 @@ $(function() { resetInputHeight(input.get(0)); if (text.indexOf("/") === 0) { - const separatorPos = text.indexOf(" "); - const cmd = text.substring(1, separatorPos > 1 ? separatorPos : text.length); - const parameters = separatorPos > text.indexOf(cmd) ? text.substring(text.indexOf(cmd) + cmd.length + 1, text.length) : ""; - if (typeof utils[cmd] === "function") { + const args = text.substr(1).split(" "); + const cmd = args.shift().toLowerCase(); + if (typeof utils.inputCommands[cmd] === "function") { if (cmd === "join") { - const channel = parameters.split(" ")[0]; + const channel = args.shift(); if (channel !== "") { - if (utils[cmd](channel)) { + if (utils.inputCommands[cmd](channel)) { return; } } } else { - if (utils[cmd]()) { + if (utils.inputCommands[cmd]()) { return; } } diff --git a/client/js/utils.js b/client/js/utils.js index 2eae9a29..b916dfc3 100644 --- a/client/js/utils.js +++ b/client/js/utils.js @@ -8,11 +8,8 @@ var serverHash = -1; var lastMessageId = -1; module.exports = { + inputCommands: { collapse, expand, join }, findCurrentNetworkChan, - clear, - collapse, - expand, - join, serverHash, lastMessageId, confirmExit, @@ -47,13 +44,6 @@ function forceFocus() { input.trigger("click").focus(); } -function clear() { - chat.find(".active") - .find(".show-more").addClass("show").end() - .find(".messages .msg, .date-marker-container").remove(); - return true; -} - function collapse() { $(".chan.active .toggle-button.opened").click(); return true;