From 48d83dcc6686b5417b041a98145160405c0fbd1c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 18 Aug 2014 02:13:01 +0000 Subject: [PATCH] Media Grid: on page load with `?item=` in the URL, if the model is not in the library: fetch it. Defer the triggering of `edit:attachment` until the model has been fetched. Fixes #29052. git-svn-id: https://develop.svn.wordpress.org/trunk@29525 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 0cb0654ff2..7324f3bdc8 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -306,10 +306,20 @@ // Show the modal with a specific item showItem: function( query ) { - var library = media.frame.state().get('library'); + var library = media.frame.state().get('library'), item; // Trigger the media frame to open the correct item - media.frame.trigger( 'edit:attachment', library.findWhere( { id: parseInt( query, 10 ) } ) ); + item = library.findWhere( { id: parseInt( query, 10 ) } ); + if ( item ) { + media.frame.trigger( 'edit:attachment', item ); + } else { + item = media.attachment( query ); + media.frame.listenTo( item, 'change', function( model ) { + media.frame.stopListening( item ); + media.frame.trigger( 'edit:attachment', model ); + } ); + item.fetch(); + } } }); @@ -373,9 +383,6 @@ if ( this.options.model ) { this.model = this.options.model; - } else { - // this is a hack - this.model = this.library.at( 0 ); } this.bindHandlers();