From abc6b8c1d734510075e190436610f1bc11228cb0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 24 Jul 2014 19:04:48 +0000 Subject: [PATCH] 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 --- src/wp-includes/js/media-grid.js | 7 +++++-- src/wp-includes/js/media-views.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 82d500b95e..9a37df0eb0 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -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(); } ); diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index f034d2047b..25ea293184 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -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; }