+/**
+ * Convert HSL to RGB formatted colour
+ */
+function hsl2rgb(h, s, l) {
+ var m1, m2, hue;
+ var r, g, b
+ s /=100;
+ l /= 100;
+ if (s == 0)
+ r = g = b = (l * 255);
+ else {
+ function HueToRgb(m1, m2, hue) {
+ var v;
+ if (hue < 0)
+ hue += 1;
+ else if (hue > 1)
+ hue -= 1;
+
+ if (6 * hue < 1)
+ v = m1 + (m2 - m1) * hue * 6;
+ else if (2 * hue < 1)
+ v = m2;
+ else if (3 * hue < 2)
+ v = m1 + (m2 - m1) * (2/3 - hue) * 6;
+ else
+ v = m1;
+
+ return 255 * v;
+ }
+ if (l <= 0.5)
+ m2 = l * (s + 1);
+ else
+ m2 = l + s - l * s;
+ m1 = l * 2 - m2;
+ hue = h / 360;
+ r = HueToRgb(m1, m2, hue + 1/3);
+ g = HueToRgb(m1, m2, hue);
+ b = HueToRgb(m1, m2, hue - 1/3);
+ }
+ return [r,g,b];
+}
+
+
+
+
/**
* Formats a message. Adds bold, underline and colouring
},\r
newMsg: function (msg) {\r
// TODO: make sure that the message pane is scrolled to the bottom (Or do we? ~Darren)\r
- var re, line_msg, $this = this.$el;\r
+ var re, line_msg, $this = this.$el,\r
+ nick_colour_hex;\r
\r
// Escape any HTML that may be in here\r
msg.msg = $('<div />').text(msg.msg).html();\r
// Convert IRC formatting into HTML formatting\r
msg.msg = formatIRCMsg(msg.msg);\r
\r
+\r
+ // Add some colours to the nick (Method based on IRSSIs nickcolor.pl)\r
+ nick_colour_hex = (function (nick) {\r
+ var nick_int = 0, rgb;\r
+\r
+ nick.split('').map(function (i) { nick_int += i.charCodeAt(0); });\r
+ rgb = hsl2rgb(nick_int % 255, 70, 35);\r
+ rgb = rgb[2] | (rgb[1] << 8) | (rgb[0] << 16);\r
+\r
+ return '#' + rgb.toString(16);\r
+ })(msg.nick);\r
+\r
+ msg.nick_style = 'color:' + nick_colour_hex + ';';\r
+\r
// Build up and add the line\r
- line_msg = '<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';\r
+ line_msg = '<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick" style="<%= nick_style %>"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';\r
$this.append(_.template(line_msg, msg));\r
\r
this.scrollToBottom();\r