Skip to content

Commit 97cde4e

Browse files
committed
Media: Add MediaElement.js 2.2 back-compat for MediaElement.js 4.2
* Introduces `mediaelement-migrate.js`. * Upgrades ME.js from 4.2.5-74e01a40 to 4.2.6-78496d1. Props rafa8626, bradyvercher. See #39686. Fixes #42189. git-svn-id: https://develop.svn.wordpress.org/trunk@41877 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9dfb758 commit 97cde4e

16 files changed

Lines changed: 1009 additions & 682 deletions

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ module.exports = function(grunt) {
346346
'!wp-includes/js/media-*',
347347
// WordPress scripts inside directories
348348
'wp-includes/js/jquery/jquery.table-hotkeys.js',
349+
'wp-includes/js/mediaelement/mediaelement-migrate.js',
349350
'wp-includes/js/mediaelement/wp-mediaelement.js',
350351
'wp-includes/js/mediaelement/wp-playlist.js',
351352
'wp-includes/js/plupload/handlers.js',

src/wp-includes/js/mediaelement/mediaelement-and-player.js

Lines changed: 559 additions & 430 deletions
Large diffs are not rendered by default.

src/wp-includes/js/mediaelement/mediaelement-and-player.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* global console, MediaElementPlayer, mejs */
2+
(function ( window, $ ) {
3+
// Reintegrate `plugins` since they don't exist in MEJS anymore; it won't affect anything in the player
4+
if (mejs.plugins === undefined) {
5+
mejs.plugins = {};
6+
mejs.plugins.silverlight = [];
7+
mejs.plugins.silverlight.push({
8+
types: []
9+
});
10+
}
11+
12+
// Inclusion of old `HtmlMediaElementShim` if it doesn't exist
13+
mejs.HtmlMediaElementShim = mejs.HtmlMediaElementShim || {
14+
getTypeFromFile: mejs.Utils.getTypeFromFile
15+
};
16+
17+
// Add missing global variables for backward compatibility
18+
if (mejs.MediaFeatures === undefined) {
19+
mejs.MediaFeatures = mejs.Features;
20+
}
21+
if (mejs.Utility === undefined) {
22+
mejs.Utility = mejs.Utils;
23+
}
24+
25+
/**
26+
* Create missing variables and have default `classPrefix` overridden to avoid issues.
27+
*
28+
* `media` is now a fake wrapper needed to simplify manipulation of various media types,
29+
* so in order to access the `video` or `audio` tag, use `media.originalNode` or `player.node`;
30+
* `player.container` used to be jQuery but now is a HTML element, and many elements inside
31+
* the player rely on it being a HTML now, so its conversion is difficult; however, a
32+
* `player.$container` new variable has been added to be used as jQuery object
33+
*/
34+
var init = MediaElementPlayer.prototype.init;
35+
MediaElementPlayer.prototype.init = function () {
36+
this.options.classPrefix = 'mejs-';
37+
this.$media = this.$node = $( this.node );
38+
init.call( this );
39+
};
40+
41+
var ready = MediaElementPlayer.prototype._meReady;
42+
MediaElementPlayer.prototype._meReady = function () {
43+
this.container = $( this.container) ;
44+
this.controls = $( this.controls );
45+
this.layers = $( this.layers );
46+
ready.apply( this, arguments );
47+
};
48+
49+
// Override method so certain elements can be called with jQuery
50+
MediaElementPlayer.prototype.getElement = function ( el ) {
51+
return $ !== undefined && el instanceof $ ? el[0] : el;
52+
};
53+
54+
// Add jQuery ONLY to most of custom features' arguments for backward compatibility; default features rely 100%
55+
// on the arguments being HTML elements to work properly
56+
MediaElementPlayer.prototype.buildfeatures = function ( player, controls, layers, media ) {
57+
var defaultFeatures = [
58+
'playpause',
59+
'current',
60+
'progress',
61+
'duration',
62+
'tracks',
63+
'volume',
64+
'fullscreen'
65+
];
66+
for (var i = 0, total = this.options.features.length; i < total; i++) {
67+
var feature = this.options.features[i];
68+
if (this['build' + feature]) {
69+
try {
70+
// Use jQuery for non-default features
71+
if (defaultFeatures.indexOf(feature) === -1) {
72+
this['build' + feature]( player, $(controls), $(layers), media );
73+
} else {
74+
this['build' + feature]( player, controls, layers, media );
75+
}
76+
77+
} catch (e) {
78+
console.error( 'error building ' + feature, e );
79+
}
80+
}
81+
}
82+
};
83+
84+
})( window, jQuery );

0 commit comments

Comments
 (0)