diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 60261ef4b3..c23d1350f1 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -303,6 +303,35 @@ // Update the selection. this.model.on( 'add', this.select, this ); this.model.on( 'remove', this.deselect, this ); + this.model.on( 'sync', this.afterDelete, this ); + }, + + deleteAttachment: function( event ) { + event.preventDefault(); + + this.lastIndex = this.controller.getCurrentIndex(); + this.hasNext = this.controller.hasNext(); + + media.view.Attachment.Details.prototype.deleteAttachment.apply( this, arguments ); + }, + + afterDelete: function( model ) { + if ( ! model.destroyed ) { + return; + } + + var frame = this.controller, index = this.lastIndex; + + if ( ! frame.library.length ) { + media.frame.modal.close(); + return; + } + + if ( this.hasNext ) { + index -= 1; + } + frame.model = frame.library.at( index ); + frame.nextMediaItem(); }, render: function() { diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php index 6830bfe9e8..e730d4ab7c 100644 --- a/src/wp-includes/media-template.php +++ b/src/wp-includes/media-template.php @@ -290,11 +290,6 @@ function wp_print_media_templates() { <# if ( data.width && data.height ) { #>