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.

Built from https://develop.svn.wordpress.org/trunk@39060


git-svn-id: http://core.svn.wordpress.org/trunk@39002 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2016-10-31 16:42:30 +00:00
parent 4356a28b52
commit 1c45ae618c
3 changed files with 12 additions and 11 deletions

View File

@ -29,20 +29,21 @@
* @returns {string} URL with customized state. * @returns {string} URL with customized state.
*/ */
injectUrlWithState = function( url ) { injectUrlWithState = function( url ) {
var urlParser, queryParams; var urlParser, oldQueryParams, newQueryParams;
urlParser = document.createElement( 'a' ); urlParser = document.createElement( 'a' );
urlParser.href = url; 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; newQueryParams.customize_changeset_uuid = oldQueryParams.customize_changeset_uuid;
if ( ! api.settings.theme.active ) { if ( oldQueryParams.customize_theme ) {
queryParams.customize_theme = api.settings.theme.stylesheet; newQueryParams.customize_theme = oldQueryParams.customize_theme;
} }
if ( api.settings.theme.channel ) { if ( oldQueryParams.customize_messenger_channel ) {
queryParams.customize_messenger_channel = api.settings.channel; newQueryParams.customize_messenger_channel = oldQueryParams.customize_messenger_channel;
} }
urlParser.search = $.param( queryParams ); urlParser.search = $.param( newQueryParams );
return url; return urlParser.href;
}; };
history.replaceState = ( function( nativeReplaceState ) { history.replaceState = ( function( nativeReplaceState ) {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-beta1-39059'; $wp_version = '4.7-beta1-39060';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.