X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..9441756a895fb4fdc4bcf20e0d228cef622663ca:/wp-includes/js/mediaelement/wp-mediaelement.js diff --git a/wp-includes/js/mediaelement/wp-mediaelement.js b/wp-includes/js/mediaelement/wp-mediaelement.js index fb09e3cd..fe47d2f0 100644 --- a/wp-includes/js/mediaelement/wp-mediaelement.js +++ b/wp-includes/js/mediaelement/wp-mediaelement.js @@ -1,15 +1,61 @@ -(function ($) { +/* 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 () { + function wpMediaElement() { var settings = {}; - if ( typeof _wpmejsSettings !== 'undefined' ) - settings.pluginPath = _wpmejsSettings.pluginPath; + /** + * 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(); - $('.wp-audio-shortcode, .wp-video-shortcode').mediaelementplayer( settings ); - }); + $( document ).on( 'ready', window.wp.mediaelement.initialize ); -}(jQuery)); +})( window, jQuery );