Make WordPress Core

Changeset 22802


Ignore:
Timestamp:
11/22/2012 12:41:39 AM (13 years ago)
Author:
koopersmith
Message:

Media: Make priority list views leverage the subview management class. see #21390.

File:
1 edited

Legend:

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

    r22798 r22802  
    681681            if ( existing ) {
    682682                if ( options.add ) {
    683                     if ( _.isUndefined( options.at ) )
     683                    if ( _.isUndefined( options.at ) ) {
    684684                        next = existing.concat( views );
    685                     else
    686                         next = existing.splice.apply( existing, [ options.at, 0 ].concat( views ) );
     685                    } else {
     686                        next = existing;
     687                        next.splice.apply( next, [ options.at, 0 ].concat( views ) );
     688                    }
    687689                } else {
    688690                    _.each( next, function( view ) {
     
    737739        // For more information on the `options` object, see `Views.set()`.
    738740        add: function( selector, views, options ) {
     741            if ( ! _.isString( selector ) ) {
     742                options  = views;
     743                views    = selector;
     744                selector = '';
     745            }
     746
    739747            return this.set( selector, views, _.extend({ add: true }, options ) );
    740748        },
     
    21852193            delete this.options.views;
    21862194
    2187             if ( ! this.options.silent )
     2195            // if ( ! this.options.silent )
    21882196                this.render();
    21892197        },
    21902198
    2191         destroy: function() {
    2192             this.remove();
    2193             _.each( this._views, function( view ) {
    2194                 if ( view.destroy )
    2195                     view.destroy();
    2196             });
    2197         },
    2198 
    2199         render: function() {
    2200             var els = _( this._views ).chain().sortBy( function( view ) {
    2201                     return view.options.priority || 10;
    2202                 }).pluck('el').value();
    2203 
    2204             // Make sure to detach the elements we want to reuse.
    2205             // Otherwise, `jQuery.html()` will unbind their events.
    2206             $( els ).detach();
    2207 
    2208             this.$el.html( els );
    2209             return this;
    2210         },
     2199        destroy: this.dispose,
    22112200
    22122201        set: function( id, view, options ) {
     2202            var priority, views, index;
     2203
    22132204            options = options || {};
    22142205
     
    22162207            if ( _.isObject( id ) ) {
    22172208                _.each( id, function( view, id ) {
    2218                     this.set( id, view, { silent: true });
     2209                    this.set( id, view );
    22192210                }, this );
    2220 
    2221                 if ( ! options.silent )
    2222                     this.render();
    22232211                return this;
    22242212            }
     
    22292217            view.controller = view.controller || this.controller;
    22302218
     2219            this.unset( id );
     2220
     2221            priority = view.options.priority || 10;
     2222            views = this.views.get() || [];
     2223
     2224            _.find( views, function( existing, i ) {
     2225                if ( existing.options.priority > priority ) {
     2226                    index = i;
     2227                    return true;
     2228                }
     2229            });
     2230
    22312231            this._views[ id ] = view;
    2232             if ( ! options.silent )
    2233                 this.render();
     2232            this.views.add( view, {
     2233                at: _.isNumber( index ) ? index : views.length || 0
     2234            });
     2235
    22342236            return this;
    22352237        },
     
    22392241        },
    22402242
    2241         unset: function( id, options ) {
     2243        unset: function( id ) {
     2244            var view = this.get( id );
     2245            if ( view )
     2246                view.dispose();
     2247
    22422248            delete this._views[ id ];
    2243             if ( ! options || ! options.silent )
    2244                 this.render();
    22452249            return this;
    22462250        },
Note: See TracChangeset for help on using the changeset viewer.