Skip to content

Commit 9a3c191

Browse files
author
dodortus
committed
* submit 수정
1 parent ae506fc commit 9a3c191

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

contents/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ input[type="text"] { padding: 2px 5px; border: solid 1px #bbb; font-size: 1.3em;
4242
header { position: relative; margin-bottom: 10px; }
4343

4444
/* chat */
45-
#chat-wrap { margin: 0 auto; width: 300px; }
45+
#chat-wrap { margin: 0 auto; width: 340px; }
4646
#chat-wrap input[type="text"] {
4747
width: 200px; font-size: 14px; padding: 6px; background: rgba(255,255,255,0.8); font-family: inherit;
4848
}

contents/js/base.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66
*/
77
$(function() {
88
var socket = io();
9+
var nickName = 'user-' + new Date().getTime();
910
var $msgInput = $('#message');
1011

1112
$('form').submit(function() {
12-
socket.emit('message', $msgInput.val());
13+
socket.emit('message', {
14+
nickName: nickName,
15+
body: $msgInput.val()
16+
});
1317
$msgInput.val('');
1418
return false;
1519
});
1620

1721
socket.on('message', function(msg) {
1822
console.log('message', msg);
19-
$('#chat-content').append($('<li/>').text(msg));
23+
24+
$('#chat-content').append([
25+
"<li>",
26+
"<h3 class='name'>" + msg.nickName + "</h3>",
27+
"<p class='message'>" + msg.body + "</p>",
28+
"</li>"
29+
]);
2030
});
2131
});

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"version": "0.0.1",
55
"description": "nodejs simple chatting.",
66
"dependencies": {
7-
"express": "4.13.*",
8-
"ejs": "2.4.*",
9-
"socketio": "1.4.*"
7+
"express": "4.13.4",
8+
"ejs": "2.4.1",
9+
"socket.io": "1.4.5"
1010
},
1111
"engine": {
1212
"node": "0.12.x"

0 commit comments

Comments
 (0)