-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (69 loc) · 1.56 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
<!doctype html>
<html>
<head>
<title>Type Away</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
padding: 10px;
}
form {
display: flex;
margin-bottom: 10px;
}
input, button {
font-size: 22px;
}
input {
box-sizing: border-box;
width: 100%;
height: 32px;
}
.send {
height: 32px;
}
</style>
</head>
<body>
<div id="app">
<form @submit.prevent="onSubmit">
<input v-model="input" ref="input" autocomplete="off">
<button class="send">➤</button>
</form>
<button @click="onBackspace">⌫</button>
<button @click="onEnter">⏎</button>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
const socket = io();
const vm = new Vue({
el: '#app',
data: {
input: '',
},
mounted() {
this.focusInput();
},
methods: {
onSubmit() {
socket.emit('type', this.input);
this.input = ''
this.focusInput();
},
onBackspace() {
socket.emit('key', 'BackSpace');
this.focusInput();
},
onEnter() {
socket.emit('key', 'Return');
this.focusInput();
},
focusInput() {
this.$refs.input.focus();
},
},
});
</script>
</body>
</html>