From 0b3802eb12ed6e6be0f3a30567d3b262c8db80e0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 25 Jul 2014 00:59:29 +0000 Subject: [PATCH] Media Grid: when closing the modal, automatically focus the proper attachment by reading the model's ID, which is unique. Props adamsilverstein (for the red), wonderboymusic (for the green). Fixes #28857. git-svn-id: https://develop.svn.wordpress.org/trunk@29299 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-grid.js | 4 +--- src/wp-includes/js/media-views.js | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/js/media-grid.js b/src/wp-includes/js/media-grid.js index 9a37df0eb0..f75499090d 100644 --- a/src/wp-includes/js/media-grid.js +++ b/src/wp-includes/js/media-grid.js @@ -175,7 +175,6 @@ wp.media( { frame: 'edit-attachments', gridRouter: this.gridRouter, - gridItem: $( currentTarget ).closest( 'li' ), library: this.state().get('library'), model: model } ); @@ -368,7 +367,6 @@ state: 'edit-attachment' }); - this.gridItem = this.options.gridItem; this.gridRouter = this.options.gridRouter; this.library = this.options.library; if ( this.options.model ) { @@ -406,7 +404,7 @@ self.modal.remove(); $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */ // Restore the original focus item if possible - self.gridItem && self.gridItem.focus(); + $( 'li.attachment[data-id="' + self.model.get( 'id' ) +'"]' ).focus(); self.resetRoute(); } ); diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 0ad303d458..c62837fada 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -4639,7 +4639,11 @@ options = _.defaults( this.options, { rerenderOnModelChange: true } ); - this.$el.attr( 'aria-label', this.model.get( 'title' ) ).attr( 'aria-checked', false ); + this.$el.attr( { + 'aria-label' : this.model.get( 'title' ), + 'aria-checked': false, + 'data-id' : this.model.get( 'id' ) + } ); if ( options.rerenderOnModelChange ) { this.model.on( 'change', this.render, this );