From abc7c676a46ecb24c9184bbc08324b524fd9b379 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 31 Oct 2016 16:41:06 +0000 Subject: [PATCH] Customize: Ensure state query params persist in preview through calls to `history.pushState()` & `history.replaceState()`. Allow history to be manipulated before DOM ready by sourcing state params from the current URL instead of from the `wp.customize.settings` object, since they will be the same anyway. This fixes a JS error since `wp.customize.settings` is not defined before DOM ready. Amends [38810]. See #30937. Fixes #38592. git-svn-id: https://develop.svn.wordpress.org/trunk@39060 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/customize-preview.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js index 94173ef0bc..484ccf4acc 100644 --- a/src/wp-includes/js/customize-preview.js +++ b/src/wp-includes/js/customize-preview.js @@ -29,20 +29,21 @@ * @returns {string} URL with customized state. */ injectUrlWithState = function( url ) { - var urlParser, queryParams; + var urlParser, oldQueryParams, newQueryParams; urlParser = document.createElement( 'a' ); urlParser.href = url; - queryParams = api.utils.parseQueryString( urlParser.search.substr( 1 ) ); + oldQueryParams = api.utils.parseQueryString( location.search.substr( 1 ) ); + newQueryParams = api.utils.parseQueryString( urlParser.search.substr( 1 ) ); - queryParams.customize_changeset_uuid = api.settings.changeset.uuid; - if ( ! api.settings.theme.active ) { - queryParams.customize_theme = api.settings.theme.stylesheet; + newQueryParams.customize_changeset_uuid = oldQueryParams.customize_changeset_uuid; + if ( oldQueryParams.customize_theme ) { + newQueryParams.customize_theme = oldQueryParams.customize_theme; } - if ( api.settings.theme.channel ) { - queryParams.customize_messenger_channel = api.settings.channel; + if ( oldQueryParams.customize_messenger_channel ) { + newQueryParams.customize_messenger_channel = oldQueryParams.customize_messenger_channel; } - urlParser.search = $.param( queryParams ); - return url; + urlParser.search = $.param( newQueryParams ); + return urlParser.href; }; history.replaceState = ( function( nativeReplaceState ) {