Merge pull request #385 from AmShaegar13/click_channel

made channel names in chat clickable; lets users join channels
This commit is contained in:
Jérémie Astori 2016-01-07 00:53:42 -05:00
commit 409936e57a
2 changed files with 33 additions and 1 deletions

View File

@ -608,6 +608,12 @@ button {
display: none;
font-style: normal;
}
#chat .msg .inline-channel {
cursor: pointer;
}
#chat .msg .inline-channel:hover {
opacity: .6;
}
#chat .time,
#chat .from,
#chat .text {

View File

@ -191,13 +191,39 @@ $(function() {
var chan = chat.find(target);
var from = data.msg.from;
var msg = $(render("msg", {messages: [data.msg]}));
chan.find(".messages")
.append(render("msg", {messages: [data.msg]}))
.append(msg)
.trigger("msg", [
target,
data.msg
]);
var text = msg.find(".text");
if (text.find("i").size() === 1) {
text = text.find("i");
}
// Channels names are strings (beginning with a '&' or '#' character)
// of length up to 200 characters.
// See https://tools.ietf.org/html/rfc1459#section-1.3
text.html(text.html().replace(/(^|\s)([#&][^\x07\x2C\s]{0,199})/ig,
'$1<span class="inline-channel" role="button" tabindex="0" data-chan="$2">$2</span>'));
text.find("span.inline-channel")
.on("click", function() {
var chan = $(".network")
.find(".chan.active")
.parent(".network")
.find(".chan[data-title='" + $(this).data("chan") + "']");
if (chan.size() === 1) {
chan.click();
} else {
socket.emit("input", {
target: chat.data("id"),
text: "/join " + $(this).data("chan")
});
}
});
if (!chan.hasClass("channel")) {
return;
}