blob: ab516a4e8846b3768fb474c2dfc4f5cc54cb7fd1 (
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
63
64
65
|
function requestFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
function getFullscreenElement() {
return (
document.fullscreenElement ||
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
null
);
}
function toggleFullscreen(element) {
if (getFullscreenElement()) {
exitFullscreen();
} else {
requestFullscreen(element);
}
}
function setup(container, fullscreenElement=null) {
const fullscreenLink = container.querySelector('.fullscreen-link');
if (fullscreenLink !== null) {
if (fullscreenElement === null) {
fullscreenElement = container.querySelector('.fullscreen-element');
}
fullscreenLink.addEventListener('click', (e) => {
toggleFullscreen(fullscreenElement);
e.preventDefault();
return false;
}, false);
}
const template = container.querySelector('template');
const templateContentContainer = container.querySelector('.template-content-container');
if (template !== null && templateContentContainer !== null) {
const mode = container.dataset.shadowMode;
const shadow = templateContentContainer.attachShadow({mode});
const content = document.importNode(template.content, true);
setup(content);
shadow.appendChild(content);
}
}
|