This repository was archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchattest.php
117 lines (75 loc) · 2.37 KB
/
chattest.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chat</title>
<link rel="stylesheet" href="static/css/chatstyle.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="static/js/chat.js"></script>
<script type="text/javascript">
// ask user for name with popup prompt
var nick = prompt("Enter your chat name:", "Guest");
// default name is 'Guest'
if (!nick || nick === ' ') {
nick = "Guest";
}
// strip tags
nick = nick.replace(/(<([^>]+)>)/ig,"");
// ask user for name with popup prompt
var name = prompt("Enter who you want to chat with:", "Bob");
// default name is 'Guest'
if (!name || name === ' ') {
name = "Bob";
}
// strip tags
name = name.replace(/(<([^>]+)>)/ig,"");
var chat = new Chat(name);
// display name on page
$("#name-area").html("You are: <span>" + nick + "</span>");
$(function() {
chat.getState();
// watch textarea for key presses
$("#sendie").keydown(function(event) {
var key = event.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) {
event.preventDefault();
}
}
});
// watch textarea for release of key press
$('#sendie').keyup(function(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, nick);
$(this).val("");
} else {
$(this).val(text.substring(0, maxLength));
}
}
});
setInterval('chat.update()', 1000);
});
</script>
</head>
<body>
<div id="page-wrap">
<h2>jQuery/PHP Chat</h2>
<p id="name-area"></p>
<div id="chat-wrap"><div id="chat-area"></div></div>
<form id="send-message-area">
<p>Your message: </p>
<textarea id="sendie" maxlength = '100' ></textarea>
</form>
<button onclick="chat.clear()">CLEAR</button>
</div>
</body>
</html>