X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5964d2279dc52bdfe105f9bfa17e04337d47a3fa..refs/tags/wordpress-4.1-scripts:/wp-includes/js/customize-preview.js diff --git a/wp-includes/js/customize-preview.js b/wp-includes/js/customize-preview.js index caefe653..82f7bb86 100644 --- a/wp-includes/js/customize-preview.js +++ b/wp-includes/js/customize-preview.js @@ -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,26 @@ 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 ) { @@ -108,11 +126,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 +154,8 @@ this.bind( update ); }); }); + + api.trigger( 'preview-ready' ); }); })( wp, jQuery );