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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
<?php
htmlHeader(
array('stats'), 'Chat',
'BetaChat for Pathery.com',
array('scores', 'dateformat')
);
?>
<body>
<?php
topbar($Links);
if (!$accepted) {
echo "<center>Please <a href='javascript:showSignin();'>login</a> to chat!</center>";
}
?>
<style>
.chatMessage {
width:99%;
min-height:36px;
margin:4px;
display:block;
clear:both;
}
.chatColumn1 {
float:left;
min-height:36px;
width:15%;
margin:2px;
padding:2px;
height:100%;
background-color:#222;
text-overflow: ellipsis;
white-space:nowrap;
display:block;
}
.chatColumn2 {
float:left;
min-height:36px;
width:81%;
background-color:#222;
margin:2px;
padding:2px;
border-bottom-right-radius: 20px;
border-top-right-radius: 20px;
}
.chatTimestamp {
font-family:"Times New Roman", Times, serif;
float:left;
padding: 5px 3px 3px 3px;
min-width:70px;
overflow:hidden;
text-overflow: ellipsis;
white-space:nowrap;
}
.chatBadge {
height:100%;
float:left;
}
.chatUsername {
font-family:Comic Sans MS, Comic Sans MS5, cursive;
min-height:36px;
text-overflow: ellipsis;
padding: 5px 5px 5px 5px;
}
.chatText {
font-family:Comic Sans MS, Comic Sans MS5, cursive;
min-height:36px;
padding: 5px 5px 5px 5px;
}
.chatInputMessage {
font-family:Comic Sans MS, Comic Sans MS5, cursive;
border: 1px solid gray;
width: 700px;
margin: 4px;
}
.chatButton {
margin: 4px;
}
#chatContainer {
width:800px;
margin:0 auto;
height:400px;
overflow:auto;
}
.chatContainer2 {
width:810px;
margin:0 auto;
height:450px;
overflow:auto;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var lastID = 1;
var chatTimerDelayUpper = 9000;
var chatTimerDelayLower = 2000;
var chatTimerDelay = 5000;
var skipNextGetChat = false;
var chatBuffer = new Array();
getChatTimer();
function getChatTimer() {
setTimeout("getChatTimer()", chatTimerDelay);
if (chatTimerDelay < chatTimerDelayUpper)
chatTimerDelay += 150;
if (skipNextGetChat) {
skipNextGetChat = false;
return;
}
getChat();
}
function getChatDone(data) {
var items = [];
var p; //our prep string
var newChats = false;
////console.log('datalength', data.length);
if (data.length < 3 || data == 'false')
return;
//console.log("START BUILD");
//console.log("JSON TO PARSE", data);
json = jQuery.parseJSON(data);
//console.log("JSON PREPED");
$.each(json, function(key, user) {
var postDate = new Date();
postDate.setTime(postDate.getTime() + user.secondsSince * 1000);
//var timestamp = postDate.format("ddd h:MM TT");
//var timestamp = postDate.format("h:MM:ss");
var timestamp = postDate.format("hh:MM:ss");
//console.log("INSIDE BUILD START");
p = '';
p = p+ " <div class='chatColumn1'>";
p = p+ " <span class='chatTimestamp'>["+timestamp+"]</span>";
p = p+ " <div class='grid_td chatBadge' style='float:left; width:35px; height:35px; background:"+user.wallColor+" url(images/marks/"+user.wallEmblem+");'>";
p = p+ " <div style='background-color:transparent;' class='grid_td_inner grid_td_rocks'>";
p = p+ " </div>";
p = p+ " </div>";
p = p+ " </div>";
p = p+ " <div class='chatColumn2'>";
p = p+ "<span class='chatUsername'><a href='achievements?id="+user.userID+"' style='color:"+user.displayColor+"'>";
p = p+ user.displayName+"</a>:</span>";
p = p+ " <span class='chatText'>";
p = p+ htmlEncode(user.message);
p = p+ " </span>";
p = p+ " </div>";
lastID = user.ID;
items.unshift('<div class="chatMessage" id="' + key + '">' + p + '</div>');
newChats = true;
});
//console.log("BUILD DONE");
if (newChats) {
if (chatTimerDelay > chatTimerDelayLower)
chatTimerDelay -= 1000;
var new_chatDiv = $('<div/>', {
'class': 'my-new-list',
'style': 'display: none',
html: items.join('')
});
new_chatDiv.prependTo('#chatContainer').slideDown('fast');
}
//console.log('(END) lastID', lastID);
}
function prepChat(chat) {
chat = chat.join('|:|');
chat = chat.replace(/\&/g,'%26')
return chat;
}
function getChat(message) {
//console.log('LASTID:', lastID);
var dataString = 'getChatFromID='+lastID;
if (chatBuffer.length > 0) {
dataString += '&send=true&messages='+prepChat(chatBuffer);
chatBuffer.length = 0;
}
//$.getJSON('ajax_chat.php?getChatFromID='+lastID++message, );
$.ajax({
type: "GET",
url: "ajax_chat.php",
data: dataString,
success: function(data) {getChatDone(data);}
});
}
function sendChat() {
var message = $("input#message").val().replace("|:|", "||");
chatBuffer.push(message);
$("input#message").val('');
if (skipNextGetChat == false) {
skipNextGetChat = true;
getChat();
}
return false;
}
$(document).ready(function() {
$('#sendChat').live("submit", function() {
sendChat()
});
});
function htmlEncode(value){
if (value) {
return jQuery('<div />').text(value).html();
} else {
return '';
}
}
</script>
<h3>Pathery Chat - BETA</h3>
<div class='chatContainer2'>
<form id='sendChat' onsubmit="return false">
<? if($accepted) { /*Only show the chat button if we're logged in*/ ?>
<input type="hidden" name="stuff" value="1724">
<input class='chatButton' type="button" class="send" id='chatSendBtn' value='Send' onClick="sendChat();">
<input class='chatInputMessage' type="text" name="message" id="message" value="" maxlength="255" autocomplete="off" >
<? } ?>
</form>
<div id='chatContainer'>
</div>
</div>
<?
htmlFooter();
?>
|