Merge pull request #1491 from realies/master

Focus a channel by joining it, refactor user commands #1189
This commit is contained in:
Pavel Djundik 2017-11-22 15:42:32 +02:00 committed by GitHub
commit ca389c914f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 22 deletions

View File

@ -182,14 +182,12 @@ $(function() {
input.val("");
resetInputHeight(input.get(0));
if (text.indexOf("/collapse") === 0) {
$(".chan.active .toggle-preview.opened").click();
if (text.charAt(0) === "/") {
const args = text.substr(1).split(" ");
const cmd = args.shift().toLowerCase();
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
return;
}
if (text.indexOf("/expand") === 0) {
$(".chan.active .toggle-preview:not(.opened)").click();
return;
}
socket.emit("input", {
@ -198,18 +196,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);
@ -266,7 +252,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();
@ -284,7 +270,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();

View File

@ -7,6 +7,8 @@ var serverHash = -1;
var lastMessageId = -1;
module.exports = {
inputCommands: {collapse, expand, join},
findCurrentNetworkChan,
serverHash,
lastMessageId,
confirmExit,
@ -19,6 +21,18 @@ module.exports = {
requestIdleCallback,
};
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;
}
@ -29,6 +43,27 @@ function forceFocus() {
input.trigger("click").focus();
}
function collapse() {
$(".chan.active .toggle-button.opened").click();
return true;
}
function expand() {
$(".chan.active .toggle-button:not(.opened)").click();
return true;
}
function join(args) {
const channel = args[0];
if (channel) {
const chan = findCurrentNetworkChan(channel);
if (chan.length) {
chan.click();
return true;
}
}
}
function toggleNickEditor(toggle) {
$("#nick").toggleClass("editable", toggle);
$("#nick-value").attr("contenteditable", toggle);