summaryrefslogtreecommitdiffstats
path: root/pages/chat.php
diff options
context:
space:
mode:
authorPatrick Davison <snapwilliam@gmail.com>2013-01-15 01:22:15 -0800
committerPatrick Davison <snapwilliam@gmail.com>2013-01-15 01:22:15 -0800
commit43067b7e18c0bd44f703a8bee8770bcdab674f20 (patch)
tree4f492083a9675bb6cefec53d6e1c1f0da1870643 /pages/chat.php
parentcb9620d7917cc7fa4aeee54b21d32593a50b081c (diff)
downloadpathery-43067b7e18c0bd44f703a8bee8770bcdab674f20.tar.xz
This is the chat app* whoops.
Diffstat (limited to 'pages/chat.php')
-rw-r--r--pages/chat.php220
1 files changed, 220 insertions, 0 deletions
diff --git a/pages/chat.php b/pages/chat.php
new file mode 100644
index 0000000..11bb935
--- /dev/null
+++ b/pages/chat.php
@@ -0,0 +1,220 @@
+<?php
+htmlHeader(
+ array('stats'), 'Chat',
+ 'BetaChat for Pathery.com',
+ array('scores', 'dateformat')
+);
+?>
+<body>
+<?php
+topbar($Links);
+
+?>
+
+<style>
+.chatMessage {
+ width:99%;
+ height:40px;
+ margin:5px;
+ background-color:#222;
+ display:block;
+ white-space:nowrap;
+ overflow-x:hidden;
+}
+.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;
+}
+.chatUsername {
+ font-family:Comic Sans MS, Comic Sans MS5, cursive;
+ float:left;
+ padding: 5px 0px 3px 3px;
+ min-width:60px;
+ overflow:hidden;
+ text-overflow: ellipsis;
+ white-space:nowrap;
+}
+.chatText {
+ font-family:Comic Sans MS, Comic Sans MS5, cursive;
+ width:99%;
+ float:left;
+ padding: 5px 0px 3px 3px;
+ width:330px;
+
+}
+
+#chatContainer {
+ border:1px solid red;
+ width:600px;
+ margin:0 auto;
+ height:400px;
+ overflow:auto;
+}
+.chatContainer2 {
+ border:1px solid yellow;
+ width:610px;
+ 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 chatTimerDelay = 5000;
+
+var skipNextGetChat = false;
+
+var chatBuffer = new Array();
+
+getChatTimer();
+function getChatTimer() {
+ setTimeout("getChatTimer()", chatTimerDelay);
+ if (skipNextGetChat) {
+ skipNextGetChat = false;
+ return;
+ }
+ getChat();
+}
+
+
+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");
+
+ console.log("INSIDE BUILD START");
+ p = '';
+ p = p+ " <span class='chatTimestamp'>["+timestamp+"]</span>";
+ p = p+ " <div class='grid_td' 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+ "<span class='chatUsername'><a href='achievements?id="+user.userID+"' style='color:"+user.displayColor+"'>";
+ //p = p+ user.dateSent+": ";
+ p = p+ user.displayName+"</a>:</span>";
+
+ p = p+ " <span class='chatText'>";
+ p = p+ htmlEncode(user.message);
+ p = p+ " </span>";
+
+ lastID = user.ID;
+
+ items.unshift('<div class="chatMessage" id="' + key + '">' + p + '</div>');
+ newChats = true;
+ });
+
+ console.log("BUILD DONE");
+
+ if (newChats) {
+ 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 getChat(message) {
+ console.log('LASTID:', lastID);
+ var dataString = 'getChatFromID='+lastID;
+ if (chatBuffer.length > 0) {
+ dataString += '&send=true&messages='+chatBuffer.join('|:|');
+ 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>this page will overflow...</h3>
+
+<div class='chatContainer2'>
+ <form id='sendChat' onsubmit="return false">
+ <input type="hidden" name="stuff" value="1724">
+ <input type="text" name="message" id="message" value="" maxlength="255" autocomplete="off" >
+ <input type="button" class="send" id='chatSendBtn' value='Send' onClick="sendChat();">
+ </form>
+ <div id='chatContainer'>
+
+ </div>
+
+</div>
+
+
+<?
+
+
+htmlFooter();
+?> \ No newline at end of file