diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 567702709f..99b28ff292 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -91,6 +91,8 @@ this.options.uploader = false; } + this.gridRouter = new media.view.MediaFrame.Manage.Router(); + // Call 'initialize' directly on the parent class. media.view.MediaFrame.prototype.initialize.apply( this, arguments ); @@ -109,21 +111,6 @@ } self.gridRouter.navigate( self.gridRouter.baseUrl( url ) ); }, 1000 ) ); - - // This is problematic. - _.delay( _.bind( this.createRouter, this ), 1000 ); - }, - - createRouter: function() { - this.gridRouter = new media.view.MediaFrame.Manage.Router(); - - // Verify pushState support and activate - if ( window.history && window.history.pushState ) { - Backbone.history.start({ - root: _wpMediaGridSettings.adminUrl, - pushState: true - }); - } }, /** @@ -210,6 +197,7 @@ scrollElement: document }); + this.browserView.on( 'ready', _.bind( this.bindDeferred, this ) ); this.errors = wp.Uploader.errors; this.errors.on( 'add remove reset', this.sidebarVisibility, this ); @@ -217,6 +205,20 @@ sidebarVisibility: function() { this.browserView.$( '.media-sidebar' ).toggle( this.errors.length ); + }, + + bindDeferred: function() { + this.browserView.dfd.done( _.bind( this.startHistory, this ) ); + }, + + startHistory: function() { + // Verify pushState support and activate + if ( window.history && window.history.pushState ) { + Backbone.history.start( { + root: _wpMediaGridSettings.adminUrl, + pushState: true + } ); + } } }); diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index fc35be075b..0eefa3db8f 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -5819,14 +5819,14 @@ if ( ! this.collection.length ) { this.toolbar.get( 'spinner' ).show(); - this.collection.more().done(function() { + this.dfd = this.collection.more().done( function() { if ( ! view.collection.length ) { noItemsView.$el.removeClass( 'hidden' ); } else { noItemsView.$el.addClass( 'hidden' ); } view.toolbar.get( 'spinner' ).hide(); - }); + } ); } else { noItemsView.$el.addClass( 'hidden' ); view.toolbar.get( 'spinner' ).hide();