This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
138 lines (127 loc) · 3.24 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
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Socket.IO chat</title>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
<style>
html,body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-size: 120%;
font-family: "微軟雅黑","Microsoft YaHei","Arial";
}
ul {
list-style: none;
word-wrap: break-word;
}
.pages {
height: 100%;
width: 100%;
margin: 0;
padding: 0px 0px 50px 0px;
}
/* msgPage */
#msgBox {
height: 100%;
width: 100%;
overflow: scroll;
background: lightblue;
}
/* msgBar */
.msg {
padding-left: 0px;
padding-right: 0px;
}
#talkBar {
height: 50px;
width: 100%;
background: lightgray;
padding-top: 9px;
padding-bottom: 3px;
position: fixed;
bottom: 0;
position: absolute;
}
#messages {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#messages li {
padding: 5px 10px;
}
#messages li:nth-child(odd) {
background: #eee;
}
</style>
</head>
<body>
<div class="pages">
<div id="msgBox">
<ul id="messages"></ul>
</div>
<div class="container-fluid" id="talkBar">
<div class="row">
<div class="col-xs-4 col-sm-3 nickname">
<input type="nickname" class="form-control" id="nickName" placeholder="暱稱">
</div>
<div class="col-xs-5 col-sm-6 msg">
<input type="msg" class="form-control" id="msg" autocomplete="off" placeholder="請輸入訊息...">
</div>
<div class="col-xs-3">
<button type="button" class="btn btn-success btn-block"><li class="fa fa-paper-plane fa-fw"></button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function(){
var socket = io();
var $msgInput = $('#msg');
var $msgBox = $('#msgBox');
var $messages = $('#messages');
$('#talkBar').keypress(function(e) {
var key = window.event ? e.keyCode : e.which;
if (key == 13)
$('button').click();
});
$('button').click(function(){
var nickName = $('#nickName').val();
var msg = $('#msg').val();
if(msg != '')
{
if(nickName == '')
nickName='匿名';
socket.emit('chat message', nickName + ':' + msg);
$('#msg').val('');
$msgInput.focus();
}
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
$msgBox.scrollTop($messages[0].scrollHeight+42);
});
});
</script>
</body>
</html>
<!-- Test code -->
<!-- $(function(){
var text=0;
function msgPost(){
$('#msg').val(text++);
$('button').click();
}
setInterval(msgPost,500);
}) -->