WordPress.org

Make WordPress Core

Changeset 22535


Ignore:
Timestamp:
11/10/2012 07:25:39 PM (8 years ago)
Author:
koopersmith
Message:

Media: Automatically strip any non-image items from the collection when creating a gallery.

Also changes the rules for when the "new gallery" button shows:

  • More than two items must be selected.
  • At least one of them must be an image.

see #21390.

File:
1 edited

Legend:

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

    r22533 r22535  
    15981598    media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({
    15991599        initialize: function() {
    1600             var selectionToLibrary = function( state ) {
     1600            var selectionToLibrary = function( state, filter ) {
    16011601                    return function() {
    16021602                        var controller = this.controller,
    16031603                            selection = controller.state().get('selection'),
    1604                             edit = controller.get( state );
    1605 
    1606                         edit.set( 'library', new media.model.Selection( selection.models, {
     1604                            edit = controller.get( state ),
     1605                            models = filter ? filter( selection ) : selection.models;
     1606
     1607                        edit.set( 'library', new media.model.Selection( models, {
    16071608                            props:    selection.props.toJSON(),
    16081609                            multiple: true
     
    16171618                    text:     l10n.createNewGallery,
    16181619                    priority: 40,
    1619                     click:    selectionToLibrary('gallery-edit')
     1620                    click:    selectionToLibrary('gallery-edit', function( selection ) {
     1621                        return selection.where({ type: 'image' });
     1622                    })
    16201623                },
    16211624
     
    16381641
    16391642            // Check if every attachment in the selection is an image.
    1640             this.get('gallery').$el.toggle( count > 1 && selection.all( function( attachment ) {
     1643            this.get('gallery').$el.toggle( count > 1 && selection.any( function( attachment ) {
    16411644                return 'image' === attachment.get('type');
    16421645            }) );
Note: See TracChangeset for help on using the changeset viewer.