diff --git a/wp-includes/js/customize-loader.dev.js b/wp-includes/js/customize-loader.dev.js index 1e1032765..c2e92a639 100644 --- a/wp-includes/js/customize-loader.dev.js +++ b/wp-includes/js/customize-loader.dev.js @@ -6,9 +6,15 @@ if ( typeof wp === 'undefined' ) Loader; Loader = { + supports: { + history: !! ( window.history && history.pushState ), + hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7) + }, + initialize: function() { - this.body = $( document.body ).addClass('customize-support'); - this.element = $( '
' ).appendTo( this.body ); + this.body = $( document.body ).addClass('customize-support'); + this.window = $( window ); + this.element = $( '
' ).appendTo( this.body ); $('#wpbody').on( 'click', '.load-customize', function( event ) { event.preventDefault(); @@ -16,8 +22,35 @@ if ( typeof wp === 'undefined' ) // Load the theme. Loader.open( $(this).attr('href') ); }); + + // Add navigation listeners. + if ( this.supports.history ) + this.window.on( 'popstate', Loader.popstate ); + + if ( this.supports.hashchange ) + this.window.on( 'hashchange', Loader.hashchange ); + }, + popstate: function( e ) { + var state = e.originalEvent.state; + if ( state && state.customize ) + Loader.open( state.customize ); + else if ( Loader.active ) + Loader.close(); + }, + hashchange: function( e ) { + var hash = window.location.toString().split('#')[1]; + + if ( hash && 0 === hash.indexOf( 'customize=on' ) ) + Loader.open( wpCustomizeLoaderL10n.url + '?' + hash ); + + if ( ! hash ) + Loader.close(); }, open: function( src ) { + if ( this.active ) + return; + this.active = true; + this.iframe = $( '