-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatroom.html
75 lines (57 loc) · 1.6 KB
/
chatroom.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
<html>
<head>
<link rel=stylesheet type='text/css' href='chat.css'>
<script src='js/jquery-2.1.4.min.js'> </script>
<script src='socket.io/socket.io.js'></script>
<script>
var name;
var socket = io('http://localhost:3000');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', {my: 'data'});
});
/**
* Capture text only from myself. (Currently)
*/
var updateTextArea = function() {
if($("#inputArea").val() == "") {
console.log("Nothing sent");
} else {
$("#showArea").append(name + " " + $("#inputArea").val() + "<br>");
$("#showArea").animate({scrollTop: $("#showArea")[0].scrollHeight});
$("#inputArea").val("");
socket.emit('messages', $("#inputArea").val());
}
};
$(document).ready( function() {
$( "#button" ).click(updateTextArea);
});
$(document).ready( function() {
$("#inputArea").keypress( function(e) {
if(e.which == 13) {
console.log("enter pressed");
updateTextArea();
// Still need to send something to the server
}
});
});
$(document).ready( function() {
$( "#nameArea" ).keypress( function(e) {
if(e.which == 13) {
console.log("name entered");
name = $("#nameArea").val();
$("#nameArea").hide();
}
})
});
</script>
</head>
<body>
<h1> Chat Room </h1>
<div id='showArea'>
</div>
<input type='text' id='nameArea'>
<input type='text' id='inputArea'>
<input type='submit' value='Enter' id='button'>
</body>
</html>