Skip to content

Commit

Permalink
Fix: Exposed purge globally, linting (fixes #271) (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Sep 4, 2023
1 parent 01fadec commit ba5db01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
41 changes: 19 additions & 22 deletions js/mediaLibrariesOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Object.assign(window.mejs.MepDefaults, {

// The following function is used to to prevent a memory leak in Internet Explorer
// See: http://javascript.crockford.com/memory/leak.html
const purge = function (d) {
window.mejs.purge = function (d) {
let a = d.attributes;
if (a) {
for (let i = a.length - 1; i >= 0; i -= 1) {
Expand All @@ -37,7 +37,7 @@ const purge = function (d) {
a = d.childNodes;
if (a) {
for (let i = 0, count = a.length; i < count; i += 1) {
purge(d.childNodes[i]);
window.mejs.purge(d.childNodes[i]);
}
}
};
Expand All @@ -46,41 +46,40 @@ const purge = function (d) {
* Overwrite mediaelement-and-player killContextMenuTimer to remove global delete
*/
window.mejs.MediaElementPlayer.prototype.killContextMenuTimer = function () {
var timer = this.contextMenuTimer;
let timer = this.contextMenuTimer;

//

if (timer != null) {
clearTimeout(timer);
timer = null;
}
},
};

/**
* Overwrite mediaelement-and-player buildfullscreen to remove global delete
*/
window.mejs.MediaElementPlayer.prototype.buildfullscreen = function (player, controls, layers, media) {

if (!player.isVideo)
return;
if (!player.isVideo) { return; }

player.isInIframe = (window.location != window.parent.location);
player.isInIframe = (window.location !== window.parent.location);

// detect on start
media.addEventListener('play', function () { player.detectFullscreenMode(); });

// build button
var t = this,
hideTimeout = null,
fullscreenBtn =
const t = this;
let hideTimeout = null;
const fullscreenBtn =
$('<div class="mejs-button mejs-fullscreen-button">' +
'<button type="button" aria-controls="' + t.id + '" title="' + t.options.fullscreenText + '" aria-label="' + t.options.fullscreenText + '"></button>' +
'</div>')
.appendTo(controls)
.on('click', function () {

// toggle fullscreen
var isFullScreen = (mejs.MediaFeatures.hasTrueNativeFullScreen && mejs.MediaFeatures.isFullScreen()) || player.isFullScreen;
const isFullScreen = (window.mejs.MediaFeatures.hasTrueNativeFullScreen && window.mejs.MediaFeatures.isFullScreen()) || player.isFullScreen;

if (isFullScreen) {
player.exitFullScreen();
Expand All @@ -91,21 +90,21 @@ window.mejs.MediaElementPlayer.prototype.buildfullscreen = function (player, con
.on('mouseover', function () {

// very old browsers with a plugin
if (t.fullscreenMode == 'plugin-hover') {
if (t.fullscreenMode === 'plugin-hover') {
if (hideTimeout !== null) {
clearTimeout(hideTimeout);
}

var buttonPos = fullscreenBtn.offset(),
containerPos = player.container.offset();
const buttonPos = fullscreenBtn.offset();
const containerPos = player.container.offset();

media.positionFullscreenButton(buttonPos.left - containerPos.left, buttonPos.top - containerPos.top, true);
}

})
.on('mouseout', function () {

if (t.fullscreenMode == 'plugin-hover') {
if (t.fullscreenMode === 'plugin-hover') {
if (hideTimeout !== null) {
clearTimeout(hideTimeout);
}
Expand All @@ -117,12 +116,10 @@ window.mejs.MediaElementPlayer.prototype.buildfullscreen = function (player, con

});



player.fullscreenBtn = fullscreenBtn;

t.globalBind('keydown', function (e) {
if (e.keyCode == 27 && ((mejs.MediaFeatures.hasTrueNativeFullScreen && mejs.MediaFeatures.isFullScreen()) || t.isFullScreen)) {
if (e.keyCode === 27 && ((window.mejs.MediaFeatures.hasTrueNativeFullScreen && window.mejs.MediaFeatures.isFullScreen()) || t.isFullScreen)) {
player.exitFullScreen();
}
});
Expand All @@ -131,12 +128,12 @@ window.mejs.MediaElementPlayer.prototype.buildfullscreen = function (player, con
t.normalWidth = 0;

// setup native fullscreen event
if (mejs.MediaFeatures.hasTrueNativeFullScreen) {
if (window.mejs.MediaFeatures.hasTrueNativeFullScreen) {

// chrome doesn't alays fire this in an iframe
var fullscreenChanged = function (e) {
const fullscreenChanged = function (e) {
if (player.isFullScreen) {
if (mejs.MediaFeatures.isFullScreen()) {
if (window.mejs.MediaFeatures.isFullScreen()) {
player.isNativeFullScreen = true;
// reset the controls once we are fully in full screen
player.setControlsSize();
Expand All @@ -149,7 +146,7 @@ window.mejs.MediaElementPlayer.prototype.buildfullscreen = function (player, con
}
};

player.globalBind(mejs.MediaFeatures.fullScreenEventName, fullscreenChanged);
player.globalBind(window.mejs.MediaFeatures.fullScreenEventName, fullscreenChanged);
}

};
Expand Down
2 changes: 1 addition & 1 deletion js/mediaView.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class MediaView extends ComponentView {
if (this.mediaElement && this.mediaElement.player) {
const playerId = this.mediaElement.player.id;

purge(this.$el[0]);
window.mejs.purge(this.$el[0]);
this.mediaElement.player.remove();

if (window.mejs.players[playerId]) {
Expand Down

0 comments on commit ba5db01

Please sign in to comment.