1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-14 10:57:38 +01:00
vichan/js/id_colors.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

if (active_page == 'thread' || active_page == 'index') {
$(document).ready(function(){
$.hash = function(str) {
var i, j, msg = 0;
for (i = 0, j = str.length; i < j; ++i) {
msg = ((msg << 5) - msg) + str.charCodeAt(i);
}
return msg;
};
2014-09-27 20:56:05 +02:00
function stringToRGB(str){
var rgb, hash;
rgb = [];
hash = $.hash(str);
rgb[0] = (hash >> 24) & 0xFF;
rgb[1] = (hash >> 16) & 0xFF;
rgb[2] = (hash >> 8) & 0xFF;
return rgb;
}
2014-09-27 20:56:05 +02:00
function colorPostId(el) {
var rgb = IDToRGB($(el).text());
var ft = "#fff";
if ((rgb[0]*0.299 + rgb[1]*0.587 + rgb[2]*0.114) > 125)
ft = "#000";
2014-09-27 22:19:58 +02:00
$(el).css({
"background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
"padding": "0px 5px",
"border-radius": "8px",
"color": ft
});
2014-09-28 02:17:30 +02:00
$(el).mouseover(function() {
$(this).css('color', '#800000'); // how about a CSS :hover rule instead?
2014-09-28 02:17:30 +02:00
}).mouseout(function() {
$(this).css('color', ft);
2014-09-28 02:17:30 +02:00
});
}
$(".poster_id").each(function(k, v){
colorPostId(v);
});
$(document).on('new_post', function(e, post) {
$(post).find('.poster_id').each(function(k, v) {
colorPostId(v);
});
});
2014-09-27 20:56:05 +02:00
});
}