mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-24 17:35:10 +03:00
51c3717305
This updates the fullscreen externs to: - Add a newer definition for requestFullscreen which includes options for the method - Remove prefixed methods which are now built into the compiler and are no longer necessary - Drop document.webkitSupportsFullscreen method, which does not seem to exist as defined, even on iOS (confusion with similar property on video element: https://apple.co/39TLC5I) This enables PR #2325 to resolve issue #2324 Change-Id: Ie7bea7e7d4fd59d6d801431e2ba996649e185dc1
90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill.Fullscreen');
|
|
|
|
goog.require('shaka.polyfill');
|
|
|
|
|
|
/**
|
|
* @summary A polyfill to unify fullscreen APIs across browsers.
|
|
* Many browsers have prefixed fullscreen methods on Element and document.
|
|
* See {@link https://mzl.la/2K0xcHo Using fullscreen mode} on MDN for more
|
|
* information.
|
|
*/
|
|
shaka.polyfill.Fullscreen = class {
|
|
/**
|
|
* Install the polyfill if needed.
|
|
*/
|
|
static install() {
|
|
if (!window.Document) {
|
|
// Avoid errors on very old browsers.
|
|
return;
|
|
}
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
let proto = Element.prototype;
|
|
proto.requestFullscreen = proto.requestFullscreen ||
|
|
proto.mozRequestFullScreen ||
|
|
proto.msRequestFullscreen ||
|
|
proto.webkitRequestFullscreen;
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
proto = Document.prototype;
|
|
proto.exitFullscreen = proto.exitFullscreen ||
|
|
proto.mozCancelFullScreen ||
|
|
proto.msExitFullscreen ||
|
|
proto.webkitExitFullscreen;
|
|
|
|
if (!('fullscreenElement' in document)) {
|
|
Object.defineProperty(document, 'fullscreenElement', {
|
|
get: () => {
|
|
return document.mozFullScreenElement ||
|
|
document.msFullscreenElement ||
|
|
document.webkitFullscreenElement;
|
|
},
|
|
});
|
|
Object.defineProperty(document, 'fullscreenEnabled', {
|
|
get: () => {
|
|
return document.mozFullScreenEnabled ||
|
|
document.msFullscreenEnabled ||
|
|
document.webkitFullscreenEnabled;
|
|
},
|
|
});
|
|
}
|
|
|
|
const proxy = shaka.polyfill.Fullscreen.proxyEvent_;
|
|
document.addEventListener('webkitfullscreenchange', proxy);
|
|
document.addEventListener('webkitfullscreenerror', proxy);
|
|
document.addEventListener('mozfullscreenchange', proxy);
|
|
document.addEventListener('mozfullscreenerror', proxy);
|
|
document.addEventListener('MSFullscreenChange', proxy);
|
|
document.addEventListener('MSFullscreenError', proxy);
|
|
}
|
|
|
|
/**
|
|
* Proxy fullscreen events after changing their name.
|
|
* @param {!Event} event
|
|
* @private
|
|
*/
|
|
static proxyEvent_(event) {
|
|
const eventType = event.type.replace(/^(webkit|moz|MS)/, '').toLowerCase();
|
|
|
|
let newEvent;
|
|
// IE 11 does not have an Event constructor
|
|
if (typeof(Event) === 'function') {
|
|
newEvent = new Event(eventType, /** @type {EventInit} */(event));
|
|
} else {
|
|
newEvent = document.createEvent('Event');
|
|
newEvent.initEvent(eventType, event.bubbles, event.cancelable);
|
|
}
|
|
|
|
event.target.dispatchEvent(newEvent);
|
|
}
|
|
};
|
|
|
|
|
|
shaka.polyfill.register(shaka.polyfill.Fullscreen.install);
|