--- a/wp/wp-includes/js/customize-loader.js Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-includes/js/customize-loader.js Mon Oct 14 17:39:30 2019 +0200
@@ -1,4 +1,10 @@
-/* global _wpCustomizeLoaderSettings, confirm */
+/* global _wpCustomizeLoaderSettings */
+/**
+ * Expose a public API that allows the customizer to be
+ * loaded on any page.
+ *
+ * @namespace wp
+ */
window.wp = window.wp || {};
(function( exports, $ ){
@@ -18,9 +24,12 @@
*
* e.g. <a class="load-customize" href="<?php echo wp_customize_url(); ?>">Open Customizer</a>
*
+ * @memberOf wp.customize
+ *
+ * @class
* @augments wp.customize.Events
*/
- Loader = $.extend( {}, api.Events, {
+ Loader = $.extend( {}, api.Events,/** @lends wp.customize.Loader.prototype */{
/**
* Setup the Loader; triggered on document#ready.
*/
@@ -111,7 +120,11 @@
this.active = true;
this.body.addClass('customize-loading');
- // Dirty state of Customizer in iframe
+ /*
+ * Track the dirtiness state (whether the drafted changes have been published)
+ * of the Customizer in the iframe. This is used to decide whether to display
+ * an AYS alert if the user tries to close the window before saving changes.
+ */
this.saved = new api.Value( true );
this.iframe = $( '<iframe />', { 'src': src, 'title': Loader.settings.l10n.mainIframeTitle } ).appendTo( this.element );
@@ -124,6 +137,19 @@
targetWindow: this.iframe[0].contentWindow
});
+ // Expose the changeset UUID on the parent window's URL so that the customized state can survive a refresh.
+ if ( history.replaceState ) {
+ this.messenger.bind( 'changeset-uuid', function( changesetUuid ) {
+ var urlParser = document.createElement( 'a' );
+ urlParser.href = location.href;
+ urlParser.search = $.param( _.extend(
+ api.utils.parseQueryString( urlParser.search.substr( 1 ) ),
+ { changeset_uuid: changesetUuid }
+ ) );
+ history.replaceState( { customize: urlParser.href }, '', urlParser.href );
+ } );
+ }
+
// Wait for the connection from the iframe before sending any postMessage events.
this.messenger.bind( 'ready', function() {
Loader.messenger.send( 'back' );
@@ -142,12 +168,6 @@
// Prompt AYS dialog when navigating away
$( window ).on( 'beforeunload', this.beforeunload );
- this.messenger.bind( 'activated', function( location ) {
- if ( location ) {
- window.location = location;
- }
- });
-
this.messenger.bind( 'saved', function () {
Loader.saved( true );
} );
@@ -181,37 +201,37 @@
* Callback after the Customizer has been opened.
*/
opened: function() {
- Loader.body.addClass( 'customize-active full-overlay-active' );
+ Loader.body.addClass( 'customize-active full-overlay-active' ).attr( 'aria-busy', 'true' );
},
/**
- * Close the Customizer overlay and return focus to the link that opened it.
+ * Close the Customizer overlay.
*/
close: function() {
- if ( ! this.active ) {
+ var self = this, onConfirmClose;
+ if ( ! self.active ) {
return;
}
- // Display AYS dialog if Customizer is dirty
- if ( ! this.saved() && ! confirm( Loader.settings.l10n.saveAlert ) ) {
- // Go forward since Customizer is exited by history.back()
- history.forward();
- return;
- }
-
- this.active = false;
+ onConfirmClose = function( confirmed ) {
+ if ( confirmed ) {
+ self.active = false;
+ self.trigger( 'close' );
- this.trigger( 'close' );
+ // Restore document title prior to opening the Live Preview
+ if ( self.originalDocumentTitle ) {
+ document.title = self.originalDocumentTitle;
+ }
+ } else {
- // Restore document title prior to opening the Live Preview
- if ( this.originalDocumentTitle ) {
- document.title = this.originalDocumentTitle;
- }
+ // Go forward since Customizer is exited by history.back()
+ history.forward();
+ }
+ self.messenger.unbind( 'confirmed-close', onConfirmClose );
+ };
+ self.messenger.bind( 'confirmed-close', onConfirmClose );
- // Return focus to link that was originally clicked.
- if ( this.link ) {
- this.link.focus();
- }
+ Loader.messenger.send( 'confirm-close' );
},
/**
@@ -225,13 +245,20 @@
Loader.saved = null;
Loader.body.removeClass( 'customize-active full-overlay-active' ).removeClass( 'customize-loading' );
$( window ).off( 'beforeunload', Loader.beforeunload );
+ /*
+ * Return focus to the link that opened the Customizer overlay after
+ * the body element visibility is restored.
+ */
+ if ( Loader.link ) {
+ Loader.link.focus();
+ }
},
/**
* Callback for the `load` event on the Customizer iframe.
*/
loaded: function() {
- Loader.body.removeClass('customize-loading');
+ Loader.body.removeClass( 'customize-loading' ).attr( 'aria-busy', 'false' );
},
/**