Merge pull request #366 from thelounge/xpaw/fix-clicks

Improve click handling on users and inline channels
This commit is contained in:
Pavel Djundik 2016-07-03 20:51:20 +03:00 committed by GitHub
commit 34b4a7a018
2 changed files with 41 additions and 27 deletions

View File

@ -200,16 +200,18 @@ $(function() {
}) })
); );
renderChannel(data.chan); renderChannel(data.chan);
var chan = sidebar.find(".chan")
// Queries do not automatically focus, unless the user did a whois
if (data.chan.type === "query" && !data.shouldOpen) {
return;
}
sidebar.find(".chan")
.sort(function(a, b) { .sort(function(a, b) {
return $(a).data("id") - $(b).data("id"); return $(a).data("id") - $(b).data("id");
}) })
.last(); .last()
if (!whois) { .click();
chan = chan.filter(":not(.query)");
}
whois = false;
chan.click();
}); });
function buildChatMessage(data) { function buildChatMessage(data) {
@ -644,21 +646,46 @@ $(function() {
}); });
}); });
chat.on("click", ".inline-channel", function() { function findCurrentNetworkChan(name) {
var chan = $(".network") name = name.toLowerCase();
.find(".chan.active")
return $(".network .chan.active")
.parent(".network") .parent(".network")
.find(".chan[data-title='" + $(this).data("chan") + "']"); .find(".chan")
if (chan.size() === 1) { .filter(function() {
return $(this).data("title").toLowerCase() === name;
})
.first();
}
chat.on("click", ".inline-channel", function() {
var name = $(this).data("chan");
var chan = findCurrentNetworkChan(name);
if (chan.length) {
chan.click(); chan.click();
} else { } else {
socket.emit("input", { socket.emit("input", {
target: chat.data("id"), target: chat.data("id"),
text: "/join " + $(this).data("chan") text: "/join " + name
}); });
} }
}); });
chat.on("click", ".user", function() {
var name = $(this).data("name");
var chan = findCurrentNetworkChan(name);
if (chan.length) {
chan.click();
}
socket.emit("input", {
target: chat.data("id"),
text: "/whois " + name
});
});
chat.on("click", ".chat", function() { chat.on("click", ".chat", function() {
setTimeout(function() { setTimeout(function() {
var text = ""; var text = "";
@ -800,20 +827,6 @@ $(function() {
}); });
}); });
var whois = false;
chat.on("click", ".user", function() {
var user = $(this).text().trim().replace(/[+%@~&]/, "");
if (user.indexOf("#") !== -1) {
return;
}
whois = true;
var text = "/whois " + user;
socket.emit("input", {
target: chat.data("id"),
text: text
});
});
chat.on("msg", ".messages", function(e, target, msg) { chat.on("msg", ".messages", function(e, target, msg) {
if (msg.self) { if (msg.self) {
return; return;

View File

@ -12,6 +12,7 @@ module.exports = function(irc, network) {
}); });
network.channels.push(chan); network.channels.push(chan);
client.emit("join", { client.emit("join", {
shouldOpen: true,
network: network.id, network: network.id,
chan: chan chan: chan
}); });