web/wp-admin/js/custom-background.dev.js
changeset 194 32102edaa81b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
       
     1 var farbtastic, pickColor;
       
     2 
       
     3 (function($) {
       
     4 
       
     5 	var defaultColor = '';
       
     6 
       
     7 	pickColor = function(color) {
       
     8 		farbtastic.setColor(color);
       
     9 		$('#background-color').val(color);
       
    10 		$('#custom-background-image').css('background-color', color);
       
    11 		// If we have a default color, and they match, then we need to hide the 'Default' link.
       
    12 		// Otherwise, we hide the 'Clear' link when it is empty.
       
    13 		if ( ( defaultColor && color === defaultColor ) || ( ! defaultColor && ( '' === color || '#' === color ) ) )
       
    14 			$('#clearcolor').hide();
       
    15 		else
       
    16 			$('#clearcolor').show();
       
    17 	}
       
    18 
       
    19 	$(document).ready(function() {
       
    20 
       
    21 		defaultColor = $('#defaultcolor').val();
       
    22 
       
    23 		$('#pickcolor').click(function() {
       
    24 			$('#colorPickerDiv').show();
       
    25 			return false;
       
    26 		});
       
    27 
       
    28 		$('#clearcolor a').click( function(e) {
       
    29 			pickColor( defaultColor );
       
    30 			e.preventDefault();
       
    31 		});
       
    32 
       
    33 		$('#background-color').keyup(function() {
       
    34 			var _hex = $('#background-color').val(), hex = _hex;
       
    35 			if ( hex.charAt(0) != '#' )
       
    36 				hex = '#' + hex;
       
    37 			hex = hex.replace(/[^#a-fA-F0-9]+/, '');
       
    38 			if ( hex != _hex )
       
    39 				$('#background-color').val(hex);
       
    40 			if ( hex.length == 4 || hex.length == 7 )
       
    41 				pickColor( hex );
       
    42 		});
       
    43 
       
    44 		$('input[name="background-position-x"]').change(function() {
       
    45 			$('#custom-background-image').css('background-position', $(this).val() + ' top');
       
    46 		});
       
    47 
       
    48 		$('input[name="background-repeat"]').change(function() {
       
    49 			$('#custom-background-image').css('background-repeat', $(this).val());
       
    50 		});
       
    51 
       
    52 		farbtastic = $.farbtastic('#colorPickerDiv', function(color) {
       
    53 			pickColor(color);
       
    54 		});
       
    55 		pickColor($('#background-color').val());
       
    56 
       
    57 		$(document).mousedown(function(){
       
    58 			$('#colorPickerDiv').each(function(){
       
    59 				var display = $(this).css('display');
       
    60 				if ( display == 'block' )
       
    61 					$(this).fadeOut(2);
       
    62 			});
       
    63 		});
       
    64 	});
       
    65 
       
    66 })(jQuery);