]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/mediaelement/wp-mediaelement.js
WordPress 4.4
[autoinstalls/wordpress.git] / wp-includes / js / mediaelement / wp-mediaelement.js
index 8c4364aa329a23bcccd9a38c992490f80ff3b09d..fe47d2f0c129a485024cb5e56c1891e48f039a88 100644 (file)
@@ -1,34 +1,61 @@
 /* global mejs, _wpmejsSettings */
-(function ($) {
+(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 = _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;
+               /**
+                * 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;
+                       }
 
-                               autoplay && mejs.addEventListener( 'canplay', function () {
-                                       mejs.play();
-                               }, false );
+                       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 );
+               }
 
-                               loop && mejs.addEventListener( 'ended', function () {
-                                       mejs.play();
-                               }, false );
-                       }
+               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 );