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:
Scott Taylor 2014-07-24 19:05:15 +00:00
parent 6f44e96d70
commit 5be43cfeb1
4 changed files with 9 additions and 5 deletions

View File

@ -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();
} );

File diff suppressed because one or more lines are too long

View File

@ -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;
}

File diff suppressed because one or more lines are too long