Changeset 22888
- Timestamp:
- 11/28/2012 02:03:31 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-views.js
r22882 r22888 815 815 } 816 816 817 views = views || []; 818 817 819 if ( existing = this.get( selector ) ) { 818 820 views = _.isArray( views ) ? views : [ views ]; … … 821 823 822 824 if ( ! options || ! options.silent ) 823 _.invoke( views, 'dispose' , { silent: true });825 _.invoke( views, 'dispose' ); 824 826 825 827 return this; … … 1015 1017 var options; 1016 1018 1019 if ( this.prepare ) 1020 options = this.prepare(); 1021 1017 1022 this.views.detach(); 1018 1023 1019 1024 if ( this.template ) { 1020 options = this.prepare ? this.prepare() :{};1025 options = options || {}; 1021 1026 this.trigger( 'prepare', options ); 1022 1027 this.$el.html( this.template( options ) ); … … 2434 2439 }, 2435 2440 2436 destroy: function() { 2437 this.model.off( null, null, this ); 2438 this.remove(); 2441 dispose: function() { 2442 this.updateAll(); 2443 media.View.prototype.dispose.apply( this, arguments ); 2444 return this; 2439 2445 }, 2440 2446 … … 2463 2469 options.size = this.imageSize(); 2464 2470 2471 this.views.detach(); 2465 2472 this.$el.html( this.template( options ) ); 2466 2473 … … 2475 2482 this.select(); 2476 2483 2484 this.views.render(); 2477 2485 return this; 2478 2486 }, … … 2572 2580 }, 2573 2581 2582 updateAll: function() { 2583 var $settings = this.$('[data-setting]'), 2584 model = this.model, 2585 changed; 2586 2587 changed = _.chain( $settings ).map( function( el ) { 2588 var $input = $('input, textarea, select, [value]', el ), 2589 setting, value; 2590 2591 if ( ! $input.length ) 2592 return; 2593 2594 setting = $(el).data('setting'); 2595 value = $input.val(); 2596 2597 // Record the value if it changed. 2598 if ( model.get( setting ) !== value ) 2599 return [ setting, value ]; 2600 }).compact().object().value(); 2601 2602 if ( changed ) 2603 model.save( changed ); 2604 }, 2605 2574 2606 removeFromLibrary: function( event ) { 2575 2607 // Stop propagation so the model isn't selected. … … 2615 2647 tagName: 'ul', 2616 2648 className: 'attachments', 2617 template: media.template('attachments-css'), 2649 2650 cssTemplate: media.template('attachments-css'), 2618 2651 2619 2652 events: { … … 2632 2665 }); 2633 2666 2634 _.each(['add','remove'], function( method ) { 2635 this.collection.on( method, function( attachment, attachments, options ) { 2636 this[ method ]( attachment, options.index ); 2637 }, this ); 2667 this._viewsByCid = {}; 2668 2669 this.collection.on( 'add', function( attachment, attachments, options ) { 2670 this.views.add( this.createAttachmentView( attachment ), { 2671 at: options.index 2672 }); 2673 }, this ); 2674 2675 this.collection.on( 'remove', function( attachment, attachments, options ) { 2676 var view = this._viewsByCid[ attachment.cid ]; 2677 delete this._viewsByCid[ attachment.cid ]; 2678 2679 if ( view ) 2680 view.remove(); 2638 2681 }, this ); 2639 2682 … … 2665 2708 $css.remove(); 2666 2709 2667 media.view.Attachments.$head().append( this. template({2710 media.view.Attachments.$head().append( this.cssTemplate({ 2668 2711 id: this.el.id, 2669 2712 edge: this.edge(), … … 2740 2783 }, 2741 2784 2742 render: function() { 2743 // If there are no elements, load some. 2744 if ( ! this.collection.length ) { 2785 createAttachmentView: function( attachment ) { 2786 var view = new this.options.AttachmentView({ 2787 controller: this.controller, 2788 model: attachment, 2789 collection: this.collection, 2790 selection: this.options.selection 2791 }); 2792 2793 return this._viewsByCid[ attachment.cid ] = view; 2794 }, 2795 2796 prepare: function() { 2797 // Create all of the Attachment views, and replace 2798 // the list in a single DOM operation. 2799 if ( this.collection.length ) { 2800 this.views.set( this.collection.map( this.createAttachmentView, this ) ); 2801 2802 // If there are no elements, clear the views and load some. 2803 } else { 2804 this.views.unset(); 2745 2805 this.collection.more().done( this.scroll ); 2746 this.$el.empty();2747 return this;2748 2806 } 2749 2750 // Otherwise, create all of the Attachment views, and replace2751 // the list in a single DOM operation.2752 this.$el.html( this.collection.map( function( attachment ) {2753 return new this.options.AttachmentView({2754 controller: this.controller,2755 model: attachment,2756 collection: this.collection,2757 selection: this.options.selection2758 }).render().$el;2759 }, this ) );2760 2761 return this;2762 2807 }, 2763 2808 … … 2766 2811 // threshold to query for additional attachments. 2767 2812 this.scroll(); 2768 },2769 2770 add: function( attachment, index ) {2771 var view, children;2772 2773 view = new this.options.AttachmentView({2774 controller: this.controller,2775 model: attachment,2776 collection: this.collection,2777 selection: this.options.selection2778 }).render();2779 2780 children = this.$el.children();2781 2782 if ( children.length > index )2783 children.eq( index ).before( view.$el );2784 else2785 this.$el.append( view.$el );2786 },2787 2788 remove: function( attachment, index ) {2789 var children = this.$el.children();2790 if ( children.length )2791 children.eq( index ).detach();2792 2813 }, 2793 2814
Note: See TracChangeset
for help on using the changeset viewer.