From 5f936ab3ddb6e119e30ac6b398c9f9c11f92edd1 Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Wed, 12 Mar 2014 21:06:30 +0000 Subject: [PATCH] Smooth out some display and race condition issues with the media modal loading spinner. props kadamwhite, gcorne. see #24859. git-svn-id: https://develop.svn.wordpress.org/trunk@27516 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index cc481268b4..09c1ec678c 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -5205,13 +5205,22 @@ }, scroll: function() { + var view = this, + toolbar; + // @todo: is this still necessary? if ( ! this.$el.is(':visible') ) { return; } if ( this.collection.hasMore() && this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) { - this.collection.more().done( this.scroll ); + toolbar = this.views.parent.toolbar; + toolbar.get('spinner').show(); + + this.collection.more().done(function() { + view.scroll(); + toolbar.get('spinner').hide(); + }); } } }, { @@ -5451,16 +5460,6 @@ this.collection.on( 'add remove reset', this.updateContent, this ); }, - toggleSpinner: function( state ) { - if ( state ) { - this.spinnerTimeout = _.delay(function( view ) { - view.toolbar.get( 'spinner' ).show(); - }, 600, this ); - } else { - this.toolbar.get( 'spinner' ).hide(); - clearTimeout( this.spinnerTimeout ); - } - }, /** * @returns {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining */ @@ -5525,12 +5524,12 @@ } if ( ! this.collection.length ) { - this.toggleSpinner( true ); + this.toolbar.get( 'spinner' ).show(); this.collection.more().done(function() { if ( ! view.collection.length ) { view.createUploader(); } - view.toggleSpinner( false ); + view.toolbar.get( 'spinner' ).hide(); }); } }, @@ -6764,14 +6763,23 @@ media.view.Spinner = media.View.extend({ tagName: 'span', className: 'spinner', + spinnerTimeout: false, + delay: 400, show: function() { - this.$el.show(); + if ( ! this.spinnerTimeout ) { + this.spinnerTimeout = _.delay(function( $el ) { + $el.show(); + }, this.delay, this.$el ); + } + return this; }, hide: function() { this.$el.hide(); + this.spinnerTimeout = clearTimeout( this.spinnerTimeout ); + return this; } });