From 2875c699c07de67e9f010d5610283ebcc43e50a7 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Sun, 24 Feb 2013 03:39:15 -0800 Subject: Added /spoiler command to chat - Fixed issue with 2 quick succession chats being very slow. --- ajax/chat.ajax.php | 7 +++++-- css/chat.css | 10 ++++++++++ pages/chat.php | 55 +++++++++++++++++++++++++++++++++--------------------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 02fc396..5ac77e4 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -50,9 +50,12 @@ if ($_REQUEST['messages']) { } } //Anyone commands: + if ($command == 'spoiler') { + $insertID = addchat($userID, $message); + } if ($command == 'help') { $r[0]['serverMessage'] = 'true'; - $r[0]['message'] = "Commands: /help /time . - Chat by Pathery.com"; + $r[0]['message'] = "Commands: /help /time /spoiler . - Chat by Pathery.com"; $r[0]['secondsSince'] = 0; $r[0]['userID'] = -1; echo json_encode($r); @@ -66,7 +69,7 @@ if ($_REQUEST['messages']) { echo json_encode($r); exit; } - } else { + } else { $insertID = addchat($userID, $message); } } diff --git a/css/chat.css b/css/chat.css index 0b38d70..c10be74 100644 --- a/css/chat.css +++ b/css/chat.css @@ -95,6 +95,16 @@ background-color: #844; } +.chatText.spoiler { + color:transparent; +} +.chatText.spoiler:before { + content: " Click to reveal Spoiler "; + color:#7AF; + font-style: italic; +} + + .chatContainer2 { background-color: #222; padding:10px; 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+ "
"; p = p+ " ["+timestamp+"]"; - p = p+ "
"; + p = p+ "
"; p = p+ "
"; p = p+ "
"; p = p+ "
"; p = p+ "
"; p = p+ "
"; - if (user.userID == '-1') { + if (chat.userID == '-1') { p = p+ ""; } else { - p = p+ ""; + p = p+ ""; } - p = p+ user.displayName+":"; + p = p+ chat.displayName+":"; - p = p+ " "; - p = p+ htmlEncode(user.message); + if (isSpoiler == true) p = p+ " "; + else p = p+ " "; + p = p+ htmlEncode(chat.message); p = p+ " "; p = p+ "
"; //Message is legitmently new or a server message? - if (user.ID > lastID || typeof(user.ID) == 'undefined') { - items.push('
' + p + '
'); + if (chat.ID > lastID || typeof(chat.ID) == 'undefined') { + items.push('
' + p + '
'); 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 = $('
', { - 'class': 'my-new-list', + //var new_chatDiv = $('
', { + //'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; } -- cgit v1.2.3