Changeset 22662
- Timestamp:
- 11/19/2012 06:02:00 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r22660 r22662 575 575 576 576 _.extend( media.Views.prototype, { 577 all: function() { 578 return _.flatten( this._views ); 579 }, 580 577 581 get: function( selector ) { 578 582 selector = selector || ''; … … 593 597 existing = this.get( selector ); 594 598 next = views; 595 method = add ? ' attach' : 'replace';599 method = add ? 'insert' : 'replace'; 596 600 597 601 if ( existing ) { … … 602 606 next = existing.splice.apply( existing, [ options.at, 0 ].concat( views ) ); 603 607 } else { 604 this.unset( selector ); 605 _.invoke( existing, 'dispose' ); 608 _.each( next, function( view ) { 609 view.__detach = true; 610 }); 611 612 _.each( existing, function( view ) { 613 if ( view.__detach ) 614 view.$el.detach(); 615 else 616 view.dispose(); 617 }); 618 619 _.each( next, function( view ) { 620 delete view.__detach; 621 }); 606 622 } 607 623 } … … 635 651 } 636 652 637 views = _.isArray( views ) ? views : [ views ]; 638 639 if ( existing = this.get( selector ) ) 640 this._views[ selector ] = _.difference( existing, views ); 641 653 if ( existing = this.get( selector ) ) { 654 views = _.isArray( views ) ? views : [ views ]; 655 this._views[ selector ] = views.length ? _.difference( existing, views ) : []; 656 } 657 658 return this; 659 }, 660 661 detach: function() { 662 $( _.pluck( this.all(), 'el' ) ).detach(); 642 663 return this; 643 664 }, … … 661 682 delete this.selector; 662 683 663 _. chain( this._views ).flatten().invoke('dispose');684 _.invoke( this.all(), 'dispose' ); 664 685 this._views = []; 686 return this; 665 687 }, 666 688 … … 670 692 }, 671 693 672 attach: function( $target, els, options ) {694 insert: function( $target, els, options ) { 673 695 var at = options && options.at, 674 696 $children; … … 718 740 this.dispose(); 719 741 return Backbone.View.prototype.remove.apply( this, arguments ); 742 }, 743 744 render: function() { 745 var options; 746 747 this.views.detach(); 748 749 if ( this.template ) { 750 options = this.prepare ? this.prepare() : {}; 751 this.trigger( 'prepare', options ); 752 this.$el.html( this.template( options ) ); 753 } 754 755 this.views.render(); 756 return this; 757 }, 758 759 prepare: function() { 760 return this.options; 720 761 } 721 762 }); … … 754 795 model.frame = this; 755 796 }, this ); 756 },757 758 render: function() {759 if ( ! this.template )760 return;761 762 this.$el.html( this.template( this.options ) );763 this.views.render();764 return this;765 797 }, 766 798
Note: See TracChangeset
for help on using the changeset viewer.