mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-30 23:39:42 +01:00
9737acc1a5
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
86 lines
2.0 KiB
JavaScript
86 lines
2.0 KiB
JavaScript
/*globals wp, _, Backbone */
|
|
|
|
/**
|
|
* wp.media.view.Selection
|
|
*
|
|
* @class
|
|
* @augments wp.media.View
|
|
* @augments wp.Backbone.View
|
|
* @augments Backbone.View
|
|
*/
|
|
var View = require( './view.js' ),
|
|
AttachmentsSelection = require( './attachments/selection.js' ),
|
|
l10n = wp.media.view.l10n,
|
|
Selection;
|
|
|
|
Selection = View.extend({
|
|
tagName: 'div',
|
|
className: 'media-selection',
|
|
template: wp.template('media-selection'),
|
|
|
|
events: {
|
|
'click .edit-selection': 'edit',
|
|
'click .clear-selection': 'clear'
|
|
},
|
|
|
|
initialize: function() {
|
|
_.defaults( this.options, {
|
|
editable: false,
|
|
clearable: true
|
|
});
|
|
|
|
/**
|
|
* @member {wp.media.view.Attachments.Selection}
|
|
*/
|
|
this.attachments = new AttachmentsSelection({
|
|
controller: this.controller,
|
|
collection: this.collection,
|
|
selection: this.collection,
|
|
model: new Backbone.Model()
|
|
});
|
|
|
|
this.views.set( '.selection-view', this.attachments );
|
|
this.collection.on( 'add remove reset', this.refresh, this );
|
|
this.controller.on( 'content:activate', this.refresh, this );
|
|
},
|
|
|
|
ready: function() {
|
|
this.refresh();
|
|
},
|
|
|
|
refresh: function() {
|
|
// If the selection hasn't been rendered, bail.
|
|
if ( ! this.$el.children().length ) {
|
|
return;
|
|
}
|
|
|
|
var collection = this.collection,
|
|
editing = 'edit-selection' === this.controller.content.mode();
|
|
|
|
// If nothing is selected, display nothing.
|
|
this.$el.toggleClass( 'empty', ! collection.length );
|
|
this.$el.toggleClass( 'one', 1 === collection.length );
|
|
this.$el.toggleClass( 'editing', editing );
|
|
|
|
this.$('.count').text( l10n.selected.replace('%d', collection.length) );
|
|
},
|
|
|
|
edit: function( event ) {
|
|
event.preventDefault();
|
|
if ( this.options.editable ) {
|
|
this.options.editable.call( this, this.collection );
|
|
}
|
|
},
|
|
|
|
clear: function( event ) {
|
|
event.preventDefault();
|
|
this.collection.reset();
|
|
|
|
// Keep focus inside media modal
|
|
// after clear link is selected
|
|
this.controller.modal.focusManager.focus();
|
|
}
|
|
});
|
|
|
|
module.exports = Selection;
|