Make WordPress Core

Changeset 29076


Ignore:
Timestamp:
07/10/2014 07:38:56 PM (10 years ago)
Author:
wonderboymusic
Message:

Media Grid: decouple the Grid and Edit modal frames. Next steps: we shouldn't have to reload the frame while paginating.
See #24716.

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

Legend:

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

    r29074 r29076  
    217217            // Handle a frame-level event for editing an attachment.
    218218            this.on( 'edit:attachment', this.editAttachment, this );
    219             this.on( 'edit:attachment:next', this.editNextAttachment, this );
    220             this.on( 'edit:attachment:previous', this.editPreviousAttachment, this );
    221219        },
    222220
    223221        addNewClickHandler: function() {
    224222            this.trigger( 'show:upload:attachment' );
    225         },
    226 
    227         editPreviousAttachment: function( currentModel ) {
    228             var library = this.state().get('library'),
    229                 currentModelIndex = library.indexOf( currentModel );
    230             this.trigger( 'edit:attachment', library.at( currentModelIndex - 1 ) );
    231         },
    232 
    233         editNextAttachment: function( currentModel ) {
    234             var library = this.state().get('library'),
    235                 currentModelIndex = library.indexOf( currentModel );
    236             this.trigger( 'edit:attachment', library.at( currentModelIndex + 1 ) );
    237223        },
    238224
     
    245231
    246232            // Create a new EditAttachment frame, passing along the library and the attachment model.
    247             this.editAttachmentFrame = new media.view.Frame.EditAttachments({
     233            this.editAttachmentFrame = wp.media( {
     234                frame:       'edit-attachments',
    248235                gridRouter:  this.gridRouter,
    249236                library:     library,
    250237                model:       model
    251             });
    252 
    253             // Listen to events on the edit attachment frame for triggering pagination callback handlers.
    254             this.listenTo( this.editAttachmentFrame, 'edit:attachment:next', this.editNextAttachment );
    255             this.listenTo( this.editAttachmentFrame, 'edit:attachment:previous', this.editPreviousAttachment );
     238            } );
     239
    256240            // Listen to keyboard events on the modal
    257241            $( 'body' ).on( 'keydown.media-modal', function( e ) {
     
    386370     * Requires an attachment model to be passed in the options hash under `model`.
    387371     */
    388     media.view.Frame.EditAttachments = media.view.Frame.extend({
     372    media.view.MediaFrame.EditAttachments = media.view.Frame.extend({
    389373
    390374        className: 'edit-attachment-frame',
     
    536520        },
    537521
     522        resetContent: function() {
     523            this.modal.close();
     524            wp.media( {
     525                frame:       'edit-attachments',
     526                gridRouter:  this.gridRouter,
     527                library:     this.library,
     528                model:       this.model
     529            } );
     530        },
     531
    538532        /**
    539533         * Click handler to switch to the previous media item.
     
    543537                return;
    544538            }
    545             this.modal.close();
    546             this.trigger( 'edit:attachment:previous', this.model );
     539            this.model = this.library.at( this.getCurrentIndex() - 1 );
     540            this.resetContent();
    547541        },
    548542
     
    554548                return;
    555549            }
    556             this.modal.close();
    557             this.trigger( 'edit:attachment:next', this.model );
     550            this.model = this.library.at( this.getCurrentIndex() + 1 );
     551            this.resetContent();
    558552        },
    559553
  • trunk/src/wp-includes/js/media-models.js

    r28688 r29076  
    3939        } else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) {
    4040            frame = new MediaFrame.VideoDetails( attributes );
     41        } else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) {
     42            frame = new MediaFrame.EditAttachments( attributes );
    4143        }
    4244
Note: See TracChangeset for help on using the changeset viewer.