From e11cc3ec4fb65db545e8e50db35420550b3e24fe Mon Sep 17 00:00:00 2001 From: koopersmith Date: Mon, 16 Apr 2012 23:07:23 +0000 Subject: [PATCH] Theme Customizer: Integrate with browser history. Use window.history by default, with window.onhashchange as a fallback. fixes #20337, see #19910. git-svn-id: http://svn.automattic.com/wordpress/trunk@20488 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/customize-loader.dev.js | 58 ++++++++++++++++++++++++-- wp-includes/theme.php | 1 + 2 files changed, 55 insertions(+), 4 deletions(-) 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 = $( '