diff options
author | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2018-01-24 01:50:07 +0000 |
---|---|---|
committer | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2018-01-24 01:50:07 +0000 |
commit | 1a748ed226246d587e66b33b86d46adb6e6f5d19 (patch) | |
tree | a459b3eb3de662f759d97fe2a31b3fe8cec9ab75 /src/wp-includes/js | |
parent | 818a0f1ccf5e7adff74aaa3337fbedfa488a90cb (diff) | |
download | wordpress-1a748ed226246d587e66b33b86d46adb6e6f5d19.tar.gz wordpress-1a748ed226246d587e66b33b86d46adb6e6f5d19.zip |
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
Diffstat (limited to 'src/wp-includes/js')
-rw-r--r-- | src/wp-includes/js/mediaelement/wp-mediaelement.js | 21 |
1 files changed, 20 insertions, 1 deletions
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 '<a href="' + node.src + '">' + mejsL10n.strings['mejs.download-video'] + '</a>'; + } + }; + // Only initialize new media elements. $( '.wp-audio-shortcode, .wp-video-shortcode' ) .not( '.mejs-container' ) |