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.


Built from https://develop.svn.wordpress.org/trunk@27537


git-svn-id: http://core.svn.wordpress.org/trunk@27380 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-03-14 13:17:16 +00:00
parent 608177d39b
commit 9432aaca82
2 changed files with 50 additions and 34 deletions

View File

@ -296,13 +296,23 @@
attrs[ key ] = false;
}
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) {
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
*
@ -558,7 +568,9 @@
/**
* @namespace
*/
wp.media.audio = _.extend({
wp.media.audio = {
coerce : wp.media.mixin.coerce,
defaults : {
id : wp.media.view.settings.post.id,
src : '',
@ -597,12 +609,14 @@
attrs: shortcode
});
}
}, wp.media.mixin);
};
/**
* @namespace
*/
wp.media.video = _.extend({
wp.media.video = {
coerce : wp.media.mixin.coerce,
defaults : {
id : wp.media.view.settings.post.id,
src : '',
@ -649,7 +663,7 @@
content: content
});
}
}, wp.media.mixin);
};
/**
* wp.media.featuredImage
@ -1111,38 +1125,40 @@
* @global wp.media.view.l10n
*/
init: function() {
$(document.body).on( 'click', '.insert-media', function( event ) {
var elem = $( event.currentTarget ),
editor = elem.data('editor'),
options = {
frame: 'post',
state: 'insert',
title: wp.media.view.l10n.addMedia,
multiple: true
};
$(document.body)
.on( 'click', '.insert-media', function( event ) {
var elem = $( event.currentTarget ),
editor = elem.data('editor'),
options = {
frame: 'post',
state: 'insert',
title: wp.media.view.l10n.addMedia,
multiple: true
};
event.preventDefault();
event.preventDefault();
// Remove focus from the `.insert-media` button.
// Prevents Opera from showing the outline of the button
// above the modal.
//
// See: http://core.trac.wordpress.org/ticket/22445
elem.blur();
// Remove focus from the `.insert-media` button.
// Prevents Opera from showing the outline of the button
// above the modal.
//
// See: http://core.trac.wordpress.org/ticket/22445
elem.blur();
if ( elem.hasClass( 'gallery' ) ) {
options.state = 'gallery';
options.title = wp.media.view.l10n.createGalleryTitle;
} else if ( elem.hasClass( 'playlist' ) ) {
options.state = 'playlist';
options.title = wp.media.view.l10n.createPlaylistTitle;
} else if ( elem.hasClass( 'video-playlist' ) ) {
options.state = 'video-playlist';
options.title = wp.media.view.l10n.createVideoPlaylistTitle;
}
if ( elem.hasClass( 'gallery' ) ) {
options.state = 'gallery';
options.title = wp.media.view.l10n.createGalleryTitle;
} else if ( elem.hasClass( 'playlist' ) ) {
options.state = 'playlist';
options.title = wp.media.view.l10n.createPlaylistTitle;
} else if ( elem.hasClass( 'video-playlist' ) ) {
options.state = 'video-playlist';
options.title = wp.media.view.l10n.createVideoPlaylistTitle;
}
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.
new wp.media.view.EditorUploader().render();

File diff suppressed because one or more lines are too long