From d45ed6a478b30acff54450f719d5e0528d8a05e9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 10 Jul 2014 18:24:23 +0000 Subject: [PATCH] Media Grid: make the router work when `?item=` is in the URL on page load. This is still a hack, needs to be event-driven. See #24716. git-svn-id: https://develop.svn.wordpress.org/trunk@29073 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 58e453a2f3..906e32b654 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -140,19 +140,6 @@ this.bindHandlers(); this.render(); - this.gridRouter = new media.view.Frame.Router( this ); - - // Set up the Backbone router after a brief delay - _.delay( function(){ - // Verify pushState support and activate - if ( window.history && window.history.pushState ) { - Backbone.history.start({ - root: mediaGridSettings.adminUrl, - pushState: true - }); - } - }, 250); - // Update the URL when entering search string (at most once per second) $( '#media-search-input' ).on( 'input', _.debounce( function(e) { var val = $( e.currentTarget ).val(), url = ''; @@ -161,6 +148,20 @@ } self.gridRouter.navigate( self.gridRouter.baseUrl( url ) ); }, 1000 ) ); + + _.delay( _.bind( this.createRouter, this ), 1000 ); + }, + + createRouter: function() { + this.gridRouter = new media.view.Frame.Router( this ); + + // Verify pushState support and activate + if ( window.history && window.history.pushState ) { + Backbone.history.start({ + root: mediaGridSettings.adminUrl, + pushState: true + }); + } }, createSelection: function() {