forked from Flotype/now
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiroomchat.html
49 lines (41 loc) · 1.11 KB
/
multiroomchat.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>nowjs test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="/nowjs/now.js"></script>
<script>
$(document).ready(function(){
now.receiveMessage = function(name, message){
$("#messages").append("<br><b>" + name + "</b>: " + message);
}
$("#send-button").click(function(){
now.distributeMessage($("#text-input").val());
$("#text-input").val("");
});
$(".change").click(function(){
now.changeRoom($(this).text());
});
$("#text-input").keypress(function (e) {
if (e.which && e.which === 13) {
$("#send-button").click();
return false;
}
});
now.name = prompt("What's your name?", "");
$("#text-input").focus();
});
</script>
</head>
<body>
<div>
<a href="#" class="change selected">room 1</a> -
<a href="#" class="change">room 2</a> -
<a href="#" class="change">room 3</a>
</div>
<br>
<div id="messages"><br>You're in room 1</div>
<input type="text" id="text-input">
<input type="button" value="Send" id="send-button">
</body>
</html>