Created
November 6, 2011 16:52
-
-
Save themasch/1343161 to your computer and use it in GitHub Desktop.
a tiny javascript "colorpicker". use it as a bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
document.cE = document.createElement; | |
var s = [], div = document.cE('div'); | |
var text = document.cE('input'); | |
var col = [0, 0, 0]; | |
var aE = "attachEvent", oc = "onchange", ok = "onkeyup"; | |
var uB = function() { | |
var c = text.value.match(/\w\w?/g), n, i; | |
for(i in c) { | |
s[i].value = col[i] = parseInt(c[i], 16) || 0; | |
} | |
div.style.backgroundColor = text.value; | |
} | |
var uC = function(c, val) { | |
col[c] = parseInt(val, 10); | |
text.value = '#'; | |
for(var i in col) { | |
n = col[i]; | |
var v = ((n < 16) ? '0' : '') + n.toString(16).toUpperCase(); | |
text.value += v; | |
} | |
div.style.backgroundColor = text.value; | |
} | |
if(!(text.attachEvent)) { aE = "addEventListener"; oc = "change"; ok = "keyup" } | |
text.size = 7; | |
text[aE](ok, uB); | |
div.appendChild(text); | |
div.appendChild(document.cE('br')); | |
with(div.style) { | |
position = 'fixed'; | |
padding = top = left = '5px'; | |
boxShadow = '0 0 5px black'; | |
backgroundColor = '#000'; | |
} | |
for(var c in ['r','g','b']) { | |
s[c] = document.cE('input'); | |
s[c].type = 'range'; | |
s[c].value = 0; | |
s[c].min = 0; | |
s[c].max = 255; | |
s[c].step = 1; | |
s[c][aE](oc, (function() { var col = c; return function() { uC(col, this.value); }})()); | |
div.appendChild(s[c]); | |
div.appendChild(document.cE('br')); | |
} | |
document.body.appendChild(div); | |
})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){document.cE=document.createElement;var s=[],div=document.cE("div"),text=document.cE("input"),col=[0,0,0],aE="attachEvent",oc="onchange",ok="onkeyup",uB=function(){var a=text.value.match(/\w\w?/g),b,c;for(c in a)s[c].value=col[c]=parseInt(a[c],16)||0;div.style.backgroundColor=text.value},uC=function(a,b){col[a]=parseInt(b,10),text.value="#";for(var c in col){n=col[c];var d=(n<16?"0":"")+n.toString(16).toUpperCase();text.value+=d}div.style.backgroundColor=text.value};text.attachEvent||(aE="addEventListener",oc="change",ok="keyup"),text.size=7,text[aE](ok,uB),div.appendChild(text),div.appendChild(document.cE("br"));with(div.style)position="fixed",padding=top=left="5px",boxShadow="0 0 5px black",backgroundColor="#000";for(var c in["r","g","b"])s[c]=document.cE("input"),s[c].type="range",s[c].value=0,s[c].min=0,s[c].max=255,s[c].step=1,s[c][aE](oc,function(){var a=c;return function(){uC(a,this.value)}}()),div.appendChild(s[c]),div.appendChild(document.cE("br"));document.body.appendChild(div)})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ugg
(function() {document.cE = document.createElement;
var s = [], div = document.cE('div');
var text = document.cE('input');
var col = [0, 0, 0];
var aE = "attachEvent", oc = "onchange", ok = "onkeyup";
var uB = function() {
var c = text.value.match(/\w\w?/g), n, i;
for(i in c) {
s[i].value = col[i] = parseInt(c[i], 16) || 0;
}
div.style.backgroundColor = text.value;
}
var uC = function(c, val) {
col[c] = parseInt(val, 10);
text.value = '#';
for(var i in col) {
n = col[i];
var v = ((n < 16) ? '0' : '') + n.toString(16).toUpperCase();
text.value += v;
}
div.style.backgroundColor = text.value;
}
if(!(text.attachEvent)) { aE = "addEventListener"; oc = "change"; ok = "keyup" }
text.size = 7;
text[aE](ok, uB);
div.appendChild(text);
div.appendChild(document.cE('br'));
with(div.style) {
position = 'fixed';
padding = top = left = '5px';
boxShadow = '0 0 5px black';
backgroundColor = '#000';
}
for(var c in ['r','g','b']) {
s[c] = document.cE('input');
s[c].type = 'range';
s[c].value = 0;
s[c].min = 0;
s[c].max = 255;
s[c].step = 1;
s[c][aE](oc, (function() { var col = c; return function() { uC(col, this.value); }})());
div.appendChild(s[c]);
div.appendChild(document.cE('br'));
}
})()``