summaryrefslogtreecommitdiffstats
path: root/pages
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-02-24 03:39:15 -0800
committerPatrick Davison <snapwilliam@gmail.com>2013-02-24 03:39:15 -0800
commit2875c699c07de67e9f010d5610283ebcc43e50a7 (patch)
tree3db4b22fd780aab70a2387cf1d639136166da7c6 /pages
parent438184ffc7ec1e447668c22b09416c984a9c12f2 (diff)
downloadpathery-2875c699c07de67e9f010d5610283ebcc43e50a7.tar.xz
Added /spoiler command to chat - Fixed issue with 2 quick succession chats being very slow.
Diffstat (limited to 'pages')
-rw-r--r--pages/chat.php55
1 files changed, 34 insertions, 21 deletions
diff --git a/pages/chat.php b/pages/chat.php
index b90226c..67c6831 100644
--- a/pages/chat.php
+++ b/pages/chat.php
@@ -58,52 +58,59 @@ function getChatDone(data) {
//console.log("JSON PREPED");
- $.each(json, function(key, user) {
+ $.each(json, function(key, chat) {
var postDate = new Date();
- postDate.setTime(postDate.getTime() + user.secondsSince * 1000);
+ postDate.setTime(postDate.getTime() + chat.secondsSince * 1000);
//var timestamp = postDate.format("ddd h:MM TT");
//var timestamp = postDate.format("h:MM:ss");
var timestamp = postDate.format("hh:MM:ss");
var strClass = '';
- if (user.userID == userObj.ID) {
+ if (chat.userID == userObj.ID) {
strClass += ' self';
- }
- if (user.userID == '-1') {
+ }
+ if (chat.userID == '-1') {
strClass += ' server';
- user.displayName = 'SERVER'
+ chat.displayName = 'SERVER'
+ }
+
+ var isSpoiler = false;
+ if (chat.message.indexOf("/spoiler ") == 0) {
+ chat.message = chat.message.substring(9);
+ isSpoiler = true;
}
//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 class='grid_td chatBadge' style='float:left; width:35px; height:35px; background:"+chat.wallColor+" url(images/marks/"+chat.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'>";
- if (user.userID == '-1') {
+ if (chat.userID == '-1') {
p = p+ "<span class='chatUsername'><a href='home'>";
} else {
- p = p+ "<span class='chatUsername'><a href='achievements?id="+user.userID+"' style='color:"+user.displayColor+"'>";
+ p = p+ "<span class='chatUsername'><a href='achievements?id="+chat.userID+"' style='color:"+chat.displayColor+"'>";
}
- p = p+ user.displayName+"</a>:</span>";
+ p = p+ chat.displayName+"</a>:</span>";
- p = p+ " <span class='chatText'>";
- p = p+ htmlEncode(user.message);
+ if (isSpoiler == true) p = p+ " <span class='chatText spoiler' onclick='spoil(this);'>";
+ else p = p+ " <span class='chatText'>";
+ p = p+ htmlEncode(chat.message);
p = p+ " </span>";
p = p+ " </div>";
//Message is legitmently new or a server message?
- if (user.ID > lastID || typeof(user.ID) == 'undefined') {
- items.push('<div class="chatMessage'+strClass+'" id="C_' + user.ID + '">' + p + '</div>');
+ if (chat.ID > lastID || typeof(chat.ID) == 'undefined') {
+ items.push('<div class="chatMessage'+strClass+'" id="C_' + chat.ID + '">' + p + '</div>');
newChats = true;
}
- if (user.ID > 0) lastID = user.ID;
+ if (chat.ID > 0) lastID = chat.ID;
});
//console.log("BUILD DONE");
@@ -111,11 +118,12 @@ function getChatDone(data) {
if (newChats) {
if (chatTimerDelay > chatTimerDelayLower) chatTimerDelay -= 1000;
- var new_chatDiv = $('<div/>', {
- 'class': 'my-new-list',
+ //var new_chatDiv = $('<div/>', {
+ //'class': 'my-new-list',
//'style': 'display: none',
- html: items.join('')
- });
+ //html: items.join('')
+ //});
+
var elem = $("#chatContainer");
//var atBottom = (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight());
var atBottom = (elem.scrollTop() >= elem[0].scrollHeight - elem.outerHeight() - 1);
@@ -124,7 +132,8 @@ function getChatDone(data) {
//var elem = $("#chatContainer"); console.log ("Ret", elem[0].scrollHeight, elem.scrollTop(), elem.outerHeight(), elem[0].scrollHeight - elem.scrollTop());
//new_chatDiv.appendTo('#chatContainer').slideDown('fast');
- new_chatDiv.appendTo('#chatContainer');
+ //new_chatDiv.appendTo('#chatContainer');
+ $("#chatContainer").append(items.join(''));
if (atBottom || firstGetChat) {
$("#chatContainer").scrollTop($("#chatContainer")[0].scrollHeight);
@@ -144,6 +153,10 @@ function prepChat(chat) {
return chat;
}
+function spoil(obj) {
+ $(obj).removeClass("spoiler");
+}
+
function getChat(message) {
var dataString = 'getChatFromID='+lastID;
if (chatBuffer.length > 0) {
@@ -166,8 +179,8 @@ function sendChat() {
$("input#message").val('');
if (skipNextGetChat == false) {
skipNextGetChat = true;
- getChat();
}
+ getChat();
return false;
}