Theme Customizer: Bind the preview iframe load event when triggering refresh instead of when creating the iframe. see #19910.

The loaded event should only fire when we've actually triggered a refresh. If loaded is bound when the iframe is created, sometimes the blank iframe will fire a 'load' event before a refresh is triggered (this occurred with relative frequency in firefox). By binding the loaded event in the refresh function, we prevent this from occurring.

git-svn-id: http://svn.automattic.com/wordpress/trunk@20049 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith 2012-02-29 22:24:46 +00:00
parent b1621b75bb
commit cc784490da

View File

@ -13,6 +13,8 @@
initialize: function( params, options ) { initialize: function( params, options ) {
$.extend( this, options || {} ); $.extend( this, options || {} );
this.loaded = $.proxy( this.loaded, this );
this.loaderUuid = 0; this.loaderUuid = 0;
/* /*
@ -53,6 +55,7 @@
this.iframe = api.ensure( params.iframe ); this.iframe = api.ensure( params.iframe );
this.form = api.ensure( params.form ); this.form = api.ensure( params.form );
this.name = this.iframe.prop('name');
this.container = this.iframe.parent(); this.container = this.iframe.parent();
@ -83,28 +86,24 @@
}); });
}, },
loader: function() { loader: function() {
var self = this,
name;
if ( this.loading ) if ( this.loading )
return this.loading; return this.loading;
name = this.iframe.prop('name');
this.loading = $('<iframe />', { this.loading = $('<iframe />', {
name: name + '-loading-' + this.loaderUuid++ name: this.name + '-loading-' + this.loaderUuid++
}).appendTo( this.container ); }).appendTo( this.container );
this.loading.one( 'load', function() {
self.iframe.remove();
self.iframe = self.loading;
delete self.loading;
self.iframe.prop( 'name', name );
});
return this.loading; return this.loading;
}, },
loaded: function() {
this.iframe.remove();
this.iframe = this.loading;
delete this.loading;
this.iframe.prop( 'name', this.name );
},
refresh: function() { refresh: function() {
this.loader().one( 'load', this.loaded );
this.submit({ this.submit({
target: this.loader().prop('name'), target: this.loader().prop('name'),
action: this.url() action: this.url()