Make WordPress Core

Changeset 42583


Ignore:
Timestamp:
01/24/2018 01:52:17 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Media: Introduce a custom error handler for MediaElement.js to display a download link if a FLV file cannot be rendered for any reason.

Props Clorith.
Merges [42582] to the 4.9 branch.
Fixes #42643.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/js/mediaelement/wp-mediaelement.js

    r41877 r42583  
    1 /* global _wpmejsSettings */
     1/* global _wpmejsSettings, mejsL10n */
    22(function( window, $ ) {
    33
     
    4343            };
    4444
     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
    4564            // Only initialize new media elements.
    4665            $( '.wp-audio-shortcode, .wp-video-shortcode' )
Note: See TracChangeset for help on using the changeset viewer.