From 27c4bc7b41d4753b24501d9817288b399d9a457c Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Wed, 18 Apr 2012 20:25:31 +0000 Subject: [PATCH] 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 --- wp-includes/js/customize-base.dev.js | 19 +++++++++++++------ wp-includes/js/customize-loader.dev.js | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/wp-includes/js/customize-base.dev.js b/wp-includes/js/customize-base.dev.js index f10003a1cc..67756d3035 100644 --- a/wp-includes/js/customize-base.dev.js +++ b/wp-includes/js/customize-base.dev.js @@ -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 ) { diff --git a/wp-includes/js/customize-loader.dev.js b/wp-includes/js/customize-loader.dev.js index c2e92a6396..759e255c56 100644 --- a/wp-includes/js/customize-loader.dev.js +++ b/wp-includes/js/customize-loader.dev.js @@ -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' );