mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-26 02:57:45 +01:00
7af3b92736
Props rafa8626, grosbouff, westonruter, azaozz, Plastikschnitzer for testing. See #39686. Built from https://develop.svn.wordpress.org/trunk@41198 git-svn-id: http://core.svn.wordpress.org/trunk@41038 1a063a9b-81f0-0310-95a4-ce76da25c4cd
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
/* global _wpmejsSettings */
|
|
(function( window, $ ) {
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
function wpMediaElement() {
|
|
var settings = {};
|
|
|
|
/**
|
|
* Initialize media elements.
|
|
*
|
|
* Ensures media elements that have already been initialized won't be
|
|
* processed again.
|
|
*
|
|
* @since 4.4.0
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
function initialize() {
|
|
if ( typeof _wpmejsSettings !== 'undefined' ) {
|
|
settings = $.extend( true, {}, _wpmejsSettings );
|
|
}
|
|
settings.classPrefix = 'mejs-';
|
|
settings.success = settings.success || function (mejs) {
|
|
var autoplay, loop;
|
|
|
|
if ( mejs.rendererName && -1 !== mejs.rendererName.indexOf( 'flash' ) ) {
|
|
autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
|
|
loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
|
|
|
|
if ( autoplay ) {
|
|
mejs.addEventListener( 'canplay', function() {
|
|
mejs.play();
|
|
}, false );
|
|
}
|
|
|
|
if ( 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();
|
|
|
|
$( window.wp.mediaelement.initialize );
|
|
|
|
})( window, jQuery );
|