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 options = require("./options");
const utils = require("./utils");
const modules = require("./modules");
require("./autocompletion");
require("./webpush");
@ -194,19 +195,27 @@ $(function() {
input.val("");
resetInputHeight(input.get(0));
if (text.indexOf("/clear") === 0) {
utils.clear();
return;
}
if (text.indexOf("/collapse") === 0) {
$(".chan.active .toggle-button.opened").click();
return;
}
if (text.indexOf("/expand") === 0) {
$(".chan.active .toggle-button:not(.opened)").click();
return;
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) : "";
switch (cmd) {
case "clear":
if (modules.clear()) return;
break;
case "collapse":
if (modules.collapse()) return;
break;
case "expand":
if (modules.expand()) return;
break;
case "join":
const channel = parameters.split(" ")[0];
if (channel != "") {
if (modules.join(channel)) return;
}
break;
}
}
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() {
utils.toggleNickEditor(true);
@ -283,7 +280,7 @@ $(function() {
chat.on("click", ".inline-channel", function() {
var name = $(this).data("chan");
var chan = findCurrentNetworkChan(name);
var chan = utils.findCurrentNetworkChan(name);
if (chan.length) {
chan.click();
@ -301,7 +298,7 @@ $(function() {
chat.on("click", ".user", function() {
var name = $(this).data("name");
var chan = findCurrentNetworkChan(name);
var chan = utils.findCurrentNetworkChan(name);
if (chan.length) {
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");
module.exports = {
findCurrentNetworkChan,
clear,
confirmExit,
forceFocus,
@ -15,6 +16,18 @@ module.exports = {
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) {
element.style.height = element.style.minHeight;
}