Small optimizations to color user ids

This commit is contained in:
Zixaphir 2013-08-15 19:53:06 -07:00
parent 963991ae84
commit 4a4dbae492
3 changed files with 15 additions and 21 deletions

View File

@ -8850,6 +8850,7 @@
if (g.VIEW === 'catalog' || !Conf['Color User IDs']) {
return;
}
this.ids = {};
return Post.prototype.callbacks.push({
name: 'Color User IDs',
cb: this.node
@ -8867,7 +8868,6 @@
}
return uid.style.cssText = IDColor.css(IDColor.ids[str] || IDColor.compute(str));
},
ids: {},
compute: function(str) {
var hash, rgb;
@ -8878,17 +8878,15 @@
return rgb;
},
css: function(rgb) {
return "background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: " + (rgb[3] ? "black;" : "white;") + " border-radius: 3px; padding: 0px 2px;";
return "background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: " + (rgb[3] ? "#000" : "#fff") + "; border-radius: 3px; padding: 0px 2px;";
},
hash: function(str) {
var i, j, msg;
var i, msg;
msg = 0;
i = 0;
j = str.length;
while (i < j) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
++i;
while (i < 8) {
msg = ((msg << 5) - msg) + str.charCodeAt(i++);
}
return msg;
}

View File

@ -8840,6 +8840,7 @@
if (g.VIEW === 'catalog' || !Conf['Color User IDs']) {
return;
}
this.ids = {};
return Post.prototype.callbacks.push({
name: 'Color User IDs',
cb: this.node
@ -8857,7 +8858,6 @@
}
return uid.style.cssText = IDColor.css(IDColor.ids[str] || IDColor.compute(str));
},
ids: {},
compute: function(str) {
var hash, rgb;
@ -8868,17 +8868,15 @@
return rgb;
},
css: function(rgb) {
return "background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: " + (rgb[3] ? "black;" : "white;") + " border-radius: 3px; padding: 0px 2px;";
return "background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: " + (rgb[3] ? "#000" : "#fff") + "; border-radius: 3px; padding: 0px 2px;";
},
hash: function(str) {
var i, j, msg;
var i, msg;
msg = 0;
i = 0;
j = str.length;
while (i < j) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
++i;
while (i < 8) {
msg = ((msg << 5) - msg) + str.charCodeAt(i++);
}
return msg;
}

View File

@ -2,6 +2,8 @@ IDColor =
init: ->
return if g.VIEW is 'catalog' or !Conf['Color User IDs']
@ids = {}
Post::callbacks.push
name: 'Color User IDs'
cb: @node
@ -12,8 +14,6 @@ IDColor =
return unless uid and uid.nodeName is 'SPAN'
uid.style.cssText = IDColor.css IDColor.ids[str] or IDColor.compute str
ids: {}
compute: (str) ->
hash = IDColor.hash str
@ -28,13 +28,11 @@ IDColor =
@ids[str] = rgb
rgb
css: (rgb) -> "background-color: rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]}); color: #{if rgb[3] then "black;" else "white;"} border-radius: 3px; padding: 0px 2px;"
css: (rgb) -> "background-color: rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]}); color: #{if rgb[3] then "#000" else "#fff"}; border-radius: 3px; padding: 0px 2px;"
hash: (str) ->
msg = 0
i = 0
j = str.length
while i < j
msg = ((msg << 5) - msg) + str.charCodeAt i
++i
while i < 8
msg = ((msg << 5) - msg) + str.charCodeAt i++
msg