-
Notifications
You must be signed in to change notification settings - Fork 1
/
chat.html
93 lines (84 loc) · 2.84 KB
/
chat.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tom & Jerry</title>
<meta name="description" content="Source code generated using layoutit.com">
<meta name="author" content="LayoutIt!">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="char.html">Characters</a>
</li>
<li class="">
<a href="info.html">Site Info</a>
</li>
<li class="active">
<a href="#">Chat Room</a>
</li>
</ul>
<br>
<br>
<ul id="messages" class="list-group"></ul>
<br>
<br>
<div class="form-group">
<form>
<div id="name_area">
<label>Enter name:</label>
<input class="form-control input-lg" id="uname" type="text" placeholder="Enter Name" autocomplete="off"><button type="button" id="name_btn" class="btn btn-primary">Set Name</button>
</div>
<div id="alerts"></div>
<br>
<label for="inputlg">Enter Chat Text</label>
<input class="form-control input-lg" id="inputlg" type="text" placeholder="Enter Chat Text" autocomplete="off">
<button type="submit" class="btn btn-primary">Send</button>
</form>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/scripts.js"></script>
<script src="node_modules/socket.io-client/socket.io.js"></script>
<script>
sessionStorage.name = ""
$('#name_btn').click(function() {
// body...
sessionStorage.name = $('#uname').val()
document.getElementById('name_area').innerHTML = "";
document.getElementById('alerts').innerHTML = '<div class="alert alert-success alert-dismissible" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>Name Set Successfully!!!</div>'
});
var socket = io();
$('form').submit(function(){
//var uname = $('#uname').val()
var mess = $('#inputlg').val()
if (sessionStorage.name == "") {
document.getElementById('alerts').innerHTML = '<div class="alert alert-danger alert-dismissible" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>Set Name First!</div>'
//return;
}
else{
var mess_str = sessionStorage.name + ": " + mess;
socket.emit('chat message', mess_str);
$('#inputlg').val('');
return false;
}
});
socket.on('chat message', function(msg){
$('#messages').append($('<li class="list-group-item">').text(msg));
});
</script>
</body>
</html>