-var farbtastic;
-
-function pickColor(color) {
- farbtastic.setColor(color);
- jQuery('#background-color').val(color);
- jQuery('#custom-background-image').css('background-color', color);
-}
-
-jQuery(document).ready(function() {
- jQuery('#pickcolor').click(function() {
- jQuery('#colorPickerDiv').show();
- return false;
- });
+var farbtastic, pickColor;
- jQuery('#background-color').keyup(function() {
- var _hex = jQuery('#background-color').val(), hex = _hex;
- if ( hex[0] != '#' )
- hex = '#' + hex;
- hex = hex.replace(/[^#a-fA-F0-9]+/, '');
- if ( hex != _hex )
- jQuery('#background-color').val(hex);
- if ( hex.length == 4 || hex.length == 7 )
- pickColor( hex );
- });
+(function($) {
- jQuery('input[name="background-position-x"]').change(function() {
- jQuery('#custom-background-image').css('background-position', jQuery(this).val() + ' top');
- });
+ var defaultColor = '';
- jQuery('input[name="background-repeat"]').change(function() {
- jQuery('#custom-background-image').css('background-repeat', jQuery(this).val());
- });
+ pickColor = function(color) {
+ farbtastic.setColor(color);
+ $('#background-color').val(color);
+ $('#custom-background-image').css('background-color', color);
+ // If we have a default color, and they match, then we need to hide the 'Default' link.
+ // Otherwise, we hide the 'Clear' link when it is empty.
+ if ( ( defaultColor && color === defaultColor ) || ( ! defaultColor && ( '' === color || '#' === color ) ) )
+ $('#clearcolor').hide();
+ else
+ $('#clearcolor').show();
+ }
- farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) {
- pickColor(color);
- });
- pickColor(jQuery('#background-color').val());
+ $(document).ready(function() {
+
+ defaultColor = $('#defaultcolor').val();
+
+ $('#pickcolor').click(function() {
+ $('#colorPickerDiv').show();
+ return false;
+ });
+
+ $('#clearcolor a').click( function(e) {
+ pickColor( defaultColor );
+ e.preventDefault();
+ });
- jQuery(document).mousedown(function(){
- jQuery('#colorPickerDiv').each(function(){
- var display = jQuery(this).css('display');
- if ( display == 'block' )
- jQuery(this).fadeOut(2);
+ $('#background-color').keyup(function() {
+ var _hex = $('#background-color').val(), hex = _hex;
+ if ( hex.charAt(0) != '#' )
+ hex = '#' + hex;
+ hex = hex.replace(/[^#a-fA-F0-9]+/, '');
+ if ( hex != _hex )
+ $('#background-color').val(hex);
+ if ( hex.length == 4 || hex.length == 7 )
+ pickColor( hex );
+ });
+
+ $('input[name="background-position-x"]').change(function() {
+ $('#custom-background-image').css('background-position', $(this).val() + ' top');
+ });
+
+ $('input[name="background-repeat"]').change(function() {
+ $('#custom-background-image').css('background-repeat', $(this).val());
+ });
+
+ farbtastic = $.farbtastic('#colorPickerDiv', function(color) {
+ pickColor(color);
+ });
+ pickColor($('#background-color').val());
+
+ $(document).mousedown(function(){
+ $('#colorPickerDiv').each(function(){
+ var display = $(this).css('display');
+ if ( display == 'block' )
+ $(this).fadeOut(2);
+ });
});
});
-});
+
+})(jQuery);
\ No newline at end of file