Make WordPress Core

Changeset 29525


Ignore:
Timestamp:
08/18/2014 02:13:01 AM (12 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-grid.js

    r29517 r29525  
    307307                // Show the modal with a specific item
    308308                showItem: function( query ) {
    309                         var library = media.frame.state().get('library');
     309                        var library = media.frame.state().get('library'), item;
    310310
    311311                        // Trigger the media frame to open the correct item
    312                         media.frame.trigger( 'edit:attachment', library.findWhere( { id: parseInt( query, 10 ) } ) );
     312                        item = library.findWhere( { id: parseInt( query, 10 ) } );
     313                        if ( item ) {
     314                                media.frame.trigger( 'edit:attachment', item );
     315                        } else {
     316                                item = media.attachment( query );
     317                                media.frame.listenTo( item, 'change', function( model ) {
     318                                        media.frame.stopListening( item );
     319                                        media.frame.trigger( 'edit:attachment', model );
     320                                } );
     321                                item.fetch();
     322                        }
    313323                }
    314324        });
     
    374384                        if ( this.options.model ) {
    375385                                this.model = this.options.model;
    376                         } else {
    377                                 // this is a hack
    378                                 this.model = this.library.at( 0 );
    379386                        }
    380387
Note: See TracChangeset for help on using the changeset viewer.