wp/wp-includes/js/customize-preview.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
--- a/wp/wp-includes/js/customize-preview.js	Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-includes/js/customize-preview.js	Tue Jun 09 03:35:32 2015 +0200
@@ -2,6 +2,11 @@
 	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() {
@@ -17,6 +22,12 @@
 		};
 	};
 
+	/**
+	 * @constructor
+	 * @augments wp.customize.Messenger
+	 * @augments wp.customize.Class
+	 * @mixes wp.customize.Events
+	 */
 	api.Preview = api.Messenger.extend({
 		/**
 		 * Requires params:
@@ -56,14 +67,14 @@
 		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 );
@@ -72,9 +83,9 @@
 			});
 		});
 
-		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();
@@ -83,19 +94,36 @@
 				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' );
+		});
+
+		api.preview.bind( 'active', function() {
+			if ( api.settings.nonce ) {
+				api.preview.send( 'nonce', api.settings.nonce );
+			}
+
+			api.preview.send( 'documentTitle', document.title );
 		});
 
-	 	preview.bind( 'active', function() {
-	 		if ( api.settings.nonce )
-	 			preview.send( 'nonce', api.settings.nonce );
-	 	});
+		api.preview.send( 'ready', {
+			activePanels: api.settings.activePanels,
+			activeSections: api.settings.activeSections,
+			activeControls: api.settings.activeControls
+		} );
 
-		preview.send( 'ready' );
+		// 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 ) {
@@ -108,11 +136,6 @@
 				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 = '';
 
@@ -141,6 +164,8 @@
 				this.bind( update );
 			});
 		});
+
+		api.trigger( 'preview-ready' );
 	});
 
 })( wp, jQuery );