-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
183 lines (176 loc) · 3.59 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<html>
<head>
<title>VervidaChat</title>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div id="vervidachat"> <p id="p">Vervida Chat</p>
<br>
<br>
<div id="holder">
<form id="messageForm">
<input type="text" id="messageInput" placeholder="Type..."/>
<button type="submit" id="btn" onclick="hidel()"> Send </button>
</form>
<div class="chat" id="chat" style="overflow-y:scroll; height:450px;">
<div id="messageBox">
</div>
</div>
</div>
<button type="submit" id="btn1" onclick="showl()"> Show All </button>
<div id="people" style="overflow-y:scroll; height:450px;">
</body>
<script>
var socket = io.connect(); //connects to socket
$(function(){
var $people = $("#people");
var $messageForm = $("#messageForm"); //ref to the div message form
var $messageInput = $("#messageInput"); //ref to input box with id message
var $chat = $("#chat"); //ref to div chat
$messageForm.submit(function(e){
e.preventDefault();
socket.emit("send message", $messageInput.val());
$messageInput.val("");
});
socket.on("new message", function(data){
if(data.msg.length > 0){
$chat.append('<br>' +'<div id="circle"> ' + '<textarea id="t" readonly>' + data.msg + '</textarea>'+' </div>' + '<br>' );
}
});
socket.on("new user", function(data){
$people.append('<br>' +'<div id="circle1"> ' + ' </div>' + '<br>' );
});
socket.on("user left", function(data){
$("#circle1").remove();
});
});
showlog = false;
window.setInterval(function() {
if(showlog == false){
var chat = document.getElementById("chat");
chat.scrollTop = chat.scrollHeight;
var people = document.getElementById("people");
people.scrollTop = people.scrollHeight;
}
}, 4);
function showl(){
showlog = true;
}
function hidel(){
var chat = document.getElementById("chat");
chat.scrollTop = chat.scrollHeight;
var people = document.getElementById("people");
people.scrollTop = people.scrollHeight;
showlog = false;
}
</script>
<style>
body{
background-color:#1abc9c;
}
#p{
margin-top:9px;
}
#people{
background-color: #f1c40f;
width:250px;
height:440px;
margin-left:767px;
margin-top:-462px;
border: 6px solid white;
}
#chat{
background-color:#e74c3c;
font-family: verdana;
color:white;
font-size: 30px;
text-align:center;
border: 2px solid white;
border-radius:15px;
width:190px;
height:60px;
}
#btn{
background-color: white;
font-size:15px;
font-family: Verdana;
color:black;
width:56px;
height:51px;
text-align: center;
margin-left:0px;
border-radius:10px;
outline:none;
border: 2px solid #e74c3c;
}
#btn1{
background-color: white;
font-size:15px;
font-family: Verdana;
color:black;
width:100px;
height:40px;
text-align: center;
margin-left:1040px;
margin-top: -40px;
border-radius:10px;
outline:none;
border: 2px solid #e74c3c;
}
#messageInput{
margin-left: 532px;
text-align:center;
border-radius:10px;
outline:none;
shadow:none;
font-size:15px;
font-family: Verdana;
color:black;
width:250px;
height:50px;
}
#t {
text-align:left;
font-size:15px;
font-family: Verdana;
color:black;
border: 2px solid #f1c40f;
margin-top: -5px;
margin-left: 72px;
width:200px;
height:90px;
background-color:white;
border-radius:12px;
resize: none;
outline: none;
}
#chat{
border: 6px solid white;
width:459px;
background-color:#e74c3c;
margin:auto;
border-radius: 10px;
margin-left:300px;
}
::-webkit-scrollbar {
display: none;
}
#circle{
width:50px;
height:50px;
border-radius:100px;
border: 5px solid white;
margin-left:25px;
background-color:#f1c40f;
}
#circle1{
width:50px;
height:50px;
border-radius:100px;
border: 5px solid white;
margin-left:25px;
background-color:#3498db;
}
</style>
</html>