I spent a few hours last night looking for a good color picker for the new version of BodyMod.org and I found 2 really nice ones.
The first was a really fancy looking one from ColourMod.com.
It’s $5 to use, and I figured it was worth it, but first I wanted to try it out on my site to make sure that it’ll work with all my styles and JS code I got goin on. I figured support at 6am on a sunday wasn’t too high, so I just borrowed the code from their site and tweaked it to get it to run on my server. End result: doesn’t work with my site. Crap. On to the next one.
The second one I found was free (i love that word), and open source (even better!). This was done by ColorJack.com.
This one worked right out of the box. Beautiful script, and really small too! A lot smaller and easier to implement than colourmod.
My only gripe (if you wanna call it that), is that it wasn’t made to handle color picking for more than one area on the same page. So, let the hacking begin!
Well into Sunday morning (now 9am), I couldn’t get it to work right…ARG! I sleep on it, and when I wake up I get an idea. BAM! Works like a charm =). So if you need multiple color pickers on the same page, this one will do it for ya! Here’s the code I modified to get it to work:
Plugin.js
function toggle(v,id) { $S(v).display=($S(v).display=='none'?'block':'none');$('divUpdateID').innerHTML=id; }
Add this to the HTML Code put at the top of the page:
Modify the calling javascript to this:
function mkColor(v){$S($('divUpdateID').innerHTML).background="#"+v;$($('divUpdateID').innerHTML).value=v;}loadSV(); updateH('F1FFCC');
Then update the onClick call from the launcher:
Launch
In the example above, the color picker will update the textbox with the id of colorArea. It will put the selected color as the background and the hex value in the text box as the value.
If you want to launch more, you just change the id of the text box you want to update in the toggle function. So you can change colorArea to colorArea2 for the second box.
I also really like his use of shortening the whole ‘document.getElementById(’blah’)’ down to just $(’blah’). I’ll be using that one from now on!
function $(v) { return(document.getElementById(v)); }
function $S(v) { return($(v).style); }
So smooth…
Tags: CSS, Javascript / AJAX, Web Design, Web Sites by .: Adam
No Comments »