From 594bbe90dff8f014d2e8d53e67830eb0a0389fc2 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 3 Dec 2012 07:04:34 +0000 Subject: [PATCH] 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 --- wp-includes/js/media-views.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 4136901608..89de1da126 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -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() {