Theme Customizer: Use native postMessage for wp.customize.Messenger. see #19910.
* Removes use of jquery.postmessage.js * Fixes bug where Opera would attempt to use the hash transport and redirect to the dashboard. * Fixes bug where multiple postMessage connections could not coexist in a single frame. git-svn-id: http://svn.automattic.com/wordpress/trunk@20517 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
88752323cb
commit
9b5c6a917c
|
@ -431,22 +431,29 @@ if ( typeof wp === 'undefined' )
|
|||
$.extend( this, options || {} );
|
||||
|
||||
url = this.add( 'url', url );
|
||||
this.add( 'targetWindow', targetWindow || null );
|
||||
this.add( 'targetWindow', targetWindow || window.parent );
|
||||
this.add( 'origin', url() ).link( url ).setter( function( to ) {
|
||||
return to.replace( /([^:]+:\/\/[^\/]+).*/, '$1' );
|
||||
});
|
||||
|
||||
this.topics = {};
|
||||
|
||||
$.receiveMessage( $.proxy( this.receive, this ), this.origin() || null );
|
||||
this.receive = $.proxy( this.receive, this );
|
||||
$( window ).on( 'message', this.receive );
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
$( window ).off( 'message', this.receive );
|
||||
},
|
||||
|
||||
receive: function( event ) {
|
||||
var message;
|
||||
|
||||
// @todo: remove, this is done in the postMessage plugin.
|
||||
// if ( this.origin && event.origin !== this.origin )
|
||||
// return;
|
||||
event = event.originalEvent;
|
||||
|
||||
// Check to make sure the origin is valid.
|
||||
if ( this.origin() && event.origin !== this.origin() )
|
||||
return;
|
||||
|
||||
message = JSON.parse( event.data );
|
||||
|
||||
|
@ -463,7 +470,7 @@ if ( typeof wp === 'undefined' )
|
|||
return;
|
||||
|
||||
message = JSON.stringify({ id: id, data: data });
|
||||
$.postMessage( message, this.url(), this.targetWindow() );
|
||||
this.targetWindow().postMessage( message, this.origin() );
|
||||
},
|
||||
|
||||
bind: function( id, callback ) {
|
||||
|
|
|
@ -43,7 +43,7 @@ if ( typeof wp === 'undefined' )
|
|||
if ( hash && 0 === hash.indexOf( 'customize=on' ) )
|
||||
Loader.open( wpCustomizeLoaderL10n.url + '?' + hash );
|
||||
|
||||
if ( ! hash )
|
||||
if ( ! hash && ! Loader.supports.history )
|
||||
Loader.close();
|
||||
},
|
||||
open: function( src ) {
|
||||
|
@ -78,7 +78,7 @@ if ( typeof wp === 'undefined' )
|
|||
// Ensure we don't call pushState if the user hit the forward button.
|
||||
if ( Loader.supports.history && window.location.href !== src )
|
||||
history.pushState( { customize: src }, '', src );
|
||||
else if ( Loader.supports.hashchange && hash )
|
||||
else if ( ! Loader.supports.history && Loader.supports.hashchange && hash )
|
||||
window.location.hash = hash;
|
||||
});
|
||||
},
|
||||
|
@ -89,6 +89,7 @@ if ( typeof wp === 'undefined' )
|
|||
|
||||
this.element.fadeOut( 200, function() {
|
||||
Loader.iframe.remove();
|
||||
Loader.messenger.destroy();
|
||||
Loader.iframe = null;
|
||||
Loader.messenger = null;
|
||||
Loader.body.removeClass( 'customize-active full-overlay-active' );
|
||||
|
|
Loading…
Reference in New Issue