Media: Fix selections in Media Library Featured Image modal on open.

In [50829] infinite scrolling was removed from the Media Library and modal which introduced unintended behavior for featured images where only the selected image shows when opening the library. This change reverts only the logic that caused this and applies a proper fix when opening the library.

Props benitolopez, hellofromTonya, joedolson, peterwilsoncc, circlecube, danielbachhuber, PieWP, sabernhardt, szaqal21, dariak, sergeybiryukov.
Fixes .


git-svn-id: https://develop.svn.wordpress.org/trunk@52384 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
antpb 2021-12-17 20:15:01 +00:00
parent 954e9c153f
commit 0759d89e67
2 changed files with 12 additions and 14 deletions
src/js/media/controllers

@ -106,9 +106,7 @@ FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prot
*/
updateSelection: function() {
var selection = this.get('selection'),
library = this.get('library'),
id = wp.media.view.settings.post.featuredImageId,
infiniteScrolling = wp.media.view.settings.infiniteScrolling,
attachment;
if ( '' !== id && -1 !== id ) {
@ -117,10 +115,6 @@ FeaturedImage = Library.extend(/** @lends wp.media.controller.FeaturedImage.prot
}
selection.reset( attachment ? [ attachment ] : [] );
if ( ! infiniteScrolling && library.hasMore() ) {
library.more();
}
}
});

@ -90,24 +90,28 @@ ReplaceImage = Library.extend(/** @lends wp.media.controller.ReplaceImage.protot
* @since 3.9.0
*/
activate: function() {
this.updateSelection();
this.frame.on( 'content:render:browse', this.updateSelection, this );
Library.prototype.activate.apply( this, arguments );
},
/**
* @since 5.9.0
*/
deactivate: function() {
this.frame.off( 'content:render:browse', this.updateSelection, this );
Library.prototype.deactivate.apply( this, arguments );
},
/**
* @since 3.9.0
*/
updateSelection: function() {
var selection = this.get('selection'),
library = this.get('library'),
attachment = this.image.attachment,
infiniteScrolling = wp.media.view.settings.infiniteScrolling;
attachment = this.image.attachment;
selection.reset( attachment ? [ attachment ] : [] );
if ( ! infiniteScrolling && library.getTotalAttachments() === 0 && library.hasMore() ) {
library.more();
}
}
});