From 557ecd19c61ccb43e2ed986822d782f1b2500c70 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 10 Mar 2015 15:55:28 +0000 Subject: [PATCH] Customizer: Add loading indicators for the Customizer preview. props Fab1en, westonruter. fixes #31196. git-svn-id: https://develop.svn.wordpress.org/trunk@31697 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/themes.css | 11 ++++++++ src/wp-admin/js/customize-controls.js | 13 ++++++++-- .../class-wp-customize-manager.php | 25 ++++++++++++++++++- src/wp-includes/js/customize-preview.js | 10 ++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/css/themes.css b/src/wp-admin/css/themes.css index 541c8eb954..cbe34460df 100644 --- a/src/wp-admin/css/themes.css +++ b/src/wp-admin/css/themes.css @@ -1352,6 +1352,16 @@ body.full-overlay-active { height: 100%; } +#customize-preview.wp-full-overlay-main { + background: url(../images/spinner.gif) no-repeat center center; + -webkit-background-size: 20px 20px; + background-size: 20px 20px; +} + +#customize-preview.wp-full-overlay-main.iframe-ready { + background: none; +} + .wp-full-overlay-sidebar .wp-full-overlay-header { position: absolute; left: 0; @@ -1710,6 +1720,7 @@ body.full-overlay-active { background-size: 15px 123px; } + #customize-preview.wp-full-overlay-main, .customize-loading #customize-container, .theme-install-overlay .wp-full-overlay-main { background-image: url(../images/spinner-2x.gif); diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index b08f10f808..00c894edf7 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -1914,6 +1914,9 @@ this.bind( 'ready', this._ready ); this.bind( 'ready', function ( data ) { + + this.container.addClass( 'iframe-ready' ); + if ( ! data ) { return; } @@ -2217,6 +2220,9 @@ refresh: function() { var self = this; + // Display loading indicator + this.send( 'loading-initiated' ); + this.abort(); this.loading = new api.PreviewFrame({ @@ -2249,8 +2255,10 @@ }); this.loading.fail( function( reason, location ) { - if ( 'redirect' === reason && location ) + self.send( 'loading-failed' ); + if ( 'redirect' === reason && location ) { self.previewUrl( location ); + } if ( 'logged out' === reason ) { if ( self.preview ) { @@ -2261,8 +2269,9 @@ self.login().done( self.refresh ); } - if ( 'cheatin' === reason ) + if ( 'cheatin' === reason ) { self.cheatin(); + } }); }, diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index ffdb3f3dc9..de723c2401 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -501,6 +501,7 @@ final class WP_Customize_Manager { add_action( 'wp', array( $this, 'customize_preview_override_404_status' ) ); add_action( 'wp_head', array( $this, 'customize_preview_base' ) ); add_action( 'wp_head', array( $this, 'customize_preview_html5' ) ); + add_action( 'wp_head', array( $this, 'customize_preview_loading_style' ) ); add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 ); add_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 ); add_filter( 'wp_die_handler', array( $this, 'remove_preview_signature' ) ); @@ -543,7 +544,7 @@ final class WP_Customize_Manager { } /** - * Print a workaround to handle HTML5 tags in IE < 9 + * Print a workaround to handle HTML5 tags in IE < 9. * * @since 3.4.0 */ @@ -560,6 +561,25 @@ final class WP_Customize_Manager { array(), 'activeSections' => array(), 'activeControls' => array(), + 'l10n' => array( + 'loading' => __( 'Loading ...' ), + ), ); if ( 2 == $this->nonce_tick ) { diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js index 82f7bb862d..e58c8d6d44 100644 --- a/src/wp-includes/js/customize-preview.js +++ b/src/wp-includes/js/customize-preview.js @@ -115,6 +115,16 @@ activeControls: api.settings.activeControls } ); + // Display a loading indicator when preview is reloading, and remove on failure. + api.preview.bind( 'loading-initiated', function () { + $( 'body' ).addClass( 'wp-customizer-unloading' ); + $( 'html' ).prop( 'title', api.settings.l10n.loading ); + }); + api.preview.bind( 'loading-failed', function () { + $( 'body' ).removeClass( 'wp-customizer-unloading' ); + $( 'html' ).prop( 'title', '' ); + }); + /* Custom Backgrounds */ bg = $.map(['color', 'image', 'position_x', 'repeat', 'attachment'], function( prop ) { return 'background_' + prop;