Theme Customizer: Maintain scrolled position when preview performs a full refresh. Allow wp.customize.Messenger to send/receive falsy values. see #19910.

git-svn-id: http://core.svn.wordpress.org/trunk@20745 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith 2012-05-09 00:23:05 +00:00
parent d5cf655ad3
commit c3ff01b334
3 changed files with 35 additions and 3 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -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 );
});
}
});