WordPress.org

Make WordPress Core

Changeset 22363


Ignore:
Timestamp:
11/05/2012 02:43:47 AM (9 years ago)
Author:
koopersmith
Message:

Media: Show an inline uploader when the media library is empty.

Merges most of wp.media.controller.Upload into wp.media.controller.Library, so we always create an inline uploader instead of an attachments browser if the state's library is empty.

props rzen, fixes #22323, see #21390.

File:
1 edited

Legend:

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

    r22362 r22363  
    192192            this.get('selection').on( 'selection:single', this.buildDetails, this );
    193193            this.get('selection').on( 'selection:unsingle', this.clearDetails, this );
     194
     195            this._updateEmpty();
     196            this.get('library').on( 'add remove reset', this._updateEmpty, this );
     197            this.on( 'change:empty', this.refresh, this );
     198            this.refresh();
    194199        },
    195200
     
    203208            this.get('selection').off( 'selection:single', this.buildDetails, this );
    204209            this.get('selection').off( 'selection:unsingle', this.clearDetails, this );
     210            this.get('library').off( 'add remove reset', this._updateEmpty, this );
     211            this.off( 'change:empty', this.refresh, this );
    205212        },
    206213
     
    231238
    232239        content: function() {
    233             var frame = this.frame;
     240            var frame = this.frame,
     241                library = this.get('library'),
     242                view;
    234243
    235244            // Content.
    236             frame.content( new media.view.AttachmentsBrowser({
    237                 controller: frame,
    238                 collection: this.get('library'),
    239                 model:      this
    240             }).render() );
     245            if ( this.get('empty') ) {
     246                // Attempt to fetch any Attachments we don't already have.
     247                library.more();
     248
     249                // In the meantime, render an inline uploader.
     250                view = new media.view.UploaderInline({
     251                    controller: frame
     252                });
     253            } else {
     254                // Browse our library of attachments.
     255                view = new media.view.AttachmentsBrowser({
     256                    controller: frame,
     257                    collection: library,
     258                    model:      this
     259                });
     260            }
     261
     262            frame.content( view.render() );
     263        },
     264
     265        refresh: function() {
     266            this.frame.$el.toggleClass( 'hide-sidebar hide-toolbar', this.get('empty') );
     267            this.content();
     268        },
     269
     270        _updateEmpty: function() {
     271            this.set( 'empty', ! this.get('library').length );
    241272        },
    242273
     
    310341
    311342            media.controller.Library.prototype.initialize.apply( this, arguments );
    312         },
    313 
    314         activate: function() {
    315             this.get('library').on( 'add remove reset', this.refresh, this );
    316             media.controller.Library.prototype.activate.apply( this, arguments );
    317             this.refresh();
    318         },
    319 
    320         deactivate: function() {
    321             this.get('library').off( 'add remove reset', this.refresh, this );
    322             media.controller.Library.prototype.deactivate.apply( this, arguments );
    323         },
    324 
    325         refresh: function() {
    326             this.frame.$el.toggleClass( 'hide-sidebar hide-toolbar', ! this.get('library').length );
    327             this.content();
    328         },
    329 
    330         content: function() {
    331             var frame = this.frame,
    332                 upload;
    333 
    334             if ( this.get('library').length ) {
    335                 media.controller.Library.prototype.content.apply( this, arguments );
    336             } else {
    337                 upload = new media.view.UploaderInline({
    338                     controller: frame
    339                 }).render();
    340 
    341                 frame.content( upload );
    342             }
    343         }
     343        }
     344
    344345    });
    345346
Note: See TracChangeset for help on using the changeset viewer.