Media Grid: Manage focus when toggling between the grid and an edit attachment modal
Props adamsilverstein for the initial patch. Fixes #28857. git-svn-id: https://develop.svn.wordpress.org/trunk@29282 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2fd45b514b
commit
abc6b8c1d7
@ -170,11 +170,12 @@
|
||||
/**
|
||||
* Open the Edit Attachment modal.
|
||||
*/
|
||||
openEditAttachmentModal: function( model ) {
|
||||
openEditAttachmentModal: function( model, currentTarget ) {
|
||||
// Create a new EditAttachment frame, passing along the library and the attachment model.
|
||||
wp.media( {
|
||||
frame: 'edit-attachments',
|
||||
gridRouter: this.gridRouter,
|
||||
gridItem: $( currentTarget ).closest( 'li' ),
|
||||
library: this.state().get('library'),
|
||||
model: model
|
||||
} );
|
||||
@ -367,6 +368,7 @@
|
||||
state: 'edit-attachment'
|
||||
});
|
||||
|
||||
this.gridItem = this.options.gridItem;
|
||||
this.gridRouter = this.options.gridRouter;
|
||||
this.library = this.options.library;
|
||||
if ( this.options.model ) {
|
||||
@ -403,7 +405,8 @@
|
||||
this.modal.on( 'close', function() {
|
||||
self.modal.remove();
|
||||
$( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
|
||||
|
||||
// Restore the original focus item if possible
|
||||
self.gridItem && self.gridItem.focus();
|
||||
self.resetRoute();
|
||||
} );
|
||||
|
||||
|
@ -4760,7 +4760,8 @@
|
||||
|
||||
// In the grid view, bubble up an edit:attachment event to the controller.
|
||||
if ( this.controller.isModeActive( 'grid' ) ) {
|
||||
this.controller.trigger( 'edit:attachment', this.model );
|
||||
// Pass the current target to restore focus when closing
|
||||
this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user