WordPress/wp-includes/js/customize-preview.dev.js
nacin 64b9b4f940 Do not specify background-image: none when a user removes a custom background
on a theme that has a default background image.

The onus is on the theme to omit the default background-image from style.css,
to allow the user to remove the default background image. Or, the theme can
specify a background-image for the body selector, as long as they then zero
it out for body.custom-background, like so:

{{{
body {
	background-image: url( ... );
}
body.custom-background {
	background-image: none;
}
}}}

This allows the theme to be compatible with the custom background feature
but also gracefully degrade if the background feature is disabled.

This is the same behavior as 3.3; setting a default image has simply been
made more prominent in 3.4. Reverts [21013], also parts of [21001].
see #20448 for change and discussion history.

see #20132, which will now be marked as invalid.

Also, per previous changes in #20448, the custom-background class should not
be shown when only a default color is in use.

fixes #20448.



git-svn-id: http://core.svn.wordpress.org/trunk@21054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2012-06-11 21:25:05 +00:00

142 lines
3.5 KiB
JavaScript

(function( exports, $ ){
var api = wp.customize,
debounce;
debounce = function( fn, delay, context ) {
var timeout;
return function() {
var args = arguments;
context = context || this;
clearTimeout( timeout );
timeout = setTimeout( function() {
timeout = null;
fn.apply( context, args );
}, delay );
};
};
api.Preview = api.Messenger.extend({
/**
* Requires params:
* - url - the URL of preview frame
*/
initialize: function( params, options ) {
var self = this;
api.Messenger.prototype.initialize.call( this, params, options );
this.body = $( document.body );
this.body.on( 'click.preview', 'a', function( event ) {
event.preventDefault();
self.send( 'scroll', 0 );
self.send( 'url', $(this).prop('href') );
});
// You cannot submit forms.
// @todo: Allow form submissions by mixing $_POST data with the customize setting $_POST data.
this.body.on( 'submit.preview', 'form', function( event ) {
event.preventDefault();
});
this.window = $( window );
this.window.on( 'scroll.preview', debounce( function() {
self.send( 'scroll', self.window.scrollTop() );
}, 200 ));
this.bind( 'scroll', function( distance ) {
self.window.scrollTop( distance );
});
}
});
$( function() {
api.settings = window._wpCustomizeSettings;
if ( ! api.settings )
return;
var preview, bg;
preview = new api.Preview({
url: window.location.href,
channel: api.settings.channel
});
preview.bind( 'settings', function( values ) {
$.each( values, function( id, value ) {
if ( api.has( id ) )
api( id ).set( value );
else
api.create( id, value );
});
});
preview.trigger( 'settings', api.settings.values );
preview.bind( 'setting', function( args ) {
var value;
args = args.slice();
if ( value = api( args.shift() ) )
value.set.apply( value, args );
});
preview.bind( 'sync', function( events ) {
$.each( events, function( event, args ) {
preview.trigger( event, args );
});
preview.send( 'synced' );
})
preview.send( 'ready' );
/* Custom Backgrounds */
bg = $.map(['color', 'image', 'position_x', 'repeat', 'attachment'], function( prop ) {
return 'background_' + prop;
});
api.when.apply( api, bg ).done( function( color, image, position_x, repeat, attachment ) {
var body = $(document.body),
head = $('head'),
style = $('#custom-background-css'),
update;
// If custom backgrounds are active and we can't find the
// default output, bail.
if ( body.hasClass('custom-background') && ! style.length )
return;
update = function() {
var css = '';
// The body will support custom backgrounds if either
// the color or image are set.
//
// See get_body_class() in /wp-includes/post-template.php
body.toggleClass( 'custom-background', !! ( color() || image() ) );
if ( color() )
css += 'background-color: ' + color() + ';';
if ( image() ) {
css += 'background-image: url("' + image() + '");';
css += 'background-position: top ' + position_x() + ';';
css += 'background-repeat: ' + repeat() + ';';
css += 'background-position: top ' + attachment() + ';';
}
// Refresh the stylesheet by removing and recreating it.
style.remove();
style = $('<style type="text/css" id="custom-background-css">body.custom-background { ' + css + ' }</style>').appendTo( head );
};
$.each( arguments, function() {
this.bind( update );
});
});
});
})( wp, jQuery );