Make WordPress Core

Changeset 22337


Ignore:
Timestamp:
10/30/2012 11:36:38 PM (14 years ago)
Author:
koopersmith
Message:

Media JS: Properly build detail views when the selection's single model changes. see #21390.

File:
1 edited

Legend:

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

    r22335 r22337  
    136136                        this.on( 'activate', this.activate, this );
    137137                        this.on( 'deactivate', this.deactivate, this );
    138                         this.on( 'change:details', this.details, this );
    139138                },
    140139
     
    148147                        if ( this.get('multiple') )
    149148                                wp.Uploader.queue.on( 'add', this.selectUpload, this );
     149
     150                        this.get('selection').on( 'selection:single', this.buildDetails, this );
     151                        this.get('selection').on( 'selection:unsingle', this.clearDetails, this );
    150152                },
    151153
     
    156158
    157159                        wp.Uploader.queue.off( 'add', this.selectUpload, this );
     160                        this.get('selection').off( 'selection:single', this.buildDetails, this );
     161                        this.get('selection').off( 'selection:unsingle', this.clearDetails, this );
    158162                },
    159163
     
    180184                        }) );
    181185
    182                         this.details({ silent: true });
     186                        this.details();
    183187                        frame.sidebar().add({
    184188                                search: new media.view.Search({
     
    212216                },
    213217
    214                 details: function( options ) {
    215                         var model = this.get('selection').single(),
    216                                 view;
    217 
    218                         if ( model ) {
    219                                 view = new media.view.Attachment.Details({
    220                                         controller: this.frame,
    221                                         model:      model,
    222                                         priority:   80
    223                                 });
    224                         } else {
    225                                 view = new Backbone.View();
    226                         }
    227 
    228                         if ( ! options || ! options.silent )
    229                                 view.render();
    230 
    231                         this.frame.sidebar().add( 'details', view, options );
     218                details: function() {
     219                        var single = this.get('selection').single();
     220                        this[ single ? 'buildDetails' : 'clearDetails' ]( single );
     221                },
     222
     223                buildDetails: function( model ) {
     224                        this.frame.sidebar().add( 'details', new media.view.Attachment.Details({
     225                                controller: this.frame,
     226                                model:      model,
     227                                priority:   80
     228                        }).render() );
     229                        return this;
     230                },
     231
     232                clearDetails: function( model ) {
     233                        if ( this.get('selection').single() )
     234                                return this;
     235
     236                        this.frame.sidebar().add( 'details', new Backbone.View({
     237                                priority: 80
     238                        }).render() );
     239                        return this;
    232240                },
    233241
Note: See TracChangeset for help on using the changeset viewer.