Nicks within messages now colorised + clickable
authorDarren <darren@darrenwhitlen.com>
Sun, 13 Jul 2014 13:55:49 +0000 (14:55 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 13 Jul 2014 13:55:49 +0000 (14:55 +0100)
client/src/views/channel.js

index bf1fcc2b55a98a4ddd1412830006b6eb3269b841..c188ce5488ee4087f0eca4f7c5dbcbe8e162c081 100644 (file)
@@ -7,6 +7,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         }
         return _.extend({}, parent_events, {
             'click .msg .nick' : 'nickClick',
+            'click .msg .inline-nick' : 'nickClick',
             "click .chan": "chanClick",
             'click .media .open': 'mediaClick',
             'mouseenter .msg .nick': 'msgEnter',
@@ -148,6 +149,31 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
     },
 
 
+    // Let nicks be clickable + colourise within messages
+    parseMessageNicks: function(word) {
+        var members, member, colour;
+
+        members = this.model.get('members');
+        if (!members) {
+            return;
+        }
+
+        member = members.getByNick(word);
+        if (!member) {
+            return;
+        }
+
+        // Use the nick from the member object so the colour matches the letter casing
+        colour = this.getNickColour(member.get('nick'));
+
+        return _.template('<span class="inline-nick" style="color:<%- colour %>;cursor:pointer;" data-nick="<%- nick %>"><%- nick %></span>', {
+            nick: word,
+            colour: colour
+        });
+
+    },
+
+
     // Make channels clickable
     parseMessageChannels: function(word) {
         var re,
@@ -258,6 +284,9 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
             parsed_word = this.parseMessageChannels(word);
             if (typeof parsed_word === 'string') return parsed_word;
 
+            parsed_word = this.parseMessageNicks(word);
+            if (typeof parsed_word === 'string') return parsed_word;
+
             parsed_word = _.escape(word);
 
             // Replace text emoticons with images
@@ -337,11 +366,20 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
 
     // Click on a nickname
     nickClick: function (event) {
-        var nick = $(event.currentTarget).parent('.msg').data('message').nick,
+        var nick,
             members = this.model.get('members'),
             are_we_an_op = !!members.getByNick(_kiwi.app.connections.active_connection.get('nick')).get('is_op'),
             member, query, userbox, menubox;
 
+        event.stopPropagation();
+
+        // Check this current element for a nick before resorting to the main message
+        // (eg. inline nicks has the nick on its own element within the message)
+        nick = $(event.currentTarget).data('nick');
+        if (!nick) {
+            nick = $(event.currentTarget).parent('.msg').data('message').nick;
+        }
+
         if (members) {
             member = members.getByNick(nick);
             if (member) {