Digitalraindrops

Background Color

Dec 28th, 2010
416
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.     jQuery('#custom-background-image').css('background-color', color);
  7. }
  8.  
  9. jQuery(document).ready(function() {
  10.     jQuery('#pickcolor').click(function() {
  11.         jQuery('#colorPickerDiv').show();
  12.         return false;
  13.     });
  14.  
  15.     jQuery('#background-color').keyup(function() {
  16.         var _hex = jQuery('#background-color').val(), hex = _hex;
  17.         if ( hex.charAt(0) != '#' )
  18.             hex = '#' + hex;
  19.         hex = hex.replace(/[^#a-fA-F0-9]+/, '');
  20.         if ( hex != _hex )
  21.             jQuery('#background-color').val(hex);
  22.         if ( hex.length == 4 || hex.length == 7 )
  23.             pickColor( hex );
  24.     });
  25.  
  26.     jQuery('input[name="background-position-x"]').change(function() {
  27.         jQuery('#custom-background-image').css('background-position', jQuery(this).val() + ' top');
  28.     });
  29.  
  30.     jQuery('input[name="background-repeat"]').change(function() {
  31.         jQuery('#custom-background-image').css('background-repeat', jQuery(this).val());
  32.     });
  33.  
  34.     farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) {
  35.         pickColor(color);
  36.     });
  37.     pickColor(jQuery('#background-color').val());
  38.  
  39.     jQuery(document).mousedown(function(){
  40.         jQuery('#colorPickerDiv').each(function(){
  41.             var display = jQuery(this).css('display');
  42.             if ( display == 'block' )
  43.                 jQuery(this).fadeOut(2);
  44.         });
  45.     });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment