Changeset 22802
- Timestamp:
- 11/22/2012 12:41:39 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r22798 r22802 681 681 if ( existing ) { 682 682 if ( options.add ) { 683 if ( _.isUndefined( options.at ) ) 683 if ( _.isUndefined( options.at ) ) { 684 684 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 } 687 689 } else { 688 690 _.each( next, function( view ) { … … 737 739 // For more information on the `options` object, see `Views.set()`. 738 740 add: function( selector, views, options ) { 741 if ( ! _.isString( selector ) ) { 742 options = views; 743 views = selector; 744 selector = ''; 745 } 746 739 747 return this.set( selector, views, _.extend({ add: true }, options ) ); 740 748 }, … … 2185 2193 delete this.options.views; 2186 2194 2187 if ( ! this.options.silent )2195 // if ( ! this.options.silent ) 2188 2196 this.render(); 2189 2197 }, 2190 2198 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, 2211 2200 2212 2201 set: function( id, view, options ) { 2202 var priority, views, index; 2203 2213 2204 options = options || {}; 2214 2205 … … 2216 2207 if ( _.isObject( id ) ) { 2217 2208 _.each( id, function( view, id ) { 2218 this.set( id, view , { silent: true });2209 this.set( id, view ); 2219 2210 }, this ); 2220 2221 if ( ! options.silent )2222 this.render();2223 2211 return this; 2224 2212 } … … 2229 2217 view.controller = view.controller || this.controller; 2230 2218 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 2231 2231 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 2234 2236 return this; 2235 2237 }, … … 2239 2241 }, 2240 2242 2241 unset: function( id, options ) { 2243 unset: function( id ) { 2244 var view = this.get( id ); 2245 if ( view ) 2246 view.dispose(); 2247 2242 2248 delete this._views[ id ]; 2243 if ( ! options || ! options.silent )2244 this.render();2245 2249 return this; 2246 2250 },
Note: See TracChangeset
for help on using the changeset viewer.