home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / js / mediaelement / wp-mediaelement.js < prev    next >
Encoding:
JavaScript  |  2018-01-23  |  2.2 KB  |  83 lines

  1. /* global _wpmejsSettings, mejsL10n */
  2. (function( window, $ ) {
  3.  
  4.     window.wp = window.wp || {};
  5.  
  6.     function wpMediaElement() {
  7.         var settings = {};
  8.  
  9.         /**
  10.          * Initialize media elements.
  11.          *
  12.          * Ensures media elements that have already been initialized won't be
  13.          * processed again.
  14.          *
  15.          * @since 4.4.0
  16.          *
  17.          * @returns {void}
  18.          */
  19.         function initialize() {
  20.             if ( typeof _wpmejsSettings !== 'undefined' ) {
  21.                 settings = $.extend( true, {}, _wpmejsSettings );
  22.             }
  23.             settings.classPrefix = 'mejs-';
  24.             settings.success = settings.success || function ( mejs ) {
  25.                 var autoplay, loop;
  26.  
  27.                 if ( mejs.rendererName && -1 !== mejs.rendererName.indexOf( 'flash' ) ) {
  28.                     autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
  29.                     loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
  30.  
  31.                     if ( autoplay ) {
  32.                         mejs.addEventListener( 'canplay', function() {
  33.                             mejs.play();
  34.                         }, false );
  35.                     }
  36.  
  37.                     if ( loop ) {
  38.                         mejs.addEventListener( 'ended', function() {
  39.                             mejs.play();
  40.                         }, false );
  41.                     }
  42.                 }
  43.             };
  44.  
  45.             /**
  46.              * Custom error handler.
  47.              *
  48.              * Sets up a custom error handler in case a video render fails, and provides a download
  49.              * link as the fallback.
  50.              *
  51.              * @since 4.9.3
  52.              *
  53.              * @param {object} media The wrapper that mimics all the native events/properties/methods for all renderers.
  54.              * @param {object} node  The original HTML video, audio, or iframe tag where the media was loaded.
  55.              * @returns {string}
  56.              */
  57.             settings.customError = function ( media, node ) {
  58.                 // Make sure we only fall back to a download link for flash files.
  59.                 if ( -1 !== media.rendererName.indexOf( 'flash' ) || -1 !== media.rendererName.indexOf( 'flv' ) ) {
  60.                     return '<a href="' + node.src + '">' + mejsL10n.strings['mejs.download-video'] + '</a>';
  61.                 }
  62.             };
  63.  
  64.             // Only initialize new media elements.
  65.             $( '.wp-audio-shortcode, .wp-video-shortcode' )
  66.                 .not( '.mejs-container' )
  67.                 .filter(function () {
  68.                     return ! $( this ).parent().hasClass( 'mejs-mediaelement' );
  69.                 })
  70.                 .mediaelementplayer( settings );
  71.         }
  72.  
  73.         return {
  74.             initialize: initialize
  75.         };
  76.     }
  77.  
  78.     window.wp.mediaelement = new wpMediaElement();
  79.  
  80.     $( window.wp.mediaelement.initialize );
  81.  
  82. })( window, jQuery );
  83.