Make WordPress Core

Changeset 42582 for trunk


Ignore:
Timestamp:
01/24/2018 01:50:07 AM (8 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.
Fixes #42643.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/mediaelement/wp-mediaelement.js

    r42403 r42582  
    1 /* global _wpmejsSettings */
     1/* global _wpmejsSettings, mejsL10n */
    22(function( window, $ ) {
    33
     
    4545                        };
    4646
     47                        /**
     48                         * Custom error handler.
     49                         *
     50                         * Sets up a custom error handler in case a video render fails, and provides a download
     51                         * link as the fallback.
     52                         *
     53                         * @since 4.9.3
     54                         *
     55                         * @param {object} media The wrapper that mimics all the native events/properties/methods for all renderers.
     56                         * @param {object} node  The original HTML video, audio, or iframe tag where the media was loaded.
     57                         * @returns {string}
     58                         */
     59                        settings.customError = function ( media, node ) {
     60                                // Make sure we only fall back to a download link for flash files.
     61                                if ( -1 !== media.rendererName.indexOf( 'flash' ) || -1 !== media.rendererName.indexOf( 'flv' ) ) {
     62                                        return '<a href="' + node.src + '">' + mejsL10n.strings['mejs.download-video'] + '</a>';
     63                                }
     64                        };
     65
    4766                        // Only initialize new media elements.
    4867                        $( '.wp-audio-shortcode, .wp-video-shortcode' )
Note: See TracChangeset for help on using the changeset viewer.