diff --git a/wp-includes/js/customize-base.dev.js b/wp-includes/js/customize-base.dev.js index bac92c96b8..84e641f95b 100644 --- a/wp-includes/js/customize-base.dev.js +++ b/wp-includes/js/customize-base.dev.js @@ -469,14 +469,14 @@ if ( typeof wp === 'undefined' ) message = JSON.parse( event.data ); - if ( message && message.id && message.data && this.topics[ message.id ] ) + if ( message && message.id && typeof message.data !== 'undefined' && this.topics[ message.id ] ) this.topics[ message.id ].fireWith( this, [ message.data ]); }, send: function( id, data ) { var message; - data = data || {}; + data = typeof data === 'undefined' ? {} : data; if ( ! this.url() ) return; diff --git a/wp-includes/js/customize-controls.dev.js b/wp-includes/js/customize-controls.dev.js index 15b532b92b..626e9460fc 100644 --- a/wp-includes/js/customize-controls.dev.js +++ b/wp-includes/js/customize-controls.dev.js @@ -311,6 +311,11 @@ api.Messenger.prototype.initialize.call( this, params.url ); + this.scroll = 0; + this.bind( 'scroll', function( distance ) { + this.scroll = distance; + }); + // We're dynamically generating the iframe, so the origin is set // to the current window's location, not the url's. this.origin.unlink( this.url ).set( window.location.href ); @@ -335,10 +340,12 @@ loaded: function() { if ( this.iframe ) this.iframe.remove(); + this.iframe = this.loading; delete this.loading; this.targetWindow( this.iframe[0].contentWindow ); + this.send( 'scroll', this.scroll ); }, query: function() {}, refresh: function() { diff --git a/wp-includes/js/customize-preview.dev.js b/wp-includes/js/customize-preview.dev.js index 6aefdd1c89..5aee863424 100644 --- a/wp-includes/js/customize-preview.dev.js +++ b/wp-includes/js/customize-preview.dev.js @@ -1,5 +1,21 @@ (function( exports, $ ){ - var api = wp.customize; + 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({ /** @@ -27,6 +43,15 @@ 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 ); + }); } });