Make WordPress Core

Changeset 39060


Ignore:
Timestamp:
10/31/2016 04:41:06 PM (8 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/customize-preview.js

    r38948 r39060  
    3030         */
    3131        injectUrlWithState = function( url ) {
    32             var urlParser, queryParams;
     32            var urlParser, oldQueryParams, newQueryParams;
    3333            urlParser = document.createElement( 'a' );
    3434            urlParser.href = url;
    35             queryParams = api.utils.parseQueryString( urlParser.search.substr( 1 ) );
    36 
    37             queryParams.customize_changeset_uuid = api.settings.changeset.uuid;
    38             if ( ! api.settings.theme.active ) {
    39                 queryParams.customize_theme = api.settings.theme.stylesheet;
    40             }
    41             if ( api.settings.theme.channel ) {
    42                 queryParams.customize_messenger_channel = api.settings.channel;
    43             }
    44             urlParser.search = $.param( queryParams );
    45             return url;
     35            oldQueryParams = api.utils.parseQueryString( location.search.substr( 1 ) );
     36            newQueryParams = api.utils.parseQueryString( urlParser.search.substr( 1 ) );
     37
     38            newQueryParams.customize_changeset_uuid = oldQueryParams.customize_changeset_uuid;
     39            if ( oldQueryParams.customize_theme ) {
     40                newQueryParams.customize_theme = oldQueryParams.customize_theme;
     41            }
     42            if ( oldQueryParams.customize_messenger_channel ) {
     43                newQueryParams.customize_messenger_channel = oldQueryParams.customize_messenger_channel;
     44            }
     45            urlParser.search = $.param( newQueryParams );
     46            return urlParser.href;
    4647        };
    4748
Note: See TracChangeset for help on using the changeset viewer.