]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/customize-preview.js
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-includes / js / customize-preview.js
index caefe653a9f4bd04e8581f5e79ec5acc8c7ca684..82f7bb862d965bce212d9899b51a7cf41206a1ea 100644 (file)
@@ -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() {
                };
        };
 
+       /**
+        * @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 );
@@ -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();
                                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
+               } );
 
                /* 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 );