X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/af50974463450c98503e763a7836a50e260461a9..refs/tags/wordpress-4.7.1:/wp-includes/js/customize-loader.js
diff --git a/wp-includes/js/customize-loader.js b/wp-includes/js/customize-loader.js
index 07f21966..1990d1a2 100644
--- a/wp-includes/js/customize-loader.js
+++ b/wp-includes/js/customize-loader.js
@@ -1,4 +1,8 @@
/* global _wpCustomizeLoaderSettings, confirm */
+/*
+ * Expose a public API that allows the customizer to be
+ * loaded on any page.
+ */
window.wp = window.wp || {};
(function( exports, $ ){
@@ -111,10 +115,14 @@ window.wp = window.wp || {};
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 = $( '', { src: src }).appendTo( this.element );
+ this.iframe = $( '', { 'src': src, 'title': Loader.settings.l10n.mainIframeTitle } ).appendTo( this.element );
this.iframe.one( 'load', this.loaded );
// Create a postMessage connection with the iframe.
@@ -124,6 +132,19 @@ window.wp = window.wp || {};
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 +163,6 @@ window.wp = window.wp || {};
// 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 );
} );
@@ -155,6 +170,10 @@ window.wp = window.wp || {};
Loader.saved( false );
} );
+ this.messenger.bind( 'title', function( newTitle ){
+ window.document.title = newTitle;
+ });
+
this.pushState( src );
this.trigger( 'open' );
@@ -177,11 +196,11 @@ window.wp = window.wp || {};
* 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 ) {
@@ -203,11 +222,6 @@ window.wp = window.wp || {};
if ( this.originalDocumentTitle ) {
document.title = this.originalDocumentTitle;
}
-
- // Return focus to link that was originally clicked.
- if ( this.link ) {
- this.link.focus();
- }
},
/**
@@ -221,13 +235,20 @@ window.wp = window.wp || {};
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' );
},
/**