-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
93 lines (76 loc) · 2.07 KB
/
main.js
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
const REDIRECTS = [
{
input: 'intro',
content: {
title: 'Foothills Ward Sacrament Meeting',
subtitle: 'Thank you for joining us today. The stream will begin in a few moments.'
}
},
{
input: 'sacrament',
content: {
title: 'Foothills Ward Sacrament Meeting',
subtitle: 'The stream will resume shortly, after the sacrament is administered.'
}
}
]
function isElement(obj) {
try {
return obj instanceof HTMLElement;
}
catch(e){
return (typeof obj==="object") &&
(obj.nodeType===1) && (typeof obj.style === "object") &&
(typeof obj.ownerDocument ==="object");
}
}
function toggleVisibility(element) {
if (isElement(element)) {
element.classList.toggle('selected');
}
}
function cycleImages() {
const images = document.getElementsByClassName('slide-photo');
toggleVisibility(images[0]);
let i = 0;
setInterval(function() {
console.log(i%images.length);
toggleVisibility(images[i%(images.length)]);
toggleVisibility(images[(i+1)%(images.length)]);
i++;
}, 12000);
}
function fillTextFields() {
const params = new URLSearchParams(window.location.search);
params.forEach((value, key) => {
element = document.getElementById(key);
if (element) element.textContent = value;
});
}
function autoRedirect(items) {
const pageUrl = new URLSearchParams(window.location.search);
let query = new URLSearchParams();
items.forEach((redirect) => {
const {input, content} = redirect;
if (pageUrl.has(input)) {
for (const [key, value] of Object.entries(content)) {
query.append(key, value);
}
location.search = query.toString();
}
});
}
// Via David Walsh. Find the right method, call on correct element
function launchFullScreen(element) {
if(element.requestFullScreen) {
element.requestFullScreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
document.addEventListener('keydown', function(e){launchFullScreen(document.body)});
autoRedirect(REDIRECTS);
fillTextFields();
cycleImages();