var Button = wp.media.view.Button, l10n = wp.media.view.l10n, DeleteSelected; /** * wp.media.view.DeleteSelectedButton * * A button that handles bulk Delete/Trash logic * * @memberOf wp.media.view * * @class * @augments wp.media.view.Button * @augments wp.media.View * @augments wp.Backbone.View * @augments Backbone.View */ DeleteSelected = Button.extend(/** @lends wp.media.view.DeleteSelectedButton.prototype */{ initialize: function() { Button.prototype.initialize.apply( this, arguments ); if ( this.options.filters ) { this.options.filters.model.on( 'change', this.filterChange, this ); } this.controller.on( 'selection:toggle', this.toggleDisabled, this ); this.controller.on( 'select:activate', this.toggleDisabled, this ); }, filterChange: function( model ) { if ( 'trash' === model.get( 'status' ) ) { this.model.set( 'text', l10n.restoreSelected ); } else if ( wp.media.view.settings.mediaTrash ) { this.model.set( 'text', l10n.trashSelected ); } else { this.model.set( 'text', l10n.deletePermanently ); } }, toggleDisabled: function() { this.model.set( 'disabled', ! this.controller.state().get( 'selection' ).length ); }, render: function() { Button.prototype.render.apply( this, arguments ); if ( this.controller.isModeActive( 'select' ) ) { this.$el.addClass( 'delete-selected-button' ); } else { this.$el.addClass( 'delete-selected-button hidden' ); } this.toggleDisabled(); return this; } }); module.exports = DeleteSelected;