]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/mediaelement/wp-mediaelement.js
WordPress 4.5
[autoinstalls/wordpress.git] / wp-includes / js / mediaelement / wp-mediaelement.js
1 /* global mejs, _wpmejsSettings */
2 (function( window, $ ) {
3
4         window.wp = window.wp || {};
5
6         // add mime-type aliases to MediaElement plugin support
7         mejs.plugins.silverlight[0].types.push('video/x-ms-wmv');
8         mejs.plugins.silverlight[0].types.push('audio/x-ms-wma');
9
10         function wpMediaElement() {
11                 var settings = {};
12
13                 /**
14                  * Initialize media elements.
15                  *
16                  * Ensures media elements that have already been initialized won't be
17                  * processed again.
18                  *
19                  * @since 4.4.0
20                  */
21                 function initialize() {
22                         if ( typeof _wpmejsSettings !== 'undefined' ) {
23                                 settings = $.extend( true, {}, _wpmejsSettings );
24                         }
25
26                         settings.success = settings.success || function (mejs) {
27                                 var autoplay, loop;
28
29                                 if ( 'flash' === mejs.pluginType ) {
30                                         autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
31                                         loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
32
33                                         autoplay && mejs.addEventListener( 'canplay', function () {
34                                                 mejs.play();
35                                         }, false );
36
37                                         loop && mejs.addEventListener( 'ended', function () {
38                                                 mejs.play();
39                                         }, false );
40                                 }
41                         };
42
43                         // Only initialize new media elements.
44                         $( '.wp-audio-shortcode, .wp-video-shortcode' )
45                                 .not( '.mejs-container' )
46                                 .filter(function () {
47                                         return ! $( this ).parent().hasClass( '.mejs-mediaelement' );
48                                 })
49                                 .mediaelementplayer( settings );
50                 }
51
52                 return {
53                         initialize: initialize
54                 };
55         }
56
57         window.wp.mediaelement = new wpMediaElement();
58
59         $( window.wp.mediaelement.initialize );
60
61 })( window, jQuery );