-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
130 lines (106 loc) · 4.04 KB
/
index.php
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Floydian Lands - IF Forever Wandering</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="chat/chat.js"></script>
<script type="text/javascript">
$("document").ready(function(){
//ask user for name with popup prompt
var name = prompt("Enter your chat name:", "Guest");
<<<<<<< HEAD
//default name is 'Guest'
//TODO random unique username generation
if (!name || name === ' ') {
name = "Guest";
}
//strip tags
name = name.replace(/(<([^>]+)>)/ig,"");
=======
//display name on page (sanitized)
$("$username").html("You are: <span id='username></span>");
$("$username span").text(name)
>>>>>>> pr/1
//display name on page (Unused)
$("#name-area").html("You are: <span id='username'>" + name + "</span>");
//start chat
var chatlogid = "chatlog"
var cmdlogid = "cmdlog"
var chat = new Chat(TypeEnum.CHAT, chatlogid);
var cmd = new Chat(TypeEnum.CMD, cmdlogid);
// watch textarea for key presses
// TODO 'someone is typing' alert, toggleable
function downhandler(e) {
var key = e.which;
//all keys including return.
if (key >= 33) {
var maxLength = $(this).attr("maxlength");
var length = this.value.length;
//don't allow new content if length is maxed out
if (length >= maxLength) {
e.preventDefault();
}
}
}
//watch textarea for key release
function uphandlercreate(chat) {
function uphandler(e) {
if (e.keyCode == 13) {
var text = $(this).val();
var maxLength = $(this).attr("maxlength");
var length = text.length;
// send
if (length <= maxLength + 1) {
chat.send(text, name);
$(this).val("");
} else {
$(this).val(text.substring(0, maxLength));
}
}
}
return uphandler;
}
var uphandlerchat = uphandlercreate(chat);
var uphandlercmd = uphandlercreate(cmd);
$(function() {
$("#sendbox").keydown(downhandler);
$("#sendbox").keyup(uphandlerchat);
$("#cmdbox").keydown(downhandler);
$("#cmdbox").keyup(uphandlercmd);
});
setInterval(chat.update, 1000, chat);
setInterval(cmd.update, 1000, cmd);
});
</script>
</head>
<body>
<div id="wrapper">
<header>
<nav>Test | Things | All | Go | Here</nav>
</header>
<div id="chat">
<!--<p id="name-area"></p>-->
<div id="chatlog"></div>
<form id="chat-send-area">
<textarea id="sendbox" maxlength='300'>Enter a message here.</textarea>
</form>
</div>
<div id="leftpane">
<div id="gargoyle"><img src="http://i.imgur.com/KPGUhid.jpg?1" /></div>
<div id="command">
<div id="cmdlog"></div>
<form id="cmd-send-area">
<b>></b><textarea id="cmdbox" maxlength='300'></textarea>
</form>
</div>
</div>
</div>
</body>
</html>