From 84d50dce03ea8b234208e5eb98d32a6e9372f4f9 Mon Sep 17 00:00:00 2001 From: Oliver Foster Date: Mon, 2 Sep 2024 13:27:38 +0100 Subject: [PATCH] Fix: Firefox fullscreen api (fixes #239) (#259) * Fix: Firefox fullscren api (fixes #239) * Changed override style * Upmerge master * Reapply original fix for #239 * Check if browser is currently in fullscreen before canceling fullscreen --------- Co-authored-by: Brad Simpson --- js/mediaLibrariesOverrides.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/js/mediaLibrariesOverrides.js b/js/mediaLibrariesOverrides.js index d9cdef2..56ee0fc 100644 --- a/js/mediaLibrariesOverrides.js +++ b/js/mediaLibrariesOverrides.js @@ -181,6 +181,35 @@ window.mejs.MediaElementPlayer.prototype.setTrack = function (lang) { }; +/** + * Fix for firefox fullscreen api + * https://github.com/adaptlearning/adapt-contrib-media/issues/239 + */ +const mediaFeatures = window.mejs.MediaFeatures; +if (mediaFeatures.hasMozNativeFullScreen) { + Object.assign(mediaFeatures, { + fullScreenEventName: document.exitFullscreen + ? 'fullscreenchange' + : 'mozfullscreenchange', + requestFullScreen: el => { + document.exitFullscreen + ? el.requestFullscreen() + : el.mozRequestFullScreen(); + }, + isFullScreen: () => { + return document.exitFullscreen + ? Boolean(document.fullscreenElement) + : document.mozFullScreen; + }, + cancelFullScreen: el => { + if (!mediaFeatures.isFullScreen()) return; + document.exitFullscreen + ? document.exitFullscreen() + : document.mozCancelFullScreen(); + } + }); +} + /** * Overwrite mediaelement-and-player enterFullScreen to remove Chrome <17 bug fix (Media issue #255) */