var api = wp.customize,
debounce;
+ /**
+ * Returns a debounced version of the function.
+ *
+ * @todo Require Underscore.js for this file and retire this.
+ */
debounce = function( fn, delay, context ) {
var timeout;
return function() {
};
};
+ /**
+ * @constructor
+ * @augments wp.customize.Messenger
+ * @augments wp.customize.Class
+ * @mixes wp.customize.Events
+ */
api.Preview = api.Messenger.extend({
/**
* Requires params:
if ( ! api.settings )
return;
- var preview, bg;
+ var bg;
- preview = new api.Preview({
+ api.preview = new api.Preview({
url: window.location.href,
channel: api.settings.channel
});
- preview.bind( 'settings', function( values ) {
+ api.preview.bind( 'settings', function( values ) {
$.each( values, function( id, value ) {
if ( api.has( id ) )
api( id ).set( value );
});
});
- preview.trigger( 'settings', api.settings.values );
+ api.preview.trigger( 'settings', api.settings.values );
- preview.bind( 'setting', function( args ) {
+ api.preview.bind( 'setting', function( args ) {
var value;
args = args.slice();
value.set.apply( value, args );
});
- preview.bind( 'sync', function( events ) {
+ api.preview.bind( 'sync', function( events ) {
$.each( events, function( event, args ) {
- preview.trigger( event, args );
+ api.preview.trigger( event, args );
});
- preview.send( 'synced' );
+ api.preview.send( 'synced' );
});
- preview.bind( 'active', function() {
- if ( api.settings.nonce )
- preview.send( 'nonce', api.settings.nonce );
- });
+ api.preview.bind( 'active', function() {
+ if ( api.settings.nonce ) {
+ api.preview.send( 'nonce', api.settings.nonce );
+ }
- preview.send( 'ready' );
+ api.preview.send( 'documentTitle', document.title );
+ });
+
+ api.preview.send( 'ready', {
+ activePanels: api.settings.activePanels,
+ activeSections: api.settings.activeSections,
+ activeControls: api.settings.activeControls
+ } );
+
+ // Display a loading indicator when preview is reloading, and remove on failure.
+ api.preview.bind( 'loading-initiated', function () {
+ $( 'body' ).addClass( 'wp-customizer-unloading' );
+ $( 'html' ).prop( 'title', api.settings.l10n.loading );
+ });
+ api.preview.bind( 'loading-failed', function () {
+ $( 'body' ).removeClass( 'wp-customizer-unloading' );
+ $( 'html' ).prop( 'title', '' );
+ });
/* Custom Backgrounds */
bg = $.map(['color', 'image', 'position_x', 'repeat', 'attachment'], function( prop ) {
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 = '';
this.bind( update );
});
});
+
+ api.trigger( 'preview-ready' );
});
})( wp, jQuery );