/** * @fileoverview Pickleview is a live MLB stat-tracking web application. * It tracks any team you choose. * * @author Richard Herrera doctyper.com * @author Ryan Christianson ryancafe.com * @author Estelle Weyl estelleweyl.com * @author Wai Seto * @version 1.0 * * @license Pickleview is released according to the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License. You are free to learn from it, distribute and modify (as long as you share alike). * @license-url http://creativecommons.org/licenses/by-nc-sa/3.0/ */ var url = "/php/xml-small-proxy.php?public=1", tweetSource = "http://m.twitter.com/", // this is html ready to be added chatScheadule = [], chatsSeen = [], doChatUpdates = false, currentValidSeries = 1, maxChats = 5, chatInterval = 5, escapeHtml = function(message) { message = message.replace(/' + RegExp.$1 + ''); } return message; }, // this goes and gets more chats fetchNewChats = function(seriesNumber) { // this is to kill old setime outs from an older pause if (seriesNumber != currentValidSeries) { return; } if (!doChatUpdates) { return; } var req = new XMLHttpRequest(); req.open("GET", url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if(req.status == 200) { gotNewChats(req.responseText, req.responseXML); $P.FetchNewChats = setTimeout("fetchNewChats(" + currentValidSeries + ")", 30000); } else { console.log("Error loading page\n"); startChatUpdates(); } } }; req.send(null); }, // this is called when ever we get new chats gotNewChats = function(xmlString, xmlObject) { var ithMessage = 0, msgs = findChild(xmlObject, "msgs"); if (msgs) { var nodes = msgs.childNodes; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; if (child.nodeType == 1) { if (child.tagName == "m") { addChat(child, ithMessage); ithMessage++; } } } } }, // iphone.hacks@mac.com insertLeftIcon = false, addChat = function(messageTag, ithMessage) { var message = getElementTagText(messageTag, "t"), guid = getElementTagText(messageTag, "g"), userName = getElementTagText(messageTag, "n"), iconUrl = "http://pickleview.com/php/profile-image.php?u=" + userName || getElementTagText(messageTag, "i"); guid = "a" + guid; // check if we have seen this chat if (chatsSeen[ guid ] == true) { return; } iconUrl = iconUrl.replace("/normal", "/mini/"); // Twitter does not allow us to cache images! Here's a workaround: // if (/\?/.test(iconUrl)) { // iconUrl = iconUrl.split("?")[0]; // } html = ""; haloLink = tweetSource + userName + '/'; html += ''; scheaduleNewChat(html, guid); }, // add a chat to the doc addChatToDoc = function(html) { var messages = $("PickleTalk"); // see how many chats there are if (messages.childNodes.length >= maxChats) { messages.removeChild(messages.childNodes[messages.childNodes.length -1]); } messages.innerHTML = html + messages.innerHTML; // get the id var firstElement = messages.childNodes[0], slideElementId = firstElement.getAttribute("id"); slideElementIn(slideElementId); }, slideElementIn = function(elementId) { var slide; if ($P.AnnouncePlay.timeout) { setTimeout(function() { new $P.slide($(elementId)); }, 2000); } else { setTimeout(function() { new $P.slide($(elementId)); }, 10); } }, addNewChatLoop = function(seriesNumber) { if (seriesNumber != currentValidSeries) { return; } if (!doChatUpdates) { return; } var newChatHtml = chatScheadule.pop(); if(newChatHtml) { addChatToDoc(newChatHtml); } $P.ChatInterval = setTimeout("addNewChatLoop(" + currentValidSeries + ")", (chatInterval * 1000)); }, scheaduleNewChat = function(html, guid) { if (chatsSeen[guid] == true) { return; } chatsSeen[guid] = true; chatScheadule.push(html); }, // get the text of a child tag getElementTagText = function(node, tagName) { node = findChild(node, tagName); return getElementText(node); }, // find a child of a parent findChild = function(node, tagName) { var nodes = node.childNodes; for (var i = 0; i < nodes.length; i++) { var child = nodes[i]; if (child.nodeType == 1) { if (child.tagName == tagName) { return child; } } } // return null; }, // get the text from a node getElementText = function(node) { return node.textContent; }, popupSeriesHide = 1, baseInfo = [];