Browse Source

Introduce Viewport.isFullscreenAvailable()

customisations
alemart 1 year ago
parent
commit
471e76c63d
2 changed files with 30 additions and 0 deletions
  1. 12
    0
      docs/api/viewport.md
  2. 18
    0
      src/core/viewport.ts

+ 12
- 0
docs/api/viewport.md View File

@@ -135,6 +135,18 @@ Exit fullscreen mode.
135 135
 
136 136
 A promise that is resolved once the fullscreen mode is no longer active, or rejected on error. The promise will be rejected if the method is called when not in fullscreen mode.
137 137
 
138
+### isFullscreenAvailable
139
+
140
+`viewport.isFullscreenAvailable(): boolean`
141
+
142
+Checks the availability of the fullscreen mode on the current platform and page.
143
+
144
+*Since:* 0.2.1
145
+
146
+**Returns**
147
+
148
+Returns `true` if the fullscreen mode can be activated.
149
+
138 150
 ## Events
139 151
 
140 152
 A viewport is an [AREventTarget](ar-event-target.md). You can listen to the following events:

+ 18
- 0
src/core/viewport.ts View File

@@ -84,6 +84,9 @@ export interface Viewport extends ViewportEventTarget
84 84
     /** Exit fullscreen mode */
85 85
     exitFullscreen(): SpeedyPromise<void>;
86 86
 
87
+    /** Is the fullscreen mode available? */
88
+    isFullscreenAvailable(): boolean;
89
+
87 90
     /** Canvas on which the physical scene will be drawn @internal */
88 91
     readonly _backgroundCanvas: HTMLCanvasElement;
89 92
 
@@ -296,6 +299,13 @@ export class BaseViewport extends ViewportEventTarget implements Viewport
296 299
         });
297 300
     }
298 301
 
302
+    /** Is the fullscreen mode available? */
303
+    isFullscreenAvailable(): boolean
304
+    {
305
+        return document.fullscreenEnabled ||
306
+               !!((document as any).webkitFullscreenEnabled);
307
+    }
308
+
299 309
     /**
300 310
      * True if the viewport is being displayed in fullscreen mode
301 311
      */
@@ -642,6 +652,14 @@ abstract class ViewportDecorator extends ViewportEventTarget implements Viewport
642 652
     }
643 653
 
644 654
     /**
655
+     * Is the fullscreen mode available?
656
+     */
657
+    isFullscreenAvailable(): boolean
658
+    {
659
+        return this._base.fullscreenAvailable;
660
+    }
661
+
662
+    /**
645 663
      * Background canvas
646 664
      * @internal
647 665
      */

Loading…
Cancel
Save