From e19f1c475c3fcb0591b7a7bae56683e368b789b4 Mon Sep 17 00:00:00 2001 From: Veno Server Date: Tue, 18 Aug 2009 02:16:14 -0500 Subject: [PATCH] Added in methods to generate the hex code when a user clicks on one of the outputted boxes --- index.php | 5 +++++ js/franz.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 2927dbc..6205adb 100644 --- a/index.php +++ b/index.php @@ -75,6 +75,11 @@ return false; }); + $(".color_boxd").live("click", function() { + // It's 4AM, and I'm tired. I'm not building a damn regular expression, so yeah, we'll multiple .replace() ;P + alert("This hex color: " + franz.RGBtoHex($(this)[0].style.backgroundColor.replace(")", "").replace("rgb(", "").replace(" ", "").split(","))); + }); + }); diff --git a/js/franz.js b/js/franz.js index 38702e8..e5c2439 100644 --- a/js/franz.js +++ b/js/franz.js @@ -232,6 +232,18 @@ var franz = { } } } - } + }, + RGBtoHex: function(rgb) { + var hex = []; + + if(rgb[3] == 0) return 'transparent'; + + for(var i = 0; i < 3; i++) { + var bit = (rgb[i] - 0).toString(16); + hex.push(bit.length == 1 ? ('0' + bit) : bit); + } + + return '#' + hex.join(''); + } }