From 3429cfeabe39f30ec46ca7cca0d6c21e83d41982 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 24 Jan 2018 01:51:30 +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. Built from https://develop.svn.wordpress.org/trunk@42582 git-svn-id: http://core.svn.wordpress.org/trunk@42411 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../js/mediaelement/wp-mediaelement.js | 21 ++++++++++++++++++- .../js/mediaelement/wp-mediaelement.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wp-includes/js/mediaelement/wp-mediaelement.js b/wp-includes/js/mediaelement/wp-mediaelement.js index f43c2b8365..dbeed1f5d5 100644 --- a/wp-includes/js/mediaelement/wp-mediaelement.js +++ b/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' ) diff --git a/wp-includes/js/mediaelement/wp-mediaelement.min.js b/wp-includes/js/mediaelement/wp-mediaelement.min.js index 660f89cdf3..fa5accb58f 100644 --- a/wp-includes/js/mediaelement/wp-mediaelement.min.js +++ b/wp-includes/js/mediaelement/wp-mediaelement.min.js @@ -1 +1 @@ -!function(a,b){function c(){function a(){"undefined"!=typeof _wpmejsSettings&&(c=b.extend(!0,{},_wpmejsSettings)),c.classPrefix="mejs-",c.success=c.success||function(a){var b,c;a.rendererName&&-1!==a.rendererName.indexOf("flash")&&(b=a.attributes.autoplay&&"false"!==a.attributes.autoplay,c=a.attributes.loop&&"false"!==a.attributes.loop,b&&a.addEventListener("canplay",function(){a.play()},!1),c&&a.addEventListener("ended",function(){a.play()},!1))},b(".wp-audio-shortcode, .wp-video-shortcode").not(".mejs-container").filter(function(){return!b(this).parent().hasClass("mejs-mediaelement")}).mediaelementplayer(c)}var c={};return{initialize:a}}a.wp=a.wp||{},a.wp.mediaelement=new c,b(a.wp.mediaelement.initialize)}(window,jQuery); \ No newline at end of file +!function(a,b){function c(){function a(){"undefined"!=typeof _wpmejsSettings&&(c=b.extend(!0,{},_wpmejsSettings)),c.classPrefix="mejs-",c.success=c.success||function(a){var b,c;a.rendererName&&-1!==a.rendererName.indexOf("flash")&&(b=a.attributes.autoplay&&"false"!==a.attributes.autoplay,c=a.attributes.loop&&"false"!==a.attributes.loop,b&&a.addEventListener("canplay",function(){a.play()},!1),c&&a.addEventListener("ended",function(){a.play()},!1))},c.customError=function(a,b){if(-1!==a.rendererName.indexOf("flash")||-1!==a.rendererName.indexOf("flv"))return''+mejsL10n.strings["mejs.download-video"]+""},b(".wp-audio-shortcode, .wp-video-shortcode").not(".mejs-container").filter(function(){return!b(this).parent().hasClass("mejs-mediaelement")}).mediaelementplayer(c)}var c={};return{initialize:a}}a.wp=a.wp||{},a.wp.mediaelement=new c,b(a.wp.mediaelement.initialize)}(window,jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index f2cc5b598c..28024f2530 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42581'; +$wp_version = '5.0-alpha-42582'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.