From 58d4a2fda16ce4883d3a11d0e8c9a6549632fecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Finn=20Gl=C3=B6e?= Date: Sat, 28 Mar 2015 18:47:15 +0000 Subject: [PATCH] made channel names in chat clickable; lets users join channels --- client/css/style.css | 6 ++++++ client/js/shout.js | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/client/css/style.css b/client/css/style.css index 7ce8ea86..a81f1adf 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -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 { diff --git a/client/js/shout.js b/client/js/shout.js index a23dc7de..d8884c56 100644 --- a/client/js/shout.js +++ b/client/js/shout.js @@ -190,13 +190,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$2')); + 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; }