Make WordPress Core

Ticket #36916: media-grid.js.patch

File media-grid.js.patch, 2.7 KB (added by Funkatronic, 7 years ago)

Decoupled EditAttachment and Manage frames

  • media-grid.js

     
    118118        toggleSelectionHandler: function() {},
    119119
    120120        render: function() {
    121                 Details.prototype.render.apply( this, arguments );
     121                var that = this;
     122                wp.media.view.Attachment.Details.prototype.render.apply( this, arguments );
     123                this.players = this.players || [];
    122124
    123                 wp.media.mixin.removeAllPlayers();
    124                 this.$( 'audio, video' ).each( function (i, elem) {
     125                wp.media.mixin.unsetPlayers.call( this );
     126
     127                this.$( 'audio, video' ).each( function ( i, elem ) {
    125128                        var el = wp.media.view.MediaDetails.prepareSrc( elem );
    126                         new window.MediaElementPlayer( el, wp.media.mixin.mejsSettings );
     129                        that.players.push( new window.MediaElementPlayer( el, wp.media.mixin.mejsSettings ) );
    127130                } );
    128131        }
    129132});
     
    382385                });
    383386
    384387                this.controller = this.options.controller;
    385                 this.gridRouter = this.controller.gridRouter;
    386388                this.library = this.options.library;
    387389
    388390                if ( this.options.model ) {
     
    428430                                $( 'body' ).off( 'keydown.media-modal' ); /* remove the keydown event */
    429431                                // Restore the original focus item if possible
    430432                                $( 'li.attachment[data-id="' + this.model.get( 'id' ) +'"]' ).focus();
    431                                 this.resetRoute();
    432433                        }, this ) );
    433434
    434435                        // Set this frame as the modal's content.
     
    466467                        controller: this,
    467468                        model:      this.model
    468469                }) );
    469 
    470                 // Update browser url when navigating media details
    471                 if ( this.model ) {
    472                         this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this.model.id ) );
    473                 }
    474470        },
    475471
    476472        /**
     
    573569                if ( 37 === event.keyCode ) {
    574570                        this.previousMediaItem();
    575571                }
    576         },
    577 
    578         resetRoute: function() {
    579                 this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) );
    580572        }
    581573});
    582574
     
    780772         * Open the Edit Attachment modal.
    781773         */
    782774        openEditAttachmentModal: function( model ) {
    783                 // Create a new EditAttachment frame, passing along the library and the attachment model.
    784                 wp.media( {
     775                this._frame = wp.media( {
    785776                        frame:       'edit-attachments',
    786777                        controller:  this,
    787778                        library:     this.state().get('library'),
    788779                        model:       model
    789780                } );
     781
     782                this._frame.modal.on( 'close', this.resetRoute, this );
     783                this._frame.on( 'content:create:edit-metadata', this.setRoute, this );
    790784        },
    791785
    792786        /**
     
    845839                                pushState: true
    846840                        } );
    847841                }
     842        },
     843
     844        resetRoute: function() {
     845                this.gridRouter.navigate( this.gridRouter.baseUrl( '' ) );
     846        },
     847
     848        setRoute: function() {
     849                // Update browser url when navigating media details
     850                if ( this._frame.model ) {
     851                        this.gridRouter.navigate( this.gridRouter.baseUrl( '?item=' + this._frame.model.id ) );
     852                }
    848853        }
    849854});
    850855