Changeset 22684
- Timestamp:
- 11/19/2012 12:11:16 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r22682 r22684 614 614 // `Backbone.View` instances. 615 615 // 616 // Use `Views.add()` as a shortcut for setting `options.add` to `true`.616 // --- 617 617 // 618 618 // Accepts an `options` object, which has a significant effect on the 619 // resulting behavior. By default, the provided `views` will replace 619 // resulting behavior. 620 // 621 // `options.silent` – *boolean, `false`* 622 // > If `options.silent` is true, no DOM modifications will be made. 623 // 624 // `options.add` – *boolean, `false`* 625 // > Use `Views.add()` as a shortcut for setting `options.add` to true. 626 // 627 // > By default, the provided `views` will replace 620 628 // any existing views associated with the selector. If `options.add` 621 // is set to `true`, the provided `views` will be added to the existing 622 // views. When adding, the `views` will added to the end of the array 623 // by default. To insert `views` at a specific index, use `options.at`. 629 // is true, the provided `views` will be added to the existing views. 630 // 631 // `options.at` – *integer, `undefined`* 632 // > When adding, to insert `views` at a specific index, use 633 // `options.at`. By default, `views` are added to the end of the array. 624 634 set: function( selector, views, options ) { 625 var $selector, els, existing, add,method;635 var $selector, els, existing, method; 626 636 627 637 if ( ! _.isString( selector ) ) { … … 631 641 } 632 642 643 options = options || {}; 633 644 views = _.isArray( views ) ? views : [ views ]; 634 add = options && options.add;635 645 existing = this.get( selector ); 636 646 next = views; 637 method = add ? 'insert' : 'replace';647 method = options.add ? 'insert' : 'replace'; 638 648 639 649 if ( existing ) { 640 if ( add ) {650 if ( options.add ) { 641 651 if ( _.isUndefined( options.at ) ) 642 652 next = existing.concat( views ); … … 673 683 }, this ); 674 684 675 this[ method ]( $selector, els, options ); 685 if ( ! options.silent ) 686 this[ method ]( $selector, els, options ); 687 676 688 return this; 677 689 }, … … 691 703 // Accepts an `options` object. By default, provided `views` will be 692 704 // inserted at the end of the array of existing views. To insert 693 // `views` at a specific index, use `options.at`. For more information 694 // on the `options` object, see `Views.set()`. 705 // `views` at a specific index, use `options.at`. If `options.silent` 706 // is true, no DOM modifications will be made. 707 // 708 // For more information on the `options` object, see `Views.set()`. 695 709 add: function( selector, views, options ) { 696 710 return this.set( selector, views, _.extend({ add: true }, options ) ); … … 700 714 // 701 715 // Stops tracking `views` registered to a `selector`. If no `views` are 702 // set, then all of the `selector`'s subviews will be unregistered. 703 unset: function( selector, views ) { 716 // set, then all of the `selector`'s subviews will be unregistered and 717 // disposed. 718 // 719 // Accepts an `options` object. If `options.silent` is set, `dispose` 720 // will *not* be triggered on the unregistered views. 721 unset: function( selector, views, options ) { 704 722 var existing; 705 723 706 724 if ( ! _.isString( selector ) ) { 725 options = views; 707 726 views = selector; 708 727 selector = ''; … … 713 732 this._views[ selector ] = views.length ? _.difference( existing, views ) : []; 714 733 } 734 735 if ( ! options || ! options.silent ) 736 _.invoke( views, 'dispose', { silent: true }); 715 737 716 738 return this; … … 747 769 // ### Dispose all subviews 748 770 // 749 // Triggers the `dispose()` method on all subviews. Resets the 750 // internals of the views manager. 751 dispose: function() { 752 delete this.parent; 753 delete this.selector; 771 // Triggers the `dispose()` method on all subviews. Detaches the master 772 // view from its parent. Resets the internals of the views manager. 773 // 774 // Accepts an `options` object. If `options.silent` is set, `unset` 775 // will *not* be triggered on the master view's parent. 776 dispose: function( options ) { 777 if ( ! options || ! options.silent ) { 778 if ( this.parent && this.parent.views ) 779 this.parent.views.unset( this.selector, this.view, { silent: true }); 780 delete this.parent; 781 delete this.selector; 782 } 754 783 755 784 _.invoke( this.all(), 'dispose' );
Note: See TracChangeset
for help on using the changeset viewer.