mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-10 22:58:33 +02:00
See #28510. Built from https://develop.svn.wordpress.org/trunk@31491 git-svn-id: http://core.svn.wordpress.org/trunk@31472 1a063a9b-81f0-0310-95a4-ce76da25c4cd
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
/*globals _ */
|
|
|
|
/**
|
|
* wp.media.selectionSync
|
|
*
|
|
* Sync an attachments selection in a state with another state.
|
|
*
|
|
* Allows for selecting multiple images in the Insert Media workflow, and then
|
|
* switching to the Insert Gallery workflow while preserving the attachments selection.
|
|
*
|
|
* @mixin
|
|
*/
|
|
var selectionSync = {
|
|
/**
|
|
* @since 3.5.0
|
|
*/
|
|
syncSelection: function() {
|
|
var selection = this.get('selection'),
|
|
manager = this.frame._selection;
|
|
|
|
if ( ! this.get('syncSelection') || ! manager || ! selection ) {
|
|
return;
|
|
}
|
|
|
|
// If the selection supports multiple items, validate the stored
|
|
// attachments based on the new selection's conditions. Record
|
|
// the attachments that are not included; we'll maintain a
|
|
// reference to those. Other attachments are considered in flux.
|
|
if ( selection.multiple ) {
|
|
selection.reset( [], { silent: true });
|
|
selection.validateAll( manager.attachments );
|
|
manager.difference = _.difference( manager.attachments.models, selection.models );
|
|
}
|
|
|
|
// Sync the selection's single item with the master.
|
|
selection.single( manager.single );
|
|
},
|
|
|
|
/**
|
|
* Record the currently active attachments, which is a combination
|
|
* of the selection's attachments and the set of selected
|
|
* attachments that this specific selection considered invalid.
|
|
* Reset the difference and record the single attachment.
|
|
*
|
|
* @since 3.5.0
|
|
*/
|
|
recordSelection: function() {
|
|
var selection = this.get('selection'),
|
|
manager = this.frame._selection;
|
|
|
|
if ( ! this.get('syncSelection') || ! manager || ! selection ) {
|
|
return;
|
|
}
|
|
|
|
if ( selection.multiple ) {
|
|
manager.attachments.reset( selection.toArray().concat( manager.difference ) );
|
|
manager.difference = [];
|
|
} else {
|
|
manager.attachments.add( selection.toArray() );
|
|
}
|
|
|
|
manager.single = selection._single;
|
|
}
|
|
};
|
|
|
|
module.exports = selectionSync;
|