-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
88 lines (73 loc) · 2.35 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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>> oiquertc?</title>
<link href="https://fonts.googleapis.com/css?family=Share+Tech+Mono" rel="stylesheet">
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="chat-window">
<div class="browser-bar">
<span class="close-button"></span>
</div>
<div class="text-area"></div>
<form action="">
<input id="message-input" autocomplete="off" autofocus/>
</form>
</div>
<script src="/socket.io/socket.io.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
$(function(){
var socket = io();
$("form").submit(function(){
socket.emit("message", $("#message-input").val());
$("#message-input").val("");
return false;
});
socket.on("connected", function(message) {
if (checkForEmptySpace() == false) {
removeFirstMessage()
}
insertMessageLine(message);
});
socket.on("disconnected", function(message) {
if (checkForEmptySpace() == false) {
removeFirstMessage()
}
insertMessageLine(message);
});
socket.on("message", function(message) {
if (checkForEmptySpace() == false) {
removeFirstMessage()
}
insertMessageLine("> <span class='underline'>" + message + "</span>");
});
});
function insertMessageLine(message) {
$(".text-area").append("<li class='message-line'>" + message + "</li>");
}
function checkForEmptySpace() {
var how_many_text_lines = $('.message-line').length;
if (how_many_text_lines == 0) {
return true;
}
else {
var line_height = $(".message-line").outerHeight(true);
var textarea_height = $(".text-area").height();
if ((textarea_height - (line_height*how_many_text_lines)) >= line_height) {
return true;
}
else {
return false;
}
}
}
function removeFirstMessage() {
$('.message-line')[0].remove();
}
</script>
</body>
</html>