-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (89 loc) · 3.28 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>chat</title>
<link type="text/css" rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css"/>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"/></script>
<script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
function getCurrentDate(){
var currentTime = new Date();
var hours = currentTime.getHours();
var mins = currentTime.getMinutes();
var secs = currentTime.getSeconds();
return(hours + ':'+ mins + ':' + secs);
}
function getDisplayMessage(){
var message = $('#messageText').val();
var userName = $('#usernameText').val();
return('<em>'+userName + ' (' + getCurrentDate() +')</em>: ' + message);
}
$(document).ready(function() {
var socket = io.connect('http://phuc-san-1692.herokuapp.com/');
socket.on('connect', function() {
$('#messages').append('<li>Connected to the server.</li>');
});
socket.on('message', function(message) {
$('#messages').append('<li>' + message + '</li>');
$('#messages').listview("refresh");
});
socket.on('disconnect', function() {
$('#messages').append('<li>Disconnected from the server.</li>');
});
$('#sendButton').bind('click', function() {
socket.send(getDisplayMessage());
$('#messages').append('<li class="mySelf">' + getDisplayMessage() + '</li>');
$('#messages').listview("refresh");
$('#messageText').val('');
});
});
</script>
<style>
.mySelf{
color:#09C;
}
.listDiv{
margin-top:40px;
margin-left:10px;
margin-right:10px;
margin-bottom:20px;
}
</style>
</head>
<body>
<div data-role="page" id="loginPage">
<div data-role="header" data-position="fixed">
<h1>Welcome</h1>
</div><!-- /header -->
<div data-role="content">
<div id="formLogin">
<p>
<label for="usertext">Please enter your username:</label>
<input type="text" id="usernameText"/>
</p>
<p>
<a href="#chatPage" data-role="button">Submit</a>
</p>
</div>
</div>
</div>
<div data-role="page" id="chatPage">
<div data-role="header" data-position="fixed">
<h1>Let's chat</h1>
</div>
<div data-role="content">
<div class="listDiv">
<ul id="messages" data-role="listview">
</ul>
</div>
<div>
<!-- <label for="messageText">Your message</label> -->
<input type="text" id="messageText"/>
<button id="sendButton" >Send</button>
</div>
</div>
</div>
</body>
</html>