Make WordPress Core

Changeset 29282


Ignore:
Timestamp:
07/24/2014 07:04:48 PM (10 years ago)
Author:
wonderboymusic
Message:

Media Grid: Manage focus when toggling between the grid and an edit attachment modal

Props adamsilverstein for the initial patch.
Fixes #28857.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-grid.js

    r29278 r29282  
    171171         * Open the Edit Attachment modal.
    172172         */
    173         openEditAttachmentModal: function( model ) {
     173        openEditAttachmentModal: function( model, currentTarget ) {
    174174            // Create a new EditAttachment frame, passing along the library and the attachment model.
    175175            wp.media( {
    176176                frame:       'edit-attachments',
    177177                gridRouter:  this.gridRouter,
     178                gridItem:    $( currentTarget ).closest( 'li' ),
    178179                library:     this.state().get('library'),
    179180                model:       model
     
    368369            });
    369370
     371            this.gridItem = this.options.gridItem;
    370372            this.gridRouter = this.options.gridRouter;
    371373            this.library = this.options.library;
     
    404406                    self.modal.remove();
    405407                    $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    406 
     408                    // Restore the original focus item if possible
     409                    self.gridItem && self.gridItem.focus();
    407410                    self.resetRoute();
    408411                } );
  • trunk/src/wp-includes/js/media-views.js

    r29278 r29282  
    47614761            // In the grid view, bubble up an edit:attachment event to the controller.
    47624762            if ( this.controller.isModeActive( 'grid' ) ) {
    4763                 this.controller.trigger( 'edit:attachment', this.model );
     4763                // Pass the current target to restore focus when closing
     4764                this.controller.trigger( 'edit:attachment', this.model, event.currentTarget );
    47644765                return;
    47654766            }
Note: See TracChangeset for help on using the changeset viewer.