-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html.tmpl
138 lines (123 loc) · 4.23 KB
/
index.html.tmpl
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
127
128
129
130
131
132
133
134
135
136
137
138
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kiosk Controller</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
<script>
function updateTabSwitchingButton(caller, isTabSwitching) {
if (isTabSwitching) {
caller.innerHTML = "Pause";
caller.setAttribute('onclick', 'toggleTabSwitching(this, \'pause\')')
} else {
caller.innerHTML = "Resume";
caller.setAttribute('onclick', 'toggleTabSwitching(this, \'resume\')')
}
}
function updateBacklightButton(caller, stati) {
// If all displays have the same status, set it to that one.
// Otherwise, set element.indeterminate = true;
if (stati.every((e, _, all) => e.status === all[0].status)) {
console.log("All displays are " + stati[0].status);
caller.checked = stati[0].status;
} else {
console.log("NOT all displays are the same");
caller.indeterminate = true;
}
}
function toggleTabSwitching(caller, action) {
event.preventDefault();
fetch('/' + action, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})
.then(res => res.text())
.then(json => dispatchStatusUpdate(JSON.parse(json)))
.catch(err => console.error(err));
return false;
}
function toggleBacklight(caller) {
event.preventDefault();
fetch('/backlight', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: "status=toggle",
})
.then(res => res.text())
.then(json => dispatchStatusUpdate(JSON.parse(json)))
.catch(err => console.error(err));
return false;
}
function dispatchStatusUpdate(parsedData) {
if ("isTabSwitching" in parsedData) {
updateTabSwitchingButton(document.getElementById("tabSwitchingButton"), parsedData["isTabSwitching"]);
}
if ("displayStati" in parsedData) {
displayStati = parsedData["displayStati"];
if (!Object.is(displayStati, null)) {
updateBacklightButton(document.getElementById("backlightButton"), displayStati);
}
}
}
new EventSource("/updates").onmessage = (event) => {
parsedData = JSON.parse(event.data);
console.group("statusUpdate");
console.dir(parsedData);
console.groupEnd("statusUpdate");
dispatchStatusUpdate(parsedData);
}
window.addEventListener("load", function(event){
new Flickity('.carousel', {
on: {
staticClick: function(event, pointer, element, index) {
if (!element) { return; }
fetch("/activate/", {
"method": "POST",
"headers": { "content-type": "application/x-www-form-urlencoded" },
"body": "id=" + element.id,
})
.catch(err => console.error(err));
},
},
wrapAround: true,
imagesLoaded: true,
percentPosition: false,
});
});
</script>
</head>
<body>
<header>
<nav>
<a href="/" class="current">Home</a>
{{ if .isTabSwitching }}
<a id="tabSwitchingButton" onclick="toggleTabSwitching(this, 'pause')">Pause</a>
{{ else }}
<a id="tabSwitchingButton" onclick="toggleTabSwitching(this, 'resume')">Resume</a>
{{ end }}
<input type="checkbox" id="backlightButton" onclick="toggleBacklight(this)"/>
</nav>
</header>
<main>
<div class="carousel">
{{ range .images }}
<img id="{{ . }}" src="/image/{{ . }}" />
{{ end }}
</div>
</main>
<footer>
<p>
{{ .programVersion }}
·
<a href="https://github.com/suhlig/kiosk">Source code</a>
·
Made with <a href="https://simplecss.org/">simple.css</a>
</p>
</footer>
</body>
</html>