-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
69 lines (59 loc) · 1.67 KB
/
index.html
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
<!DOCTYPE html>
<html lang="{{.Lang}}" title="{{.Name}}" style="height: 100%;">
<head>
{{ range .HeadElements }}
{{- . }}
{{ end }}
<script>
history.pushState(null, null, null);
window.addEventListener("popstate", (e) => {
history.pushState(null, null, null);
e.preventDefault();
});
</script>
<script src="turbo.es2017-umd.js"></script>
<script>
let protocol = "ws";
if (location.protocol === 'https:') {
protocol = 'wss';
}
let url = protocol + "://" + location.host + location.pathname
const ws = new WebSocket(url + "ws");
Turbo.session.connectStreamSource(ws);
function makeListener(eventName, propName) {
return function (e) {
const parts = e.target.id.split("-");
if (!(parts.length == 2 && parts[0] == "wasabi")) {
return
}
if (propName == "") {
props = {}
} else {
props = { [propName]: e.target[propName] }
}
ev = {
target: parts[1],
event: eventName,
props: props,
};
ws.send(JSON.stringify(ev))
}
}
ws.onopen = function (e) {
{{range.Events}}
document.addEventListener("{{.Name}}", makeListener("{{.Name}}", "{{.PropName}}"));
{{end}}
};
window.onbeforeunload = function () {
Turbo.session.disconnectStreamSource(ws);
ws.close();
}
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Name}}</title>
</head>
<body style="height: 100%; box-sizing: border-box; padding: 0px; margin: 0px; overflow: auto;">
<div id="wasabi-page"></div>
</body>
</html>