<canvas id="wheel" width="186" height="186" onmousemove="mousemove(event);" onmouseout="mouseexit(event);"></canvas>
<!-- front -->
<div id="front">
- <input type="text" id="hexinput" size="6" onblur="hexwatcher()" value="3C3C3C" />
+ <input type="text" id="hexinput" size="6" onblur="OnHexChanged()" value="3C3C3C" />
- <input type="text" id="redinput" size="3" onblur="rgbwatcher('red')" value="60" />
- <input type="text" id="greeninput" size="3" onblur="rgbwatcher('green')" value="60" />
- <input type="text" id="blueinput" size="3" onblur="rgbwatcher('blue')" value="60" />
+ <input type="text" id="redinput" size="3" onblur="OnRGBChange('red')" value="60" />
+ <input type="text" id="greeninput" size="3" onblur="OnRGBChange('green')" value="60" />
+ <input type="text" id="blueinput" size="3" onblur="OnRGBChange('blue')" value="60" />
<div class="flip" id="fliprollie"></div>
<div class="flip" id="flip" onclick="show_back(event);" onmouseover="enterflip(event);" onmouseout="exitflip(event)";></div>
// ###################################################################
// watches the three RGB fields to make sure they don't go over the limites
-function rgbwatcher(color)
+function OnRGBChange(color)
{
- field = document.getElementById(color + "input");
+ var field = document.getElementById(color + "input");
- // handle RGB triads
- if (triad = field.value.match(/(rgb)?\(?([0-9]{1,3}),\s?([0-9]{1,3}),\s?([0-9]{1,3})\)?/))
- {
+ // Handle RGB triads that are pased into a single box.
+ if (triad = field.value.match(/(rgb)?\(?([0-9]{1,3}),\s?([0-9]{1,3}),\s?([0-9]{1,3})\)?/)) {
document.getElementById("redinput").value = triad[2];
document.getElementById("greeninput").value = triad[3];
document.getElementById("blueinput").value = triad[4];
newval = Math.floor(newval);
// make sure we don't go over 255
- if (newval > 255)
- {
+ if (newval > 255) {
newval = 255;
- }
- else if (newval < 0)
- {
+ } else if (newval < 0) {
newval = 0;
}
colors_[color] = newval;
// set hex
- update_hex();
+ UpdateHex();
// redraw the swatch
Draw();
// ###################################################################
// watches the hex field for updates
-function hexwatcher()
+function OnHexChanged()
{
- field = document.getElementById("hexinput");
+ var field = document.getElementById("hexinput");
// sanitize the hex
var newval = field.value.replace(/[^0-9a-f]*/gi, "");
// get the length
var length = newval.length;
- // make sure we're always 6
- if (length > 6)
- {
+ // Trim the value.
+ if (length > 6) {
newval = newval.substr(0, 6);
- }
- else if (length == 3)
- {
- newval = newval.substr(0, 1) + newval.substr(0, 1) + newval.substr(1, 1) + newval.substr(1, 1) + newval.substr(2, 1) + newval.substr(2, 1);
- }
- else if (length < 6)
- {
- for (var i = length; i <= 6; i++)
- {
+ } else if (length == 3) {
+ newval = newval.substr(0, 1) + newval.substr(0, 1) +
+ newval.substr(1, 1) + newval.substr(1, 1) +
+ newval.substr(2, 1) + newval.substr(2, 1);
+ } else if (length < 6) {
+ for (var i = length; i <= 6; i++) {
newval = "" + newval + "0";
}
}
colors_.hex = newval;
// set RGB
- update_rgb();
+ UpdateRGB();
// redraw the swatch
Draw();
// ###################################################################
// update the hex value
-function update_hex()
+function UpdateHex()
{
- var hexstr = dec2hex(colors_.red) + dec2hex(colors_.green) + dec2hex(colors_.blue);
+ var hexstr = _Dec2Hex(colors_.red) + _Dec2Hex(colors_.green) + _Dec2Hex(colors_.blue);
colors_.hex = hexstr;
document.getElementById("hexinput").value = hexstr;
}
// ###################################################################
// update the RGB values
-function update_rgb()
+function UpdateRGB()
{
// regex match the bits
var bits = colors_.hex.match(/(..)(..)(..)/);
- colors_.red = hex2dec(bits[1]);
- colors_.green = hex2dec(bits[2]);
- colors_.blue = hex2dec(bits[3]);
+ colors_.red = _Hex2dDc(bits[1]);
+ colors_.green = _Hex2dDc(bits[2]);
+ colors_.blue = _Hex2dDc(bits[3]);
// construct the hex values
document.getElementById("redinput").value = colors_.red;
// ###################################################################
// convert a decimal to a hexidecimal
-function dec2hex(dec)
+function _Dec2Hex(dec)
{
var hexstr = "0123456789ABCDEF";
var low = dec % 16;
// ###################################################################
// converts a hexidecimal to a decimal
-function hex2dec(hex)
+function _Hex2dDc(hex)
{
return parseInt(hex, 16);
}