-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction toggleFullScreen()
More file actions
126 lines (104 loc) · 4.21 KB
/
Copy pathfunction toggleFullScreen()
File metadata and controls
126 lines (104 loc) · 4.21 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// add toggleFullScreen() to onDoubleclick of plottingPanel
/*jslint browser:true */
// copy to custom function
function toggleFullScreen() {
try {
const doc = document.documentElement;
// Check if any fullscreen element exists
const isFullScreen = document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement;
if (!isFullScreen) {
// Request full-screen mode based on the browser
if (doc.requestFullscreen) {
doc.requestFullscreen();
} else if (doc.msRequestFullscreen) {
doc.msRequestFullscreen();
} else if (doc.mozRequestFullScreen) {
doc.mozRequestFullScreen();
} else if (doc.webkitRequestFullscreen) {
doc.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); // Pass input permission for older WebKit
}
} else {
// Exit full-screen mode based on the browser
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
} catch (e) {
console.error("Error toggling full-screen mode:", e);
}
}
// Handle screen orientation for mobile devices (optional)
window.addEventListener("orientationchange", () => {
if (screen.orientation && screen.orientation.lock) {
screen.orientation.lock('landscape').catch(err => console.warn('Failed to lock orientation:', err));
}
});
older versions
//updated to address Firefox
//https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
// does not work for iOS
/*jslint browser:true */
function toggleFullScreen() {
try {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}
} else {
if (document.exitFullscreen) { //Standard
document.exitFullscreen();
} else if (document.msExitFullscreen) { //Internet Explorer 11
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) { //Gecko (Firefox)
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) { //Safari (WebKit)
document.webkitExitFullscreen();
}
}
} catch (e) {
//
}
}
//https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
// does not work for iOS
/*jslint browser:true */
function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}