Rather than extending wp.media.mixin, only borrow coerce when necessary in wp.media.audio|video|collection. wp.media.mixin will make sense to be mixed in for classes that expect to interact with the player. More universal methods can be added and inherited by all those who extend their prototype with it.

Assuming someone had implemented players in the editor, pause all players when switching between editor tabs. A method, `pauseAllPlayers`, has been added to `wp.media.mixin`.

See #27389.



git-svn-id: https://develop.svn.wordpress.org/trunk@27537 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-03-14 13:16:07 +00:00
parent 5e1e5c53ec
commit 3d244e1fed

View File

@ -296,13 +296,23 @@
attrs[ key ] = false; attrs[ key ] = false;
} }
return attrs[ key ]; return attrs[ key ];
},
pauseAllPlayers: function () {
var p;
if ( window.mejs && window.mejs.players ) {
for ( p in window.mejs.players ) {
window.mejs.players[p].pause();
}
}
} }
}; };
wp.media.collection = function(attributes) { wp.media.collection = function(attributes) {
var collections = {}; var collections = {};
return _.extend( attributes, wp.media.mixin, { return _.extend( attributes, {
coerce : wp.media.mixin.coerce,
/** /**
* Retrieve attachments based on the properties of the passed shortcode * Retrieve attachments based on the properties of the passed shortcode
* *
@ -558,7 +568,9 @@
/** /**
* @namespace * @namespace
*/ */
wp.media.audio = _.extend({ wp.media.audio = {
coerce : wp.media.mixin.coerce,
defaults : { defaults : {
id : wp.media.view.settings.post.id, id : wp.media.view.settings.post.id,
src : '', src : '',
@ -597,12 +609,14 @@
attrs: shortcode attrs: shortcode
}); });
} }
}, wp.media.mixin); };
/** /**
* @namespace * @namespace
*/ */
wp.media.video = _.extend({ wp.media.video = {
coerce : wp.media.mixin.coerce,
defaults : { defaults : {
id : wp.media.view.settings.post.id, id : wp.media.view.settings.post.id,
src : '', src : '',
@ -649,7 +663,7 @@
content: content content: content
}); });
} }
}, wp.media.mixin); };
/** /**
* wp.media.featuredImage * wp.media.featuredImage
@ -1111,7 +1125,8 @@
* @global wp.media.view.l10n * @global wp.media.view.l10n
*/ */
init: function() { init: function() {
$(document.body).on( 'click', '.insert-media', function( event ) { $(document.body)
.on( 'click', '.insert-media', function( event ) {
var elem = $( event.currentTarget ), var elem = $( event.currentTarget ),
editor = elem.data('editor'), editor = elem.data('editor'),
options = { options = {
@ -1142,7 +1157,8 @@
} }
wp.media.editor.open( editor, options ); wp.media.editor.open( editor, options );
}); })
.on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers );
// Initialize and render the Editor drag-and-drop uploader. // Initialize and render the Editor drag-and-drop uploader.
new wp.media.view.EditorUploader().render(); new wp.media.view.EditorUploader().render();