From 1a748ed226246d587e66b33b86d46adb6e6f5d19 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 24 Jan 2018 01:50:07 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@42582 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/mediaelement/wp-mediaelement.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/js/mediaelement/wp-mediaelement.js b/src/wp-includes/js/mediaelement/wp-mediaelement.js index f43c2b8365..dbeed1f5d5 100644 --- a/src/wp-includes/js/mediaelement/wp-mediaelement.js +++ b/src/wp-includes/js/mediaelement/wp-mediaelement.js @@ -1,4 +1,4 @@ -/* global _wpmejsSettings */ +/* global _wpmejsSettings, mejsL10n */ (function( window, $ ) { window.wp = window.wp || {}; @@ -44,6 +44,25 @@ } }; + /** + * Custom error handler. + * + * Sets up a custom error handler in case a video render fails, and provides a download + * link as the fallback. + * + * @since 4.9.3 + * + * @param {object} media The wrapper that mimics all the native events/properties/methods for all renderers. + * @param {object} node The original HTML video, audio, or iframe tag where the media was loaded. + * @returns {string} + */ + settings.customError = function ( media, node ) { + // Make sure we only fall back to a download link for flash files. + if ( -1 !== media.rendererName.indexOf( 'flash' ) || -1 !== media.rendererName.indexOf( 'flv' ) ) { + return '' + mejsL10n.strings['mejs.download-video'] + ''; + } + }; + // Only initialize new media elements. $( '.wp-audio-shortcode, .wp-video-shortcode' ) .not( '.mejs-container' )