From 43c289dee6d824f88d2ef117416df447c8128496 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Sat, 10 Nov 2012 19:25:39 +0000 Subject: [PATCH] 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. git-svn-id: http://core.svn.wordpress.org/trunk@22535 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-views.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 0c0ab9d9f7..d1f2dd649a 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1597,13 +1597,14 @@ // --------------------------------- media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({ initialize: function() { - var selectionToLibrary = function( state ) { + var selectionToLibrary = function( state, filter ) { return function() { var controller = this.controller, selection = controller.state().get('selection'), - edit = controller.get( state ); + edit = controller.get( state ), + models = filter ? filter( selection ) : selection.models; - edit.set( 'library', new media.model.Selection( selection.models, { + edit.set( 'library', new media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -1616,7 +1617,9 @@ gallery: { text: l10n.createNewGallery, priority: 40, - click: selectionToLibrary('gallery-edit') + click: selectionToLibrary('gallery-edit', function( selection ) { + return selection.where({ type: 'image' }); + }) }, batch: { @@ -1637,7 +1640,7 @@ media.view.Toolbar.Insert.prototype.refresh.apply( this, arguments ); // Check if every attachment in the selection is an image. - this.get('gallery').$el.toggle( count > 1 && selection.all( function( attachment ) { + this.get('gallery').$el.toggle( count > 1 && selection.any( function( attachment ) { return 'image' === attachment.get('type'); }) );