Make WordPress Core

Changeset 27538


Ignore:
Timestamp:
03/14/2014 01:47:24 PM (8 years ago)
Author:
wonderboymusic
Message:

Move removePlayer() and unsetPlayer() to wp.media.mixin so that other classes can take advantage of them.

  • removePlayer() is an alternative to MediaElement's player removal method that does not re-add the audio|video element back to the DOM.
  • unsetPlayer() will check for an existing player property on the passed instance and pause all players before calling unsetPlayer()

See #27389.

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

Legend:

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

    r27537 r27538  
    305305                    window.mejs.players[p].pause();
    306306                }
     307            }
     308        },
     309
     310        /**
     311         * Override the MediaElement method for removing a player.
     312         *  MediaElement tries to pull the audio/video tag out of
     313         *  its container and re-add it to the DOM.
     314         */
     315        removePlayer: function() {
     316            var t = this.player, featureIndex, feature;
     317
     318            // invoke features cleanup
     319            for ( featureIndex in t.options.features ) {
     320                feature = t.options.features[featureIndex];
     321                if ( t['clean' + feature] ) {
     322                    try {
     323                        t['clean' + feature](t);
     324                    } catch (e) {}
     325                }
     326            }
     327
     328            if ( ! t.isDynamic ) {
     329                t.$node.remove();
     330            }
     331
     332            if ( 'native' !== t.media.pluginType ) {
     333                t.media.remove();
     334            }
     335
     336            delete window.mejs.players[t.id];
     337
     338            t.container.remove();
     339            t.globalUnbind();
     340            delete t.node.player;
     341        },
     342
     343        /**
     344         * Allows any class that has set 'player' to a MediaElementPlayer
     345         *  instance to remove the player when listening to events.
     346         *
     347         *  Examples: modal closes, shortcode properties are removed, etc.
     348         */
     349        unsetPlayer : function() {
     350            if ( this.player ) {
     351                wp.media.mixin.pauseAllPlayers();
     352                wp.media.mixin.removePlayer.apply( this );
     353                this.player = false;
    307354            }
    308355        }
  • trunk/src/wp-includes/js/media-views.js

    r27535 r27538  
    65486548    media.view.MediaDetails = media.view.Settings.AttachmentDisplay.extend({
    65496549        initialize: function() {
    6550             _.bindAll(this, 'success', 'unsetPlayer');
    6551 
    6552             this.listenTo( this.controller, 'close', this.unsetPlayer );
     6550            _.bindAll(this, 'success');
     6551
     6552            this.listenTo( this.controller, 'close', media.mixin.unsetPlayer );
    65536553            this.on( 'ready', this.setPlayer );
    6554             this.on( 'media:setting:remove', this.unsetPlayer );
     6554            this.on( 'media:setting:remove', media.mixin.unsetPlayer, this );
    65556555            this.on( 'media:setting:remove', this.render );
    65566556            this.on( 'media:setting:remove', this.setPlayer );
     
    66056605        setMedia : function () {
    66066606            return this;
    6607         },
    6608 
    6609         /**
    6610          * Override the MediaElement method for removing a player.
    6611          *  MediaElement tries to pull the audio/video tag out of
    6612          *  its container and re-add it to the DOM.
    6613          */
    6614         removePlayer: function() {
    6615             var t = this.player, featureIndex, feature;
    6616 
    6617             // invoke features cleanup
    6618             for ( featureIndex in t.options.features ) {
    6619                 feature = t.options.features[featureIndex];
    6620                 if ( t['clean' + feature] ) {
    6621                     try {
    6622                         t['clean' + feature](t);
    6623                     } catch (e) {}
    6624                 }
    6625             }
    6626 
    6627             if ( ! t.isDynamic ) {
    6628                 t.$node.remove();
    6629             }
    6630 
    6631             if ( 'native' !== t.media.pluginType ) {
    6632                 t.media.remove();
    6633             }
    6634 
    6635             delete window.mejs.players[t.id];
    6636 
    6637             t.container.remove();
    6638             t.globalUnbind();
    6639             delete t.node.player;
    6640         },
    6641 
    6642         unsetPlayer : function() {
    6643             if ( this.player ) {
    6644                 if ( _.isUndefined( this.mejs.pluginType ) ) {
    6645                     this.mejs.pause();
    6646                 }
    6647                 this.removePlayer();
    6648                 this.player = false;
    6649             }
    66506607        },
    66516608
Note: See TracChangeset for help on using the changeset viewer.