Skip to content

Commit

Permalink
Merge pull request thelounge#366 from thelounge/xpaw/fix-clicks
Browse files Browse the repository at this point in the history
Improve click handling on users and inline channels
  • Loading branch information
xPaw authored Jul 3, 2016
2 parents 7f0fc4d + 106d488 commit 8daac11
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
67 changes: 40 additions & 27 deletions client/js/lounge.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,18 @@ $(function() {
})
);
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) {
return $(a).data("id") - $(b).data("id");
})
.last();
if (!whois) {
chan = chan.filter(":not(.query)");
}
whois = false;
chan.click();
.last()
.click();
});

function buildChatMessage(data) {
Expand Down Expand Up @@ -644,21 +646,46 @@ $(function() {
});
});

chat.on("click", ".inline-channel", function() {
var chan = $(".network")
.find(".chan.active")
function findCurrentNetworkChan(name) {
name = name.toLowerCase();

return $(".network .chan.active")
.parent(".network")
.find(".chan[data-title='" + $(this).data("chan") + "']");
if (chan.size() === 1) {
.find(".chan")
.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();
} else {
socket.emit("input", {
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() {
setTimeout(function() {
var text = "";
Expand Down Expand Up @@ -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) {
if (msg.self) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/irc-events/whois.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = function(irc, network) {
});
network.channels.push(chan);
client.emit("join", {
shouldOpen: true,
network: network.id,
chan: chan
});
Expand Down

0 comments on commit 8daac11

Please sign in to comment.