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: https://develop.svn.wordpress.org/trunk@20517 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2012-04-18 20:25:31 +00:00
parent 1792d8606b
commit 27c4bc7b41
2 changed files with 16 additions and 8 deletions

View File

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

View File

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