aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/core/overlay/fullscreen-overlay-container.ts
blob: 0eca202d863297b8a2e606194d95acbdfc36c70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * @license
 * Copyright Google Inc. All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */
/* tslint:disable:array-type member-access variable-name typedef
 only-arrow-functions directive-class-suffix component-class-suffix
 component-selector*/
import {Injectable} from '@angular/core';
import {OverlayContainer} from './overlay-container';

/**
 * The FullscreenOverlayContainer is the alternative to OverlayContainer
 * that supports correct displaying of overlay elements in Fullscreen mode
 * https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen
 * It should be provided in the root component that way:
 * providers: [
 *   {provide: OverlayContainer, useClass: FullscreenOverlayContainer}
 * ],
 */
@Injectable()
export class FullscreenOverlayContainer extends OverlayContainer {
  protected _createContainer(): void {
	super._createContainer();
	this._adjustParentForFullscreenChange();
	this._addFullscreenChangeListener(
		() => this._adjustParentForFullscreenChange());
  }

  private _adjustParentForFullscreenChange(): void {
	if (!this._containerElement) {
		return;
	}
	const fullscreenElement = this.getFullscreenElement();
	const parent = fullscreenElement || document.body;
	parent.appendChild(this._containerElement);
  }

  private _addFullscreenChangeListener(fn: () => void) {
	if (document.fullscreenEnabled) {
		document.addEventListener('fullscreenchange', fn);
	} else if (document.webkitFullscreenEnabled) {
		document.addEventListener('webkitfullscreenchange', fn);
	} else if ((document as any).mozFullScreenEnabled) {
		document.addEventListener('mozfullscreenchange', fn);
	} else if ((document as any).msFullscreenEnabled) {
		document.addEventListener('MSFullscreenChange', fn);
	}
  }

  /**
   * When the page is put into fullscreen mode, a specific element is specified.
   * Only that element and its children are visible when in fullscreen mode.
   */
  getFullscreenElement(): Element {
	return document.fullscreenElement || document.webkitFullscreenElement ||
		(document as any).mozFullScreenElement ||
		(document as any).msFullscreenElement || null;
  }
}