-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
146 lines (120 loc) · 5.37 KB
/
index.html
File metadata and controls
146 lines (120 loc) · 5.37 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<html>
<head>
<title>
Node.js chat
</title>
<style>
#contentWrap{
display: none;
}
#chatWrap{
float: left;
}
#chat{
position: relative;
width: 100%;
float:left;
min-height:100px;
height: 90%;
overflow: auto;
}
</style>
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Node.js Chat <small> Developed by <a href="http://geekytheory.com" target="_blank">Geeky Theory</a></small></h1>
</div>
<div class="input-group" style="width:300px;text-align:center;margin:0 auto;" id="nickWrap">
<input id="nickname" class="form-control input-lg" type="text" placeholder="Enter your username">
<span class="input-group-btn">
<button class="btn btn-lg btn-primary" type="submit" id="setNick">OK</button>
</span>
</div>
<div class="alert fade in alert-danger alert-dismissable" data-dismiss="alert" id="login-error" style="display:none;">
<button type="button" class="close" id="closeAlert">×</button>
That username is already taken. Try again.
</div>
<div id="contentWrap" class="row" style="height: 70%;">
<div class="col-md-2"></div>
<div id="chatWrap" class="col-md-6">
<div class="panel panel-success">
<div class="panel-heading">Chat</div>
<div id="chat" class="panel-body"></div>
</div>
<div>
<form id="send-message" class="input-group" style="text-align:center;margin:0 auto;">
<input id="message" class="form-control input-lg" type="text">
<span class="input-group-btn">
<button class="btn btn-lg btn-primary" type="submit">Send</button>
</span>
</form>
</div>
<!--
<input size="35" id="message"></input>
<input type="submit"></input>
</form>-->
</div>
<div class="col-md-2">
<div class="panel panel-info">
<div class="panel-heading">
Users
</div>
<div id="users" class="panel-body"></div>
</div>
</div>
</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
jQuery(function($) {
var socket = io.connect();
var $messageForm = $('#send-message');
var $messageBox = $('#message');
var $chat = $('#chat');
var $buttonSend = $('#send');
var $nickForm = $('#setNick');
var $nickBox = $('#nickname');
var $users = $('#users');
var $closeAlert = $('#closeAlert');
$nickForm.click(function(e) {
e.preventDefault();
socket.emit('new user', $nickBox.val(), function(data) {
if(data) {
$('#nickWrap').hide();
$('#contentWrap').show();
} else {
$("#login-error").show();
}
});
$nickBox.val('');
});
$closeAlert.click(function(e) {
$("#login-error").hide();
});
$messageForm.submit(function(e) {
e.preventDefault();
if($messageBox.val()!='') socket.emit('send message', $messageBox.val());
$messageBox.val('');
});
socket.on('new message', function(data) {
$chat.append('<b>'+data.nick+":</b> "+data.msg+"<br/>");
});
socket.on('usernames', function(data) {
var html = '';
for (var username in data) {
html += username + '<br/>';
}
$users.html(html);
});
});
</script>
</body>
</html>