summaryrefslogtreecommitdiff
path: root/js/id_colors.js
diff options
context:
space:
mode:
author8chan <admin@8chan.co>2014-09-27 20:04:57 +0000
committerczaks <marcin@6irc.net>2014-10-05 17:48:07 +0200
commit035f8437abe8713678b7cb3e301446419028593b (patch)
tree8a7720290ac74b5ff7fe3cdea73817226f749706 /js/id_colors.js
parentc3ba4cc7efc3ec345634fa1a8f409008e2c535e8 (diff)
Call on ready, dont pollute window namespace with vars
Diffstat (limited to 'js/id_colors.js')
-rw-r--r--js/id_colors.js65
1 files changed, 34 insertions, 31 deletions
diff --git a/js/id_colors.js b/js/id_colors.js
index 6923dbec..7d531fde 100644
--- a/js/id_colors.js
+++ b/js/id_colors.js
@@ -1,34 +1,37 @@
-$.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;
-};
+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;
+ };
-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;
-}
+ 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;
+ }
-$(".poster_id").each(function(){
- var rgb = stringToRGB($(this).text());
-
- $(this).css({
- "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
- "padding": "3px 5px",
- "border-radius": "8px",
- "color": "white"
+ $(".poster_id").each(function(){
+ var rgb = stringToRGB($(this).text());
+
+ $(this).css({
+ "background-color": "rgb("+rgb[0]+", "+rgb[1]+", "+rgb[2]+")",
+ "padding": "3px 5px",
+ "border-radius": "8px",
+ "color": "white"
+ });
+ });
});
-});
-
+}