diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index d619e732c4..2c5df52b99 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -371,7 +371,7 @@ window.wp = window.wp || {}; self = this, frame, data, callback; - wp.media.mixin.pauseAllPlayers(); + $( document ).trigger( 'media:edit' ); data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); frame = media.edit( data ); @@ -407,8 +407,10 @@ window.wp = window.wp || {}; initialize: function( options ) { this.players = []; this.shortcode = options.shortcode; - _.bindAll( this, 'setPlayer' ); - $(this).on( 'ready', this.setPlayer ); + _.bindAll( this, 'setPlayer', 'pausePlayers' ); + $( this ).on( 'ready', this.setPlayer ); + $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); + $( document ).on( 'media:edit', this.pausePlayers ); }, /** @@ -524,6 +526,10 @@ window.wp = window.wp || {}; this.data = {}; this.attachments = []; this.shortcode = options.shortcode; + + $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers ); + $( document ).on( 'media:edit', this.pausePlayers ); + this.fetch(); }, @@ -687,8 +693,8 @@ window.wp = window.wp || {}; }, unbind: function() { var self = this; - this.pauseAllPlayers(); _.each( this.players, function ( player ) { + player.pause(); self.removePlayer( player ); } ); this.players = []; diff --git a/src/wp-includes/js/media-audiovideo.js b/src/wp-includes/js/media-audiovideo.js index c5b580c513..8af5effa33 100644 --- a/src/wp-includes/js/media-audiovideo.js +++ b/src/wp-includes/js/media-audiovideo.js @@ -26,6 +26,15 @@ } }, + /** + * Pauses the current object's instances of MediaElementPlayer + */ + pausePlayers: function() { + _.each( this.players, function (player) { + player.pause(); + } ); + }, + /** * Utility to identify the user's browser */ @@ -168,8 +177,8 @@ */ unsetPlayers : function() { if ( this.players && this.players.length ) { - wp.media.mixin.pauseAllPlayers(); _.each( this.players, function (player) { + player.pause(); wp.media.mixin.removePlayer( player ); } ); this.players = []; @@ -911,7 +920,6 @@ */ function init() { $(document.body) - .on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers ) .on( 'click', '.add-media-source', function( e ) { media.frame.lastMime = $( e.currentTarget ).data( 'mime' ); media.frame.setState( 'add-' + media.frame.defaults.id + '-source' );