WordPress.org

Make WordPress Core

Changeset 22993


Ignore:
Timestamp:
12/03/2012 07:04:34 AM (9 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

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

    r22991 r22993  
    576576
    577577        initialize: function() {
     578            var library, comparator;
     579
    578580            // If we haven't been provided a `library`, create a `Selection`.
    579581            if ( ! this.get('library') )
     
    581583
    582584            media.controller.Library.prototype.initialize.apply( this, arguments );
     585
     586            library    = this.get('library');
     587            comparator = library.comparator;
     588
     589            // Overload the library's comparator to push items that are not in
     590            // the mirrored query to the front of the aggregate collection.
     591            library.comparator = function( a, b ) {
     592                var aInQuery = !! this.mirroring.getByCid( a.cid ),
     593                    bInQuery = !! this.mirroring.getByCid( b.cid );
     594
     595                if ( ! aInQuery && bInQuery )
     596                    return -1;
     597                else if ( aInQuery && ! bInQuery )
     598                    return 1;
     599                else
     600                    return comparator.apply( this, arguments );
     601            };
     602
     603            // Add all items in the selection to the library, so any featured
     604            // images that are not initially loaded still appear.
     605            library.observe( this.get('selection') );
    583606        },
    584607
Note: See TracChangeset for help on using the changeset viewer.