-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
125 lines (110 loc) · 3.18 KB
/
index.html
File metadata and controls
125 lines (110 loc) · 3.18 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: 13px Helvetica, Arial;
}
.bottom {
position: fixed;
bottom: 0;
width: 100%;
background: #000;
}
form {
padding: 3px;
width: 100%;
}
form input {
border: 0;
padding: 10px;
width: 70%;
margin-right: 0.5%;
}
form #input-files {
width: 9%;
background: rgb(130, 224, 255);
border: none;
padding: 10px;
}
button {
width: 9%;
background: rgb(130, 224, 255);
border: none;
padding: 10px;
}
#messages {
list-style-type: none;
margin: 0;
padding: 0;
}
#messages li {
padding: 5px 10px;
}
#messages li:nth-child(odd) {
background: #eee;
}
</style>
</head>
<body>
<ul id="messages"></ul>
<div class="bottom">
<form id="inputs">
<input id="input-text" type="text"/>
<input id="input-files" type="file"/>
<button>SEND</button>
</form>
<button id="emoji">EMOJI</button>
</div>
</body>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@joeattardi/emoji-button@3.0.2/dist/index.min.js"></script>
<script>
var socket = io();
socket.emit('connection');
var name = prompt("Enter your name");
$('#inputs').submit(function() {
socket.emit('chat-sended', name, $('#input-text').val());
$('#input-text').val('');
return false;
});
$('#input-files').on('change', function() {
if (this.files.length !== 0) {
let file = this.files[0];
let reader = new FileReader();
if (reader) {
reader.onload = (e) => socket.emit('img', name, e.target.result);
reader.readAsDataURL(file);
}
this.value = '';
}
})
$('#emoji').on('click', function () {
let button = document.querySelector('#emoji');
let picker = new EmojiButton({
theme: 'auto',
position: 'bottom-end'
});
picker.on('emoji', function(emoji){
let msg = $('#input-text').val();
$('#input-text').val(msg + emoji).focus();
});
picker.showPicker(button);
});
socket.on('chat-received', function(name, text) {
$('#messages').append('<li><strong>' + name + '</strong> : ' + text + '</li>');
});
socket.on('img', function(name, text) {
$('#messages').append('<li><strong>' + name + '</strong> : <img src=\"' + text + '\"/></li>');
});
</script>
</html>