When settting a featured image, move the currently selected image to the beginning of the library if it doesn't exist within the attachments loaded so far.

Props koopersmith
fixes #22494


git-svn-id: https://develop.svn.wordpress.org/trunk@22993 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-12-03 07:04:34 +00:00
parent 077dea75f7
commit 594bbe90df
1 changed files with 23 additions and 0 deletions

View File

@ -575,11 +575,34 @@
}, media.controller.Library.prototype.defaults ),
initialize: function() {
var library, comparator;
// If we haven't been provided a `library`, create a `Selection`.
if ( ! this.get('library') )
this.set( 'library', media.query({ type: 'image' }) );
media.controller.Library.prototype.initialize.apply( this, arguments );
library = this.get('library');
comparator = library.comparator;
// Overload the library's comparator to push items that are not in
// the mirrored query to the front of the aggregate collection.
library.comparator = function( a, b ) {
var aInQuery = !! this.mirroring.getByCid( a.cid ),
bInQuery = !! this.mirroring.getByCid( b.cid );
if ( ! aInQuery && bInQuery )
return -1;
else if ( aInQuery && ! bInQuery )
return 1;
else
return comparator.apply( this, arguments );
};
// Add all items in the selection to the library, so any featured
// images that are not initially loaded still appear.
library.observe( this.get('selection') );
},
activate: function() {