Media Grid: Manage focus when toggling between the grid and an edit attachment modal
Props adamsilverstein for the initial patch. Fixes #28857. Built from https://develop.svn.wordpress.org/trunk@29282 git-svn-id: http://core.svn.wordpress.org/trunk@29064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6f44e96d70
commit
5be43cfeb1
|
@ -170,11 +170,12 @@
|
||||||
/**
|
/**
|
||||||
* Open the Edit Attachment modal.
|
* 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.
|
// Create a new EditAttachment frame, passing along the library and the attachment model.
|
||||||
wp.media( {
|
wp.media( {
|
||||||
frame: 'edit-attachments',
|
frame: 'edit-attachments',
|
||||||
gridRouter: this.gridRouter,
|
gridRouter: this.gridRouter,
|
||||||
|
gridItem: $( currentTarget ).closest( 'li' ),
|
||||||
library: this.state().get('library'),
|
library: this.state().get('library'),
|
||||||
model: model
|
model: model
|
||||||
} );
|
} );
|
||||||
|
@ -367,6 +368,7 @@
|
||||||
state: 'edit-attachment'
|
state: 'edit-attachment'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.gridItem = this.options.gridItem;
|
||||||
this.gridRouter = this.options.gridRouter;
|
this.gridRouter = this.options.gridRouter;
|
||||||
this.library = this.options.library;
|
this.library = this.options.library;
|
||||||
if ( this.options.model ) {
|
if ( this.options.model ) {
|
||||||
|
@ -403,7 +405,8 @@
|
||||||
this.modal.on( 'close', function() {
|
this.modal.on( 'close', function() {
|
||||||
self.modal.remove();
|
self.modal.remove();
|
||||||
$( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
|
$( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
|
||||||
|
// Restore the original focus item if possible
|
||||||
|
self.gridItem && self.gridItem.focus();
|
||||||
self.resetRoute();
|
self.resetRoute();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4760,7 +4760,8 @@
|
||||||
|
|
||||||
// In the grid view, bubble up an edit:attachment event to the controller.
|
// In the grid view, bubble up an edit:attachment event to the controller.
|
||||||
if ( this.controller.isModeActive( 'grid' ) ) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue