From 99499ace2006fe0a4b89a5f48827a30e77827480 Mon Sep 17 00:00:00 2001 From: Darren Date: Thu, 4 Dec 2014 00:08:48 +0000 Subject: [PATCH] Applying general CSS styles to nicks, not just colours --- client/src/views/channel.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/client/src/views/channel.js b/client/src/views/channel.js index f7a0655..4275358 100644 --- a/client/src/views/channel.js +++ b/client/src/views/channel.js @@ -157,7 +157,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ // Let nicks be clickable + colourise within messages parseMessageNicks: function(word, colourise) { - var members, member, colour = ''; + var members, member, style = ''; members = this.model.get('members'); if (!members) { @@ -170,14 +170,13 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ } if (colourise !== false) { - // Use the nick from the member object so the colour matches the letter casing - colour = this.getNickColour(member.get('nick')); - colour = 'color:' + colour; + // Use the nick from the member object so the style matches the letter casing + style = this.getNickStyles(member.get('nick')).asCssString(); } - return _.template('<%- nick %>', { + return _.template('<%- nick %>', { nick: word, - colour: colour + style: style }); }, @@ -243,15 +242,24 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ }, - // Get a colour from a nick (Method based on IRSSIs nickcolor.pl) - getNickColour: function(nick) { - var nick_int = 0, rgb; + // Sgnerate a css style for a nick + getNickStyles: function(nick) { + var ret, colour, nick_int = 0, rgb; + // Get a colour from a nick (Method based on IRSSIs nickcolor.pl) _.map(nick.split(''), function (i) { nick_int += i.charCodeAt(0); }); rgb = hsl2rgb(nick_int % 255, 70, 35); rgb = rgb[2] | (rgb[1] << 8) | (rgb[0] << 16); + colour = '#' + rgb.toString(16); - return '#' + rgb.toString(16); + ret = {color: colour}; + ret.asCssString = function() { + return _.reduce(this, function(result, item, key){ + return result + key + ':' + item + ';'; + }, ''); + }; + + return ret; }, @@ -312,8 +320,8 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ // Convert IRC formatting into HTML formatting msg.msg = formatIRCMsg(msg.msg); - // Add some colours to the nick - msg.nick_style = 'color:' + this.getNickColour(msg.nick) + ';'; + // Add some style to the nick + msg.nick_style = this.getNickStyles(msg.nick).asCssString(); // Generate a hex string from the nick to be used as a CSS class name nick_hex = ''; -- 2.25.1