Focus a channel by joining it, refactor user commands #1189

This commit is contained in:
realies 2017-09-02 19:28:36 +03:00
parent 77e9cb65d5
commit bb1e3ee917
3 changed files with 72 additions and 27 deletions

View File

@ -19,6 +19,7 @@ require("./socket-events");
const storage = require("./localStorage"); const storage = require("./localStorage");
const options = require("./options"); const options = require("./options");
const utils = require("./utils"); const utils = require("./utils");
const modules = require("./modules");
require("./autocompletion"); require("./autocompletion");
require("./webpush"); require("./webpush");
@ -194,19 +195,27 @@ $(function() {
input.val(""); input.val("");
resetInputHeight(input.get(0)); resetInputHeight(input.get(0));
if (text.indexOf("/clear") === 0) { if (text.indexOf("/") === 0) {
utils.clear(); const separatorPos = text.indexOf(" ");
return; 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) : "";
switch (cmd) {
if (text.indexOf("/collapse") === 0) { case "clear":
$(".chan.active .toggle-button.opened").click(); if (modules.clear()) return;
return; break;
} case "collapse":
if (modules.collapse()) return;
if (text.indexOf("/expand") === 0) { break;
$(".chan.active .toggle-button:not(.opened)").click(); case "expand":
return; if (modules.expand()) return;
break;
case "join":
const channel = parameters.split(" ")[0];
if (channel != "") {
if (modules.join(channel)) return;
}
break;
}
} }
socket.emit("input", { socket.emit("input", {
@ -215,18 +224,6 @@ $(function() {
}); });
}); });
function findCurrentNetworkChan(name) {
name = name.toLowerCase();
return $(".network .chan.active")
.parent(".network")
.find(".chan")
.filter(function() {
return $(this).data("title").toLowerCase() === name;
})
.first();
}
$("button#set-nick").on("click", function() { $("button#set-nick").on("click", function() {
utils.toggleNickEditor(true); utils.toggleNickEditor(true);
@ -283,7 +280,7 @@ $(function() {
chat.on("click", ".inline-channel", function() { chat.on("click", ".inline-channel", function() {
var name = $(this).data("chan"); var name = $(this).data("chan");
var chan = findCurrentNetworkChan(name); var chan = utils.findCurrentNetworkChan(name);
if (chan.length) { if (chan.length) {
chan.click(); chan.click();
@ -301,7 +298,7 @@ $(function() {
chat.on("click", ".user", function() { chat.on("click", ".user", function() {
var name = $(this).data("name"); var name = $(this).data("name");
var chan = findCurrentNetworkChan(name); var chan = utils.findCurrentNetworkChan(name);
if (chan.length) { if (chan.length) {
chan.click(); chan.click();

35
client/js/modules.js Normal file
View File

@ -0,0 +1,35 @@
"use strict";
// vendor libraries
const $ = require("jquery");
// our libraries
const utils = require("./utils");
module.exports = {
clear,
collapse,
expand,
join
};
function clear() {
utils.clear();
}
function collapse() {
$(".chan.active .toggle-button.opened").click();
}
function expand() {
$(".chan.active .toggle-button:not(.opened)").click();
}
function join(channel) {
var chan = utils.findCurrentNetworkChan(channel);
if (chan.length) {
chan.click();
return true;
}
}

View File

@ -5,6 +5,7 @@ const chat = $("#chat");
const input = $("#input"); const input = $("#input");
module.exports = { module.exports = {
findCurrentNetworkChan,
clear, clear,
confirmExit, confirmExit,
forceFocus, forceFocus,
@ -15,6 +16,18 @@ module.exports = {
toggleNotificationMarkers toggleNotificationMarkers
}; };
function findCurrentNetworkChan(name) {
name = name.toLowerCase();
return $(".network .chan.active")
.parent(".network")
.find(".chan")
.filter(function() {
return $(this).data("title").toLowerCase() === name;
})
.first();
}
function resetHeight(element) { function resetHeight(element) {
element.style.height = element.style.minHeight; element.style.height = element.style.minHeight;
} }