diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 02a230d3af..a2b9489240 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -1929,25 +1929,6 @@ this.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() }); - // This avoids SecurityErrors when setting a window object in x-origin iframe'd scenarios. - this.targetWindow.set = function( to ) { - var from = this._value; - - to = this._setter.apply( this, arguments ); - to = this.validate( to ); - - if ( null === to || from === to ) { - return this; - } - - this._value = to; - this._dirty = true; - - this.callbacks.fireWith( this, [ to, from ] ); - - return this; - }; - this.run( deferred ); }, diff --git a/src/wp-includes/js/customize-base.js b/src/wp-includes/js/customize-base.js index 5ffa924564..2e0ab19578 100644 --- a/src/wp-includes/js/customize-base.js +++ b/src/wp-includes/js/customize-base.js @@ -538,11 +538,34 @@ window.wp = window.wp || {}; this.add( 'channel', params.channel ); this.add( 'url', params.url || '' ); - this.add( 'targetWindow', params.targetWindow || defaultTarget ); this.add( 'origin', this.url() ).link( this.url ).setter( function( to ) { return to.replace( /([^:]+:\/\/[^\/]+).*/, '$1' ); }); + // first add with no value + this.add( 'targetWindow', null ); + // This avoids SecurityErrors when setting a window object in x-origin iframe'd scenarios. + this.targetWindow.set = function( to ) { + var from = this._value; + + to = this._setter.apply( this, arguments ); + to = this.validate( to ); + + if ( null === to || from === to ) { + return this; + } + + this._value = to; + this._dirty = true; + + this.callbacks.fireWith( this, [ to, from ] ); + + return this; + }; + // now set it + this.targetWindow( params.targetWindow || defaultTarget ); + + // Since we want jQuery to treat the receive function as unique // to this instance, we give the function a new guid. //