Changeset 22745
- Timestamp:
- 11/21/2012 11:04:23 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/meta-boxes.php
r22667 r22745 1056 1056 frame = wp.media( options ); 1057 1057 1058 frame.get('library').set( 'filterable', 'uploaded' ); 1059 1058 1060 frame.toolbar.on( 'activate:select', function() { 1059 1061 frame.toolbar.view().set({ -
trunk/wp-includes/js/media-views.js
r22743 r22745 1369 1369 library: media.query( options.library ), 1370 1370 editable: true, 1371 filterable: true1371 filterable: 'all' 1372 1372 }, main ) ), 1373 1373 … … 1385 1385 1386 1386 new media.controller.Library( _.defaults({ 1387 id: 'gallery-library', 1388 library: media.query({ type: 'image' }) 1387 id: 'gallery-library', 1388 library: media.query({ type: 'image' }), 1389 filterable: 'uploaded' 1389 1390 }, gallery ) ), 1390 1391 … … 2767 2768 }, 2768 2769 2770 filters: {}, 2771 keys: [], 2772 2773 initialize: function() { 2774 // Build `<option>` elements. 2775 this.$el.html( _.chain( this.filters ).map( function( filter, value ) { 2776 return { 2777 el: this.make( 'option', { value: value }, filter.text ), 2778 priority: filter.priority || 50 2779 }; 2780 }, this ).sortBy('priority').pluck('el').value() ); 2781 2782 this.model.on( 'change', this.select, this ); 2783 this.select(); 2784 }, 2785 2786 change: function( event ) { 2787 var filter = this.filters[ this.el.value ]; 2788 2789 if ( filter ) 2790 this.model.set( filter.props ); 2791 }, 2792 2793 select: function() { 2794 var model = this.model, 2795 value = 'all', 2796 props = model.toJSON(); 2797 2798 _.find( this.filters, function( filter, id ) { 2799 var equal = _.all( filter.props, function( prop, key ) { 2800 return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] ); 2801 }); 2802 2803 if ( equal ) 2804 return value = id; 2805 }); 2806 2807 this.$el.val( value ); 2808 } 2809 }); 2810 2811 media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({ 2812 filters: { 2813 all: { 2814 text: l10n.allMediaItems, 2815 props: { 2816 parent: null 2817 }, 2818 priority: 10 2819 }, 2820 2821 uploaded: { 2822 text: l10n.uploadedToThisPost, 2823 props: { 2824 parent: media.view.settings.postId 2825 }, 2826 priority: 20 2827 } 2828 } 2829 }); 2830 2831 media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({ 2769 2832 filters: (function() { 2770 2833 var filters = {}; … … 2799 2862 2800 2863 return filters; 2801 }()), 2802 2803 initialize: function() { 2804 // Build `<option>` elements. 2805 this.$el.html( _.chain( this.filters ).map( function( filter, value ) { 2806 return { 2807 el: this.make( 'option', { value: value }, filter.text ), 2808 priority: filter.priority || 50 2809 }; 2810 }, this ).sortBy('priority').pluck('el').value() ); 2811 2812 this.model.on( 'change', this.select, this ); 2813 this.select(); 2814 }, 2815 2816 change: function( event ) { 2817 var filter = this.filters[ this.el.value ]; 2818 2819 if ( filter ) 2820 this.model.set( filter.props ); 2821 }, 2822 2823 select: function() { 2824 var model = this.model, 2825 value = 'all', 2826 type = model.get('type'), 2827 parent = model.get('parent'), 2828 props = { 2829 parent: _.isUndefined( parent ) ? null : parent, 2830 type: _.isUndefined( type ) ? null : type 2831 }; 2832 2833 _.find( this.filters, function( filter, key ) { 2834 if ( _.isEqual( filter.props, props ) ) 2835 return value = key; 2836 }); 2837 2838 this.$el.val( value ); 2839 } 2864 }()) 2840 2865 }); 2841 2866 … … 2850 2875 2851 2876 initialize: function() { 2877 var filters, FiltersConstructor; 2878 2852 2879 this.controller = this.options.controller; 2853 2880 … … 2864 2891 }); 2865 2892 2866 if ( this.options.filters ) { 2867 this.toolbar.set( 'filters', new media.view.AttachmentFilters({ 2893 filters = this.options.filters; 2894 if ( 'uploaded' === filters ) 2895 FiltersConstructor = media.view.AttachmentFilters.Uploaded; 2896 else if ( 'all' === filters ) 2897 FiltersConstructor = media.view.AttachmentFilters.All; 2898 2899 if ( FiltersConstructor ) { 2900 this.toolbar.set( 'filters', new FiltersConstructor({ 2868 2901 controller: this.controller, 2869 2902 model: this.collection.props,
Note: See TracChangeset
for help on using the changeset viewer.