mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-18 16:45:31 +01:00
b20e8dbf69
* create a public `initialize` method on the `wp.mediaelement` namespace * make it idempotent to prevent nasty side-effects caused by initializing media elements more than once Props bradyvercher. Fixes #32423. Built from https://develop.svn.wordpress.org/trunk@34346 git-svn-id: http://core.svn.wordpress.org/trunk@34310 1a063a9b-81f0-0310-95a4-ce76da25c4cd
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/* global mejs, _wpmejsSettings */
|
|
(function( window, $ ) {
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
// add mime-type aliases to MediaElement plugin support
|
|
mejs.plugins.silverlight[0].types.push('video/x-ms-wmv');
|
|
mejs.plugins.silverlight[0].types.push('audio/x-ms-wma');
|
|
|
|
function wpMediaElement() {
|
|
var settings = {};
|
|
|
|
/**
|
|
* Initialize media elements.
|
|
*
|
|
* Ensures media elements that have already been initialized won't be
|
|
* processed again.
|
|
*
|
|
* @since 4.4.0
|
|
*/
|
|
function initialize() {
|
|
if ( typeof _wpmejsSettings !== 'undefined' ) {
|
|
settings = _wpmejsSettings;
|
|
}
|
|
|
|
settings.success = settings.success || function (mejs) {
|
|
var autoplay, loop;
|
|
|
|
if ( 'flash' === mejs.pluginType ) {
|
|
autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
|
|
loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
|
|
|
|
autoplay && mejs.addEventListener( 'canplay', function () {
|
|
mejs.play();
|
|
}, false );
|
|
|
|
loop && mejs.addEventListener( 'ended', function () {
|
|
mejs.play();
|
|
}, false );
|
|
}
|
|
};
|
|
|
|
// Only initialize new media elements.
|
|
$( '.wp-audio-shortcode, .wp-video-shortcode' )
|
|
.not( '.mejs-container' )
|
|
.filter(function () {
|
|
return ! $( this ).parent().hasClass( '.mejs-mediaelement' );
|
|
})
|
|
.mediaelementplayer( settings );
|
|
}
|
|
|
|
return {
|
|
initialize: initialize
|
|
};
|
|
}
|
|
|
|
window.wp.mediaelement = new wpMediaElement();
|
|
|
|
$( document ).on( 'ready', window.wp.mediaelement.initialize );
|
|
|
|
})( window, jQuery );
|