-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
117 lines (102 loc) · 2.77 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>HTML5 Minimal template</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="minimal.css" >
<link rel="stylesheet" type="text/css" href="minimal-inputs.css" >
</head>
<body>
<p id="connecting">Connecting...</p>
<div id="interface">
<input type="text" id="nickname" class="quarter" placeholder="Nick name..."/>
<input type="text" id="message" class="half" placeholder="Message text..."/>
<button id="send" class="quarter">Send</button>
<pre id="output"></pre>
</div>
</body>
<script>
var el = function(id) { return document.getElementById(id) };
var ws = new WebSocket(document.location.href.replace("http", "ws") + "ws/");
ws.onopen = function() {
console.log("websocket opened", arguments);
el("connecting").style.display = "none";
el("interface").style.display = "block";
};
ws.onmessage = function(message) { el("output").textContent += message.data + "\n"; };
ws.onclose = function() { console.log("close"); };
var send = function(ev) {
ws.send(JSON.stringify({
"name": el("nickname").value,
"message": el("message").value,
}));
el("message").value = "";
el("message").focus();
}
el("send").onclick = send;
el("message").onkeyup = function(ev) {
if (ev.keyCode == 13) {
send(ev);
}
}
</script>
<style>
* {
box-sizing: border-box;
}
body {
color: #555;
margin: 0 auto;
max-width: 50em;
font-family: "Helvetica", "Arial", sans-serif;
line-height: 1.5;
padding: 2em 1em;
}
pre {
border-left: 2px solid #bbb;
padding: 1em;
}
a {
color: #f56a6a;
}
input[type="submit"], input[type="reset"], input[type="button"], button, .button {
box-shadow: inset 0 0 0 2px #f56a6a;
color: #f56a6a;
font-weight: 700;
letter-spacing: 0.075em;
text-transform: uppercase;
text-align: center;
font-size: 0.8em;
}
input[type="submit"], input[type="reset"], input[type="button"], button, .button, input[type="text"], input[type="password"], input[type="email"], input[type="tel"], select, textarea {
border-radius: 0.375em;
background-color: transparent;
border: 0;
cursor: pointer;
display: inline-block;
min-height: 3.5em;
line-height: 3.5em;
padding: 0 2.25em;
text-decoration: none;
margin: 0.25em 0.25em;
font-size: 0.8em;
}
input[type="text"], input[type="password"], input[type="email"], input[type="tel"], select, textarea {
background-color: #eee;
color: #555;
outline: none;
padding: 0 0.75em;
font-weight: bold;
}
.half {
width: calc(50% - 0.7em);
}
.quarter {
width: calc(25% - 0.75em);
}
#interface {
display: none;
}
</style>
</html>