Make WordPress Core

Changeset 22712


Ignore:
Timestamp:
11/20/2012 01:49:35 PM (11 years ago)
Author:
koopersmith
Message:

Media: Add filters to the media library. fixes #22514, see #21390.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/css/media-views.css

    r22706 r22712  
    387387    height: 100%;
    388388    width: 100%;
     389}
     390
     391/**
     392 * Attachment Browser Filters
     393 */
     394.media-frame select.attachment-filters {
     395    margin-top: 11px;
     396    margin-right: 10px;
    389397}
    390398
  • trunk/wp-includes/js/media-views.js

    r22710 r22712  
    256256            toolbar:    'main-attachments',
    257257            sidebar:    'settings',
    258             searchable: true
     258            searchable: true,
     259            filterable: false
    259260        },
    260261
     
    335336            var frame = this.frame;
    336337
    337             // Content.
    338338            if ( this.get('empty') ) {
    339339                // Attempt to fetch any Attachments we don't already have.
     
    355355
    356356        _updateEmpty: function() {
    357             var library = this.get('library');
     357            var library = this.get('library'),
     358                props = library.props;
     359
     360            // If we're filtering the library, bail.
     361            if ( this.get('filterable') && ( props.get('type') || props.get('parent') ) )
     362                return;
     363
    358364            this.set( 'empty', ! library.length && ! library.props.get('search') );
    359365        },
     
    12141220                search:     state.get('searchable'),
    12151221                upload:     state.get('upload'),
     1222                filters:    state.get('filterable'),
    12161223
    12171224                AttachmentView: state.get('AttachmentView')
     
    13411348                // Main states.
    13421349                new media.controller.Library( _.defaults({
    1343                     selection: options.selection,
    1344                     library:   media.query( options.library ),
    1345                     editable:  true
     1350                    selection:  options.selection,
     1351                    library:    media.query( options.library ),
     1352                    editable:   true,
     1353                    filterable: true
    13461354                }, main ) ),
    13471355
     
    27202728    });
    27212729
     2730    /**
     2731     * wp.media.view.AttachmentFilters
     2732     */
     2733    media.view.AttachmentFilters = media.View.extend({
     2734        tagName:   'select',
     2735        className: 'attachment-filters',
     2736
     2737        events: {
     2738            change: 'change'
     2739        },
     2740
     2741        initialize: function() {
     2742            var els;
     2743
     2744            els = _.map({
     2745                all:      'allMediaItems',
     2746                uploaded: 'uploadedToThisPost',
     2747                image:    'images',
     2748                audio:    'audio',
     2749                video:    'videos'
     2750            }, function( text, value ) {
     2751                return this.make( 'option', { value: value }, l10n[ text ] );
     2752            }, this );
     2753
     2754            this.$el.html( els );
     2755
     2756            this.model.on( 'change', this.select, this );
     2757            this.select();
     2758        },
     2759
     2760        change: function( event ) {
     2761            var model = this.model,
     2762                value = this.el.value,
     2763                type;
     2764
     2765            if ( 'all' === value || 'uploaded' === value )
     2766                model.unset('type');
     2767            else if ( 'image' === value || 'audio' === value || 'video' === value )
     2768                model.set( 'type', value );
     2769
     2770            if ( 'uploaded' === value )
     2771                model.set( 'parent', media.view.settings.postId );
     2772            else
     2773                model.unset('parent');
     2774        },
     2775
     2776        select: function() {
     2777            var model = this.model,
     2778                type = model.get('type'),
     2779                value = 'all';
     2780
     2781            if ( model.get('parent') === media.view.settings.postId )
     2782                value = 'uploaded';
     2783            else if ( 'image' === type )
     2784                value = 'image';
     2785            else if ( 'audio' === type )
     2786                value = 'audio';
     2787            else if ( 'video' === type )
     2788                value = 'video';
     2789
     2790            this.$el.val( value );
     2791        }
     2792    });
     2793
    27222794
    27232795
     
    27332805
    27342806            _.defaults( this.options, {
    2735                 search: true,
    2736                 upload: false,
    2737                 total:  true,
     2807                filters: false,
     2808                search:  true,
     2809                upload:  false,
    27382810
    27392811                AttachmentView: media.view.Attachment.Library
     
    27432815                controller: this.controller
    27442816            });
     2817
     2818            if ( this.options.filters ) {
     2819                this.toolbar.set( 'filters', new media.view.AttachmentFilters({
     2820                    controller: this.controller,
     2821                    model:      this.collection.props,
     2822                    priority:   -80
     2823                }).render() );
     2824            }
    27452825
    27462826            if ( this.options.search ) {
     
    27482828                    controller: this.controller,
    27492829                    model:      this.collection.props,
    2750                     priority:   -60
     2830                    priority:   60
    27512831                }).render() );
    27522832            }
  • trunk/wp-includes/media.php

    r22706 r22712  
    13581358        'returnToLibrary'   => __( '← Return to library' ),
    13591359
     1360        'allMediaItems'      => __( 'All media items' ),
     1361        'uploadedToThisPost' => __( 'Uploaded to this post' ),
     1362        'images'             => __( 'Images' ),
     1363        'audio'              => __( 'Audio' ),
     1364        'videos'             => __( 'Videos' ),
     1365
    13601366        // Embed
    13611367        'embedFromUrlTitle' => __( 'Embed From URL' ),
Note: See TracChangeset for help on using the changeset viewer.