forked from socketio/chat-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
52 lines (50 loc) · 2.38 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
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<h1 style="color: #3e3e3e">Welcome To Simple Chat room with NodeJS</h1>
<form id="chat_room">
<div class="form-group">
<label for="conversation_holder"> Conversations </label>
<div id="conversation_holder" contenteditable="true" style="height: 300px;background: #eeeeee;overflow: scroll;overflow-x: hidden;" ></div>
</div>
<div class="form-group">
<label for="enter_message">Enter Message :</label>
<input type="text" id="enter_message" class="form-control">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Send <i class="glyphicon glyphicon-send"></i></button>
</div>
</form>
</div>
<script>
$(function () {
var socket = io();
$('form#chat_room').submit(function () {
var message = $('#enter_message').val();
if ($.trim(message) != "") {
socket.emit('chat message', $('#enter_message').val());
$('#enter_message').val('');
}
return false;
});
socket.on('chat message', function (data) {
var color = (data.messageCount % 2 == 0) ? "#eeeeee" : "#DBDBDB";
var message = '<div style="background-color:' + color + ';width: 100%;padding: 5px;"> ' + data.message + '<small style="font-size: 10px;"> ('+data.date+')</small>' + '</div>';
$('#conversation_holder').append(message);
$('#conversation_holder').scrollTop($('#conversation_holder')[0].scrollHeight);
});
});
</script>
</body>
</html>