Digitalraindrops

Color Picker

Dec 28th, 2010
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var farbtastic;
  2.  
  3. function pickColor(color) {
  4.     farbtastic.setColor(color);
  5.     jQuery('#background-color').val(color);
  6. }
  7.  
  8. jQuery(document).ready(function() {
  9.     jQuery('#pickcolor').click(function() {
  10.         jQuery('#colorPickerDiv').show();
  11.         return false;
  12.     });
  13.  
  14.     jQuery('#background-color').keyup(function() {
  15.         var _hex = jQuery('#background-color').val(), hex = _hex;
  16.         if ( hex.charAt(0) != '#' )
  17.             hex = '#' + hex;
  18.         hex = hex.replace(/[^#a-fA-F0-9]+/, '');
  19.         if ( hex != _hex )
  20.             jQuery('#background-color').val(hex);
  21.         if ( hex.length == 4 || hex.length == 7 )
  22.             pickColor( hex );
  23.     });
  24.  
  25.     farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) {
  26.         pickColor(color);
  27.     });
  28.     pickColor(jQuery('#background-color').val());
  29.  
  30.     jQuery(document).mousedown(function(){
  31.         jQuery('#colorPickerDiv').each(function(){
  32.             var display = jQuery(this).css('display');
  33.             if ( display == 'block' )
  34.                 jQuery(this).fadeOut(2);
  35.         });
  36.     });
  37. });
Advertisement
Add Comment
Please, Sign In to add comment