2018-01-24 02:51:30 +01:00
|
|
|
/* global _wpmejsSettings, mejsL10n */
|
2015-09-20 05:17:24 +02:00
|
|
|
(function( window, $ ) {
|
|
|
|
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
function wpMediaElement() {
|
2013-08-01 15:15:14 +02:00
|
|
|
var settings = {};
|
|
|
|
|
2015-09-20 05:17:24 +02:00
|
|
|
/**
|
|
|
|
* Initialize media elements.
|
|
|
|
*
|
|
|
|
* Ensures media elements that have already been initialized won't be
|
|
|
|
* processed again.
|
|
|
|
*
|
2017-12-15 14:42:46 +01:00
|
|
|
* @memberOf wp.mediaelement
|
|
|
|
*
|
2015-09-20 05:17:24 +02:00
|
|
|
* @since 4.4.0
|
2017-08-01 06:43:51 +02:00
|
|
|
*
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {void}
|
2015-09-20 05:17:24 +02:00
|
|
|
*/
|
|
|
|
function initialize() {
|
|
|
|
if ( typeof _wpmejsSettings !== 'undefined' ) {
|
2016-01-20 16:47:28 +01:00
|
|
|
settings = $.extend( true, {}, _wpmejsSettings );
|
2015-09-20 05:17:24 +02:00
|
|
|
}
|
2017-08-01 06:43:51 +02:00
|
|
|
settings.classPrefix = 'mejs-';
|
2017-10-16 20:07:52 +02:00
|
|
|
settings.success = settings.success || function ( mejs ) {
|
2015-09-20 05:17:24 +02:00
|
|
|
var autoplay, loop;
|
|
|
|
|
2017-08-01 06:43:51 +02:00
|
|
|
if ( mejs.rendererName && -1 !== mejs.rendererName.indexOf( 'flash' ) ) {
|
2015-09-20 05:17:24 +02:00
|
|
|
autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
|
|
|
|
loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
|
|
|
|
|
2017-08-01 06:43:51 +02:00
|
|
|
if ( autoplay ) {
|
|
|
|
mejs.addEventListener( 'canplay', function() {
|
|
|
|
mejs.play();
|
|
|
|
}, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( loop ) {
|
|
|
|
mejs.addEventListener( 'ended', function() {
|
|
|
|
mejs.play();
|
|
|
|
}, false );
|
|
|
|
}
|
2015-09-20 05:17:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-24 02:51:30 +01:00
|
|
|
/**
|
|
|
|
* Custom error handler.
|
|
|
|
*
|
|
|
|
* Sets up a custom error handler in case a video render fails, and provides a download
|
|
|
|
* link as the fallback.
|
|
|
|
*
|
|
|
|
* @since 4.9.3
|
|
|
|
*
|
|
|
|
* @param {object} media The wrapper that mimics all the native events/properties/methods for all renderers.
|
|
|
|
* @param {object} node The original HTML video, audio, or iframe tag where the media was loaded.
|
2019-11-29 19:01:03 +01:00
|
|
|
* @return {string}
|
2018-01-24 02:51:30 +01:00
|
|
|
*/
|
|
|
|
settings.customError = function ( media, node ) {
|
|
|
|
// Make sure we only fall back to a download link for flash files.
|
|
|
|
if ( -1 !== media.rendererName.indexOf( 'flash' ) || -1 !== media.rendererName.indexOf( 'flv' ) ) {
|
2020-01-21 03:21:05 +01:00
|
|
|
return '<a href="' + node.src + '">' + mejsL10n.strings['mejs.download-file'] + '</a>';
|
2018-01-24 02:51:30 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-20 05:17:24 +02:00
|
|
|
// Only initialize new media elements.
|
|
|
|
$( '.wp-audio-shortcode, .wp-video-shortcode' )
|
|
|
|
.not( '.mejs-container' )
|
|
|
|
.filter(function () {
|
2017-05-12 22:53:45 +02:00
|
|
|
return ! $( this ).parent().hasClass( 'mejs-mediaelement' );
|
2015-09-20 05:17:24 +02:00
|
|
|
})
|
|
|
|
.mediaelementplayer( settings );
|
|
|
|
}
|
2014-05-11 03:28:15 +02:00
|
|
|
|
2015-09-20 05:17:24 +02:00
|
|
|
return {
|
|
|
|
initialize: initialize
|
2014-03-07 06:52:14 +01:00
|
|
|
};
|
2015-09-20 05:17:24 +02:00
|
|
|
}
|
|
|
|
|
2017-12-15 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* @namespace wp.mediaelement
|
|
|
|
* @memberOf wp
|
|
|
|
*/
|
2015-09-20 05:17:24 +02:00
|
|
|
window.wp.mediaelement = new wpMediaElement();
|
2013-08-01 15:15:14 +02:00
|
|
|
|
2016-01-13 18:39:25 +01:00
|
|
|
$( window.wp.mediaelement.initialize );
|
2013-03-16 06:25:44 +01:00
|
|
|
|
2015-09-20 05:17:24 +02:00
|
|
|
})( window, jQuery );
|