summaryrefslogtreecommitdiff
path: root/javascript/videojs/src/js/fullscreen-api.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/videojs/src/js/fullscreen-api.js')
-rw-r--r--javascript/videojs/src/js/fullscreen-api.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/javascript/videojs/src/js/fullscreen-api.js b/javascript/videojs/src/js/fullscreen-api.js
new file mode 100644
index 0000000..86ad091
--- /dev/null
+++ b/javascript/videojs/src/js/fullscreen-api.js
@@ -0,0 +1,62 @@
+/**
+ * @file fullscreen-api.js
+ * @module fullscreen-api
+ */
+import document from 'global/document';
+
+/**
+ * Store the browser-specific methods for the fullscreen API.
+ *
+ * @type {Object}
+ * @see [Specification]{@link https://fullscreen.spec.whatwg.org}
+ * @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
+ */
+const FullscreenApi = {
+ prefixed: true
+};
+
+// browser API methods
+const apiMap = [
+ [
+ 'requestFullscreen',
+ 'exitFullscreen',
+ 'fullscreenElement',
+ 'fullscreenEnabled',
+ 'fullscreenchange',
+ 'fullscreenerror',
+ 'fullscreen'
+ ],
+ // WebKit
+ [
+ 'webkitRequestFullscreen',
+ 'webkitExitFullscreen',
+ 'webkitFullscreenElement',
+ 'webkitFullscreenEnabled',
+ 'webkitfullscreenchange',
+ 'webkitfullscreenerror',
+ '-webkit-full-screen'
+ ]
+];
+
+const specApi = apiMap[0];
+let browserApi;
+
+// determine the supported set of functions
+for (let i = 0; i < apiMap.length; i++) {
+ // check for exitFullscreen function
+ if (apiMap[i][1] in document) {
+ browserApi = apiMap[i];
+ break;
+ }
+}
+
+// map the browser API names to the spec API names
+if (browserApi) {
+ for (let i = 0; i < browserApi.length; i++) {
+ FullscreenApi[specApi[i]] = browserApi[i];
+ }
+
+ FullscreenApi.prefixed = browserApi[0] !== specApi[0];
+}
+
+export default FullscreenApi;