/** * @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/ */ /** * Get first element by tag name * @param {String} e The element to grab * @param {String} f The parent node. If no parent, use document */ var $E = $E || function(e, f) { f = f || document; return f.getElementsByTagName(e)[0]; }; /** * Shorthand getElementById * @param {String} e The element id */ var $ = $ || function(e) { return document.getElementById(e); }; /** * Set, Get, and Delete Cookies * @class This is the Cookie "class" * @param {String} cookieName The name of the cookie * @param {String} cookieValue The cookie value */ var Cookie = function() { return { get : function(name) { var start = document.cookie.indexOf(name + "="); var len = start + name.length + 1; if ((!start) && (name != document.cookie.substring(0, name.length))) { return null; } if (start == -1) { return null; } var end = document.cookie.indexOf(';', len); if (end == -1) { end = document.cookie.length; } return unescape(document.cookie.substring(len, end)); }, set : function(name, value, expires, path, domain, secure) { var today = new Date(); today.setTime(today.getTime()); if (expires) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + '=' + escape(value) + ((expires) ? ';expires=' + expires_date.toGMTString() : '') + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ((secure) ? ';secure' : ''); }, del : function(name, path, domain) { if (Cookie.get(name)) { document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; } } }; }(); /** * Remembers your selected team */ var MyFavoriteTeam = Cookie.get("MyPickleviewTeam") || "LA Angels"; /** * Shorthand for Pickleview */ var $P; /** * The Pickleview object * @class This is the Pickleview "class" * @constructor */ var Pickleview = { myTeam : MyFavoriteTeam, maxChats : 5, currentWidth : 0, init : function() { if (!$("Pickleview")) { return; } else { var nojs = $E("div", $("Pickleview")); if (nojs) { var LoadScores = document.createElement("div"); LoadScores.setAttribute("id", "LoadScores"); LoadScores.innerHTML = '

Loading Latest Game Info...

'; $("Pickleview").replaceChild(LoadScores, nojs); } } if (!$P.loadImagesOnce) { /** * Let's preload some images */ var images = [ "/img//loader/default.gif", "/img/bubble/corners.png", "/img/bubble/edges.png", "/img/bubble/alt/corners.png", "/img/bubble/alt/edges.png", "/img/combo-bg.png", "/img/options/blueButton.png", "/img/options/grayButton.png", "/img/options/whiteButton.png", "/img/options/whiteButtonMini.png", "/img/options/grayButtonMini.png", "/img/popup.png", "/img/score/old-score.png", "/img/score/new-score.png", "/img/score/td-bg.png", "/img/title-button.png" ]; for (var i = images.length - 1; i >= 0; i--) { var img = new Image(); img.src = images[i]; } $P.loadImagesOnce = true; } if ($P.trigger) { clearTimeout($P.trigger); } $P.PlayByPlay = true; $P.url = "php/proxy.php"; var url = $P.url + "?output=" + $P.getDate() + "/miniscoreboard.xml"; var req = new XMLHttpRequest(); req.open("GET", url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.handle(req.responseXML); $P.GamesXML = url; } else { console.log("Error: " + req.status + " on $P.init()"); $P.init(); } } }; req.send(null); var cal = new Date(), date = cal.getDate().toString(), day = cal.getDay().toString(), days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], target = $("date").firstChild; if (date.length && date.length < 2) { date = "0" + date; } target.nodeValue = days[day] + " " + date; }, getDate : function(e) { var theDate = new Date(); theDate = new Date(theDate.valueOf() - 36000000 + (theDate.getTimezoneOffset() * 60000)); var year = theDate.getFullYear().toString(), month = (theDate.getMonth() + 1).toString(), day = theDate.getDate().toString(), daysInMonth = 32 - new Date(year, month, 32).getDate(), date = theDate.getDay(), gid; if (e) { if (e < daysInMonth) { $P.day = ($P.day + 1) || ((day * 1) + 1); } else { $P.day = 1; month = (parseInt(month) + 1).toString(); } } if (month.length !== 2) { month = "0" + month; } day = $P.day || day; if (typeof day !== "String") { day = day.toString(); } if (day.length !== 2) { day = "0" + day; } $P.date = date; return "year_" + year + "/" + "month_" + month + "/" + "day_" + day; }, showLoadingIcon : function() { var target = $("td2"); if (target) { if (target.firstChild) { target.removeChild(target.firstChild); } var image = document.createElement("img"); image.setAttribute("src", "/img/loader/white.gif"); image.setAttribute("alt", ""); image.setAttribute("id", "loadScores"); target.className = "active"; target.appendChild(image); } }, handle : function(e) { if ((!e) || (!$E("games", e))) { // No games at all today... req = new XMLHttpRequest(); var url = $P.url + "?output=" + $P.getDate(true) + "/" + "miniscoreboard.xml"; req.open("GET", url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.handle(req.responseXML); $P.GamesXML = url; // Snap to top onload if (!$P.TriggerTop) { setTimeout(function() { window.scrollTo(0, 1); }, 3000); $P.TriggerTop = true; } } else { console.log("Error: " + req.status + " on $P.handle()"); $P.handle(); } } }; req.send(null); return; } // I need a game ID, Dont'cha know... var games = e.getElementsByTagName("games")[0].getElementsByTagName("game"), file = "miniscoreboard.xml", gameArray = [], game, g, i, j; if (!$P.GamesTodayOnly) { var gamesToday = []; $P.GamesTodayOnly = true; } for (i = 0, j = games.length; i < j; i++) { g = games[i]; if (gamesToday) { gamesToday.push(g); $P.GamesToday = gamesToday; } if ((g.getAttribute("home_team_city") === $P.myTeam) || (g.getAttribute("away_team_city") === $P.myTeam) || (g.getAttribute("home_team_city") === "NL All-Stars") || (g.getAttribute("away_team_city") === "NL All-Stars")) { if ((g.getAttribute("home_team_city") === "NL All-Stars") || (g.getAttribute("away_team_city") === "NL All-Stars")) { $P.myTeam = g.getAttribute("home_team_city"); } else { gameArray.push(g); } } } if (gameArray.length > 1) { // Doubleheader! if (((gameArray[0].getAttribute("status") != "Game Over") && (gameArray[0].getAttribute("status") != "Final")) || $P.showFirstOfTwo) { g = gameArray[0]; $P.showFirstOfTwo = false; } else { g = gameArray[1]; } } else { g = gameArray[0]; } if (g) { var dir = g.getAttribute("gameday_link"); $P.home = g.getAttribute("home_team_city"); $P.away = g.getAttribute("away_team_city"); $P.league = g.getAttribute("league"); // If game is in progress, load miniscoreboard // Else load linescore file = (g.getAttribute("status") == "In Progress") ? "miniscoreboard.xml" : "linescore.xml"; if ($P.home === $P.myTeam) { $P.weAre = { team : $P.home, runs : g.getAttribute("home_team_runs"), link : g.getAttribute("home_preview_link"), div : g.getAttribute("home_division") }; $P.theyAre = { team : $P.away, runs : g.getAttribute("away_team_runs"), link : g.getAttribute("away_preview_link"), div : g.getAttribute("away_division") }; } else if ($P.away === $P.myTeam) { $P.weAre = { team : $P.away, runs : g.getAttribute("away_team_runs"), link : g.getAttribute("away_preview_link"), div : g.getAttribute("away_division") }; $P.theyAre = { team : $P.home, runs : g.getAttribute("home_team_runs"), link : g.getAttribute("home_preview_link"), div : g.getAttribute("home_division") }; } } gamesToday = null; var link, req; if (!$P.weAre) { // No game today, so let's try tomorrow req = new XMLHttpRequest(); req.open("GET", $P.url + "?output=" + $P.getDate(true) + "/" + file, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.handle(req.responseXML); } else { console.log("Error: " + req.status); $P.init(); } } }; req.send(null); } else { // Yay, there's a home game today! Ok, now let's get the attributes we need and parse the directory // Saving my link to the namespace $P.linescore = $P.getDate() + "/gid_" + dir + "/" + file; req = new XMLHttpRequest(); req.open("GET", $P.url + "?output=" + $P.linescore, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.game(req.responseXML); } else { console.log("Error: " + req.status); $P.init(); } } }; req.send(null); } $P.games = games; }, reload : function() { if ($P.trigger) { clearTimeout($P.trigger); } $P.showLoadingIcon(); req = new XMLHttpRequest(); req.open("GET", $P.url + "?output=" + $P.linescore, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.game(req.responseXML); } else { console.log("Error: " + req.status + " on $P.reload()"); $P.reload(); } } }; req.send(null); }, game : function(e) { var parent = $("Pickleview"); var loader = $("LoadScores"); // I need a game ID, Dont'cha know... var g = $E("game", e), batter = $E("batter", e), pitcher = $E("pitcher", e); var PickleSplit; // Splitting out the cities of multi-city teams... if (($P.away.indexOf("LA ") !== -1) || ($P.away.indexOf("NY ") !== -1) || $P.away.indexOf("Chi ") !== -1) { PickleSplit = $P.away.split(" "); $P.away = PickleSplit[1]; if (PickleSplit[2]) { $P.away += " " + PickleSplit[2]; } if ($P.myTeam.indexOf($P.away) !== -1) { $P.myTeam = $P.away; } } if (($P.home.indexOf("LA ") !== -1) || ($P.home.indexOf("NY ") !== -1) || $P.home.indexOf("Chi ") !== -1) { PickleSplit = $P.home.split(" "); $P.home = PickleSplit[1]; if (PickleSplit[2]) { $P.home += " " + PickleSplit[2]; } if ($P.myTeam.indexOf($P.home) !== -1) { $P.myTeam = $P.home; } } if (!g || !g.attributes) { // something went screwy, reload... throw "No game found"; //$P.trigger = setTimeout($P.reload, 3000); } gameInfo = { away : { city : $P.away, abbr : g.getAttribute("away_name_abbrev"), file : g.getAttribute("away_file_code") }, home : { city : $P.home, abbr : g.getAttribute("home_name_abbrev"), file : g.getAttribute("home_file_code") }, time : g.getAttribute("time"), ampm : g.getAttribute("ampm"), day : g.getAttribute("day"), ind : g.getAttribute("ind"), wrapup : g.getAttribute("wrapup_link") }; var checkStatus = $E("game_status", g); if (gameInfo.status && ((checkStatus && checkStatus.getAttribute("status")) || g.getAttribute("status"))) { var currStatus = checkStatus.getAttribute("status") || g.getAttribute("status"); if (gameInfo.status != currStatus) { gameInfo.status = currStatus; $P.init($P.myTeam); } } //var checkStatus = $E("game_status", g); if (checkStatus) { gameInfo.status = checkStatus.getAttribute("status"); gameInfo.inning = checkStatus.getAttribute("inning"); gameInfo.outs = checkStatus.getAttribute("o") || 0; gameInfo.top_inning = checkStatus.getAttribute("top_inning"); } if (g.getAttribute("status")) { gameInfo.status = g.getAttribute("status"); gameInfo.inning = g.getAttribute("inning"); gameInfo.outs = g.getAttribute("outs"); gameInfo.top_inning = g.getAttribute("top_inning"); } if ($E("runner_on_1b", g)) { gameInfo._1b = $E("runner_on_1b", g).getAttribute("first") + " " + $E("runner_on_1b", g).getAttribute("last"); gameInfo._2b = $E("runner_on_2b", g).getAttribute("first") + " " + $E("runner_on_2b", g).getAttribute("last"); gameInfo._3b = $E("runner_on_3b", g).getAttribute("first") + " " + $E("runner_on_3b", g).getAttribute("last"); gameInfo.pbp = $E("in_game", g).getAttribute("last_pbp"); } if ($E("r", g)) { gameInfo.away.runs = $E("r", g).getAttribute("away"); gameInfo.away.hits = $E("h", g).getAttribute("away"); gameInfo.away.erro = $E("e", g).getAttribute("away"); gameInfo.home.runs = $E("r", g).getAttribute("home"); gameInfo.home.hits = $E("h", g).getAttribute("home"); gameInfo.home.erro = $E("e", g).getAttribute("home"); } if (g.getAttribute("home_team_runs")) { gameInfo.away.runs = g.getAttribute("away_team_runs"); gameInfo.away.hits = g.getAttribute("away_team_hits"); gameInfo.away.erro = g.getAttribute("away_team_errors"); gameInfo.home.runs = g.getAttribute("home_team_runs"); gameInfo.home.hits = g.getAttribute("home_team_hits"); gameInfo.home.erro = g.getAttribute("home_team_errors"); } if ($E("post_game", g)) { gameInfo.away.wins = $E("away_team", g).getAttribute("wins"); gameInfo.away.loss = $E("away_team", g).getAttribute("losses"); gameInfo.home.wins = $E("home_team", g).getAttribute("wins"); gameInfo.home.loss = $E("home_team", g).getAttribute("losses"); } if (g.getAttribute("home_win")) { gameInfo.away.wins = g.getAttribute("away_win"); gameInfo.away.loss = g.getAttribute("away_loss"); gameInfo.home.wins = g.getAttribute("home_win"); gameInfo.home.loss = g.getAttribute("home_loss"); } if (gameInfo.time) { // Setting to Local time... var newTime = $P.setLocalTime(gameInfo.time, gameInfo.ampm); } if (gameInfo.day) { // Uncapping, recapping... gameInfo.day = gameInfo.day.toLowerCase(); gameInfo.day = gameInfo.day.replace(gameInfo.day.charAt(0), gameInfo.day.charAt(0).toUpperCase()); var cal = new Date(), day = cal.getDay(), days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; var hour = parseInt(newTime.split(":")[0]), daynight = ((hour > 5) && (hour < 8)) ? "Tonight" : "Today"; switch (gameInfo.day) { case days[day] : gameInfo.day = daynight; break; case days[day + 1] : gameInfo.day = "Tomorrow"; break; } } var suffix = $P.buildSuffix(gameInfo.inning); gameInfo.inning = gameInfo.inning + suffix; var b_first, b_last, p_first, p_last, batting = (gameInfo.top_inning == "Y") ? gameInfo.away.file : gameInfo.home.file, pitching = (gameInfo.top_inning == "Y") ? gameInfo.home.file : gameInfo.away.file; if (pitcher && pitcher.getAttribute("first") && pitcher.getAttribute("first") != "null") { p_first = "first"; p_last = "last"; } else if ($E("current_pitcher", g)) { pitcher = $E("current_pitcher", g); p_first = "first_name"; p_last = "last_name"; } if (batter && batter.getAttribute("first") && batter.getAttribute("first") != "null") { b_first = "first"; b_last = "last"; } else if ($E("current_batter", g)) { batter = $E("current_batter", g); b_first = "first_name"; b_last = "last_name"; } if (p_first && (p_first != "null")) { gameInfo.pitcher = pitcher.getAttribute(p_first).charAt(0) + ". " + pitcher.getAttribute( p_last); $P.renderBase("p", pitching); $P.updateBase("p", pitcher.getAttribute(p_first) + " " + pitcher.getAttribute(p_last), pitcher.getAttribute("id")); } else { gameInfo.pitcher = null; $P.unRenderBase("p"); } if (p_first && (p_first != "null") && b_first && (b_first != "null")) { gameInfo.batter = batter.getAttribute(b_first).charAt(0) + ". " + batter.getAttribute(b_last); $P.renderBase("h", batting); $P.updateBase("h", batter.getAttribute(b_first) + " " + batter.getAttribute(b_last), batter.getAttribute("id")); } else { gameInfo.batter = null; $P.unRenderBase("h"); } if ((gameInfo.away.wins) && (gameInfo.home.wins)) { gameInfo.away.record = "(" + gameInfo.away.wins + "-" + gameInfo.away.loss + ")"; gameInfo.home.record = "(" + gameInfo.home.wins + "-" + gameInfo.home.loss + ")"; } else { gameInfo.away.record = ""; gameInfo.home.record = ""; } if (!$("CurrentGame")) { var dummy = document.createElement("div"); dummy.innerHTML = '
 RHE
    
   
     
     
'; parent.replaceChild(dummy, loader); $E("ul", $("bases")).style.display = "block"; } var table = $("CurrentGame"), a_team = $("a_team").firstChild, a_record = $("a_record").firstChild, h_team = $("h_team").firstChild, h_record = $("h_record").firstChild, status, td; table.className = ""; if (a_team.parentNode.parentNode.getAttribute("id") !== gameInfo.away.abbr) { a_team.parentNode.parentNode.setAttribute("id", gameInfo.away.abbr); } if (a_team.nodeValue !== gameInfo.away.city) { a_team.nodeValue = gameInfo.away.city; } if (a_record.nodeValue !== gameInfo.away.record) { a_record.nodeValue = gameInfo.away.record; } if (h_team.parentNode.parentNode.getAttribute("id") !== gameInfo.home.abbr) { h_team.parentNode.parentNode.setAttribute("id", gameInfo.home.abbr); } if (h_team.nodeValue !== gameInfo.home.city) { h_team.nodeValue = gameInfo.home.city; } if (h_record.nodeValue !== gameInfo.home.record) { h_record.nodeValue = gameInfo.home.record; } var td1 = $("td1"); var link = $("link1"), a_runs = $("a_runs").firstChild, h_runs = $("h_runs").firstChild, a_hits = $("a_hits").firstChild, h_hits = $("h_hits").firstChild, a_erro = $("a_erro").firstChild, h_erro = $("h_erro").firstChild, moreInfo = $("MoreInfo"), tr2 = $E("td", moreInfo), info1 = $("info1").firstChild, info2 = $("info2").firstChild, info3 = $("info3").firstChild, tb = $("tb").firstChild, inning = $("inning").firstChild, outs = $("td2").firstChild, bases = $("bases"); info3.nodeValue = " "; switch (gameInfo.status) { case "Final" : case "Game Over" : case "Completed Early" : case "Postponed" : case "Cancelled" : case "Delayed" : case "Suspended" : $("CurrentGame").className += " inactive"; gameInfo.winner = { name : $E("winning_pitcher", g).getAttribute("last_name") || $E("winning_pitcher", g).getAttribute("last"), wins : $E("winning_pitcher", g).getAttribute("wins"), loss : $E("winning_pitcher", g).getAttribute("losses") }; gameInfo.loser = { name : $E("losing_pitcher", g).getAttribute("last_name") || $E("losing_pitcher", g).getAttribute("last"), wins : $E("losing_pitcher", g).getAttribute("wins"), loss : $E("losing_pitcher", g).getAttribute("losses") }; if ((gameInfo.status === "Final") || (gameInfo.status === "Game Over") ||(gameInfo.status === "Completed Early")) { (gameInfo.status === "Final") ? link.setAttribute("href", "http://mlb.mlb.com" + gameInfo.wrapup) : link.setAttribute("href", "http://mlb.mlb.com"); link.firstChild.nodeValue = gameInfo.status; if (gameInfo.inning != "9th") { link.firstChild.nodeValue += " (" + gameInfo.inning.split("th")[0] + ")"; } td1.appendChild(link); var wp_stats = info1, lp_stats = info2; if (gameInfo.winner.name && gameInfo.loser.name) { wp_stats.nodeValue = "WP: " + gameInfo.winner.name + " (" + gameInfo.winner.wins + "-" + gameInfo.winner.loss + ")"; lp_stats.nodeValue = "LP: " + gameInfo.loser.name + " (" + gameInfo.loser.wins + "-" + gameInfo.loser.loss + ")"; } else { wp_stats.nodeValue = lp_stats.nodeValue = " "; } $P.node.hide([tb.parentNode, inning.parentNode, bases]); $P.node.show([link, moreInfo]); } else { link = document.createElement("span"); link.appendChild(document.createTextNode("This game has been " + gameInfo.status)); td1.appendChild(link); $P.node.hide([link, moreInfo, tb.parentNode, inning.parentNode, bases]); } // If still here, remove loading icon if ($("loadScores")) { $("loadScores").parentNode.className = $("loadScores").parentNode.className.replace("active", ""); $("loadScores").parentNode.removeChild($("loadScores")); } a_runs.nodeValue = (a_runs.nodeValue === gameInfo.away.runs) ? a_runs.nodeValue : gameInfo.away.runs; h_runs.nodeValue = (h_runs.nodeValue === gameInfo.home.runs) ? h_runs.nodeValue : gameInfo.home.runs; a_hits.nodeValue = (a_hits.nodeValue === gameInfo.away.hits) ? a_hits.nodeValue : gameInfo.away.hits; h_hits.nodeValue = (h_hits.nodeValue === gameInfo.home.hits) ? h_hits.nodeValue : gameInfo.home.hits; a_erro.nodeValue = (a_erro.nodeValue === gameInfo.away.erro) ? a_erro.nodeValue : gameInfo.away.erro; h_erro.nodeValue = (h_erro.nodeValue === gameInfo.home.erro) ? h_erro.nodeValue : gameInfo.home.erro; // If cookies still exist, trash if (Cookie.get("OurScore")) { Cookie.del("OurScore"); } if (Cookie.get("TheirScore")) { Cookie.del("TheirScore"); } if ($P.PlayXML.trigger) { clearTimeout($P.PlayXML.trigger); $P.PlayXML.trigger = null; } // No game in progress, do the Twitter thang... //startChatUpdates(); break; case "In Progress" : case "Warmup" : $("CurrentGame").className = $("CurrentGame").className.replace("inactive", ""); if ($P.home == $P.myTeam) { $P.weAre.runs = gameInfo.home.runs; $P.theyAre.runs = gameInfo.away.runs; } else if ($P.away == $P.myTeam) { $P.weAre.runs = gameInfo.away.runs; $P.theyAre.runs = gameInfo.home.runs; } if (!$E("img", $("a_team"))) { $("a_team").innerHTML = '' + $("a_team").innerHTML; $("h_team").innerHTML = '' + $("h_team").innerHTML; } if (!$P.changeValueIs) { if (a_runs.nodeValue !== gameInfo.away.runs) { a_runs.nodeValue = gameInfo.away.runs; //$P.fade.up($("CurrentGame")); } if (h_runs.nodeValue !== gameInfo.home.runs) { h_runs.nodeValue = gameInfo.home.runs; //$P.fade.up($("CurrentGame")); } $P.changeValueIs = true; } else { if (a_runs.nodeValue !== gameInfo.away.runs) { $P.changeValue.init($("a_runs"), gameInfo.away.runs); } if (h_runs.nodeValue !== gameInfo.home.runs) { $P.changeValue.init($("h_runs"), gameInfo.home.runs); } } a_hits.nodeValue = (a_hits.nodeValue == gameInfo.away.hits) ? a_hits.nodeValue : gameInfo.away.hits; h_hits.nodeValue = (h_hits.nodeValue == gameInfo.home.hits) ? h_hits.nodeValue : gameInfo.home.hits; a_erro.nodeValue = (a_erro.nodeValue == gameInfo.away.erro) ? a_erro.nodeValue : gameInfo.away.erro; h_erro.nodeValue = (h_erro.nodeValue == gameInfo.home.erro) ? h_erro.nodeValue : gameInfo.home.erro; var half = (gameInfo.top_inning === "Y") ? "Top" : "Bot", outxt = gameInfo.outs + " Out"; // If 3 outs, we're in between innings if ((gameInfo.outs === "3") && (gameInfo.top_inning === "Y")) { half = "Mid"; outxt = " "; } tb.nodeValue = (tb.nodeValue === half) ? tb.nodeValue : half; inning.nodeValue = (inning.nodeValue === gameInfo.inning) ? inning.nodeValue : gameInfo.inning; if (!outs) { $("td2").appendChild(document.createTextNode(" ")); outs = $("td2").firstChild; } if (outs && outs.nodeName && outs.nodeName.toLowerCase() === "img") { outs.parentNode.className = ""; outs.parentNode.replaceChild(document.createTextNode(outxt), outs); } else { outs.nodeValue = (outs.nodeValue === outxt) ? outs.nodeValue : outxt; } if (gameInfo.status === "In Progress") { var a = gameInfo._1b, b = gameInfo._2b, c = gameInfo._3b, p = gameInfo.pitcher, h = gameInfo.batter; if (a == " " || a === null) { a = gameInfo._1b = null; } if (b == " " || b === null) { b = gameInfo._2b = null; } if (c == " " || c === null) { c = gameInfo._3b = null; } if (a) { $P.renderBase("a", batting); $P.updateBase("a", gameInfo._1b, $E("runner_on_1b", g).getAttribute("id")); } else { $P.unRenderBase("a"); } if (b) { $P.renderBase("b", batting); $P.updateBase("b", gameInfo._2b, $E("runner_on_2b", g).getAttribute("id")); } else { $P.unRenderBase("b"); } if (c) { $P.renderBase("c", batting); $P.updateBase("c", gameInfo._3b, $E("runner_on_3b", g).getAttribute("id")); } else { $P.unRenderBase("c"); } var current_pitcher = info1, current_batter = info2; current_pitcher.nodeValue = "P: "; current_batter.nodeValue = "AB: "; if (gameInfo.pitcher) { current_pitcher.nodeValue += gameInfo.pitcher; } if (gameInfo.batter) { current_batter.nodeValue += gameInfo.batter; } if ($P.PlayByPlay) { if (gameInfo.pbp && ($P.PlayByPlay !== gameInfo.pbp)) { $P.PlayByPlay = gameInfo.pbp; $P.AnnouncePlay(); } } $P.node.show([info2.parentNode]); // There's a game going on. Update B/S/O every 12 seconds. // On event change, reload if (!$P.PlayXML.trigger) { $P.PlayXML("plays.xml"); } } else { var warmup = info1; warmup.nodeValue = "Warm ups..."; $P.node.hide([info2.parentNode]); // No game yet. Reload normally. $P.trigger = setTimeout($P.reload, 30000); } $P.node.hide([link]); $P.node.show([tb.parentNode, inning.parentNode, bases, moreInfo]); // If still here, remove loading icon if ($("loadScores")) { $("loadScores").parentNode.className = $("loadScores").parentNode.className.replace("active", ""); $("loadScores").parentNode.removeChild($("loadScores")); } break; case "Preview" : case "Pre-Game" : $("CurrentGame").className += " inactive"; gameInfo.away.pchr = { name : $E("away_probable_pitcher", g).getAttribute("last_name"), wins : $E("away_probable_pitcher", g).getAttribute("wins"), loss : $E("away_probable_pitcher", g).getAttribute("losses") }; gameInfo.home.pchr = { name : $E("home_probable_pitcher", g).getAttribute("last_name"), wins : $E("home_probable_pitcher", g).getAttribute("wins"), loss : $E("home_probable_pitcher", g).getAttribute("losses") }; link.setAttribute("href", "http://mlb.mlb.com" + $P.weAre.link); link.firstChild.nodeValue = gameInfo.day + " @ " + newTime; var ap_stats = info1, hp_stats = info2; ap_stats.nodeValue = gameInfo.away.pchr.name + " (" + gameInfo.away.pchr.wins + "-" + gameInfo.away.pchr.loss + ")"; info3.nodeValue = "vs."; hp_stats.nodeValue = gameInfo.home.pchr.name + " (" + gameInfo.home.pchr.wins + "-" + gameInfo.home.pchr.loss + ")"; tb.nodeValue = "Next: "; $P.node.hide([inning.parentNode, bases]); $P.node.show([link, moreInfo]); // If still here, remove loading icon if ($("loadScores")) { $("loadScores").parentNode.className = $("loadScores").parentNode.className.replace("active", ""); $("loadScores").parentNode.removeChild($("loadScores")); } if (gameInfo.status === "Pre-Game") { // If this is not disabled, set timeout $P.trigger = setTimeout($P.reload, 30000); } if ($P.PlayXML.trigger) { clearTimeout($P.PlayXML.trigger); $P.PlayXML.trigger = null; } // No game in progress, do the Twitter thang... //startChatUpdates(); break; } return; }, PlayXML : function() { if ($P.PlayXML.trigger) { clearTimeout($P.PlayXML.trigger); } $P.showLoadingIcon(); var url = $P.linescore, suffix = new RegExp("linescore.xml").test(url) ? "linescore.xml" : "miniscoreboard.xml"; url = url.replace(suffix, "plays.xml"); req = new XMLHttpRequest(); req.open("GET", $P.url + "?output=" + url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.atbat(req.responseXML); } else { console.log("Error: " + req.status + " on $P.PlayXML()"); $P.PlayXML(); } } }; req.send(null); }, atbat : function(e) { if ($P.PlayXML.trigger) { clearTimeout($P.PlayXML.trigger); } var g = $E("game", e), i; if (!$P.atbat.status) { $P.atbat.status = g.getAttribute("event"); } var batter = $E("batter", e), pitcher = $E("pitcher", e); if (batter && pitcher) { batter = $E("batter", e).getAttribute("boxname"); pitcher = $E("pitcher", e).getAttribute("boxname"); if (batter && batter.indexOf(" ") !== -1) { batter = batter.split(" ")[1]; } if (pitcher && pitcher.indexOf(" ") !== -1) { pitcher = pitcher.split(" ")[1]; } if (($("info2") && $("info2").firstChild && !(new RegExp(batter).test($("info2").firstChild.nodeValue))) || ($("info1") && $("info1").firstChild && !(new RegExp(pitcher).test($("info1").firstChild.nodeValue)))) { $P.PlayXML.trigger = setTimeout($P.PlayXML, 12000); $P.reload(); return; } } if ($P.atbat.status != g.getAttribute("event")) { // Event has changed, update game $P.atbat.status = g.getAttribute("event"); $P.PlayXML.trigger = setTimeout($P.PlayXML, 12000); $P.reload(); return; } var bases = [$("a"), $("b"), $("c")]; for (i = 0, j = bases.length; i < j; i++) { if (bases[i].getElementsByTagName("img")[0] && !bases[i].getElementsByTagName("img")[1]) { $P.PlayXML.trigger = setTimeout($P.PlayXML, 12000); $P.reload(); break; } } var _b = g.getAttribute("b") || 0, _s = g.getAttribute("s") || 0, _o = g.getAttribute("o") || 0, strikes = $("strikes").firstChild, balls = $("balls").firstChild, outs = $("td2").firstChild, pitch = $("pitch").firstChild; var ab = $E("atbat", g); if (ab) { var _p = $E("atbat", g).getElementsByTagName("*"), nodes = []; if (typeof _p !== "undefined") { for (i = 0, j = _p.length; i < j; i++) { nodes.push(_p[i]); } _p = nodes[nodes.length - 1]; if ((typeof _p !== "undefined") && (typeof _p.getAttribute("des") !== "undefined")) { _p = _p.getAttribute("des"); } else { _p = null; } } } if ((_b != "undefined") && (balls.nodeValue != _b)) { balls.nodeValue = _b; } if ((_s != "undefined") && (strikes.nodeValue != _s)) { strikes.nodeValue = _s; } if (_p && (pitch.nodeValue != _p)) { pitch.nodeValue = _p; } else if (!_p) { pitch.nodeValue = " "; } var outxt = _o + " Out"; if (!$P.previousOut) { $P.previousOut = outxt; } if (!outs) { $("td2").appendChild(document.createTextNode(" ")); outs = $("td2").firstChild; } if (outs && outs.nodeName && outs.nodeName.toLowerCase() === "img") { outs.parentNode.className = ""; outs.parentNode.replaceChild(document.createTextNode(outxt), outs); } else { outs.nodeValue = (outs.nodeValue === outxt) ? outs.nodeValue : outxt; } if ($P.previousOut != outxt) { fade($("td2")); $P.previousOut = outxt; } $P.PlayXML.trigger = setTimeout($P.PlayXML, 12000); }, AnnouncePlay : function() { var play = gameInfo.pbp, target = $("PickleTalk"), item = document.createElement("li"); item.style.display = "none"; item.className = "ump"; item.innerHTML = '

' + play + '

pickleump'; // see how many chats there are if (target.childNodes.length >= $P.maxChats) { // remove the last one var SlideOut = target.childNodes[target.childNodes.length -1]; target.removeChild(target.childNodes[target.childNodes.length -1]); } target.insertBefore(item, target.firstChild); if (item) { $P.AnnouncePlay.timeout = setTimeout(function() { new $P.slide(item); //clearTimeout($P.AnnouncePlay.timeout); $P.AnnouncePlay.timeout = null; }, 2500); } }, slide : function(e) { var that = $P.slide; if (that.timeout) { clearTimeout(that.timeout); } if (!that.doOnce && e.parentNode) { if (e.nextSibling && e.nextSibling.style.height != "auto") { e.nextSibling.style.height = "auto"; } var wrap = document.createElement("div"); wrap.style.overflow = wrap.style.visibility = "hidden"; e.style.display = "block"; wrap.style.height = e.offsetHeight + "px"; e.parentNode.insertBefore(wrap, e); wrap.appendChild(e); e = wrap; if (!that.alt) { $E("li", e).className += " alt"; that.alt = true; } else { that.alt = false; } if (typeof LandscapeMode.logTweets != "undefined" || LandscapeMode.logTweets === 0) { var tweet = parseInt(LandscapeMode.logTweets); if (typeof tweet == "number") { if (tweet >= 5) { tweet = tweet.toString() + "+"; } else { tweet = tweet + 1; } if (LandscapeMode.logTweets != "NaN") { LandscapeMode.logTweets = tweet; if (!(/\bactive\b/.test($("tweet").parentNode.parentNode.className))) { $("tweet").parentNode.parentNode.className += " active"; } $("tweet").firstChild.nodeValue = LandscapeMode.logTweets; } } } that.doOnce = true; } that.oHeight = that.oHeight || e.style.height.split("px")[0]; that.cHeight = that.cHeight || 0; if (that.cHeight < that.oHeight) { if (e.style.visibility == "hidden") { e.style.visibility = "visible"; } e.style.height = that.cHeight + "px"; that.cHeight = (that.cHeight + 15); that.timeout = setTimeout(function() { that(e); }, 40); } else { e.style.height = "auto"; e.style.overflow = "visible"; that.doOnce = that.oHeight = that.cHeight = false; if (that.timeout) { clearTimeout(that.timeout); } } }, renderBase : function(e, file) { var target = $(e), img = $("img_" + e); if (!img) { img = document.createElement("img"); img.setAttribute("src", "/img/team/" + file + ".png"); img.setAttribute("alt", ""); img.setAttribute("id", "img_" + e); img.style.visibility = "hidden"; target.appendChild(img); $P.trickle(img); } else if (!new RegExp(file).test(img.getAttribute("src"))) { img.setAttribute("src", "/img/team/" + file + ".png"); } }, unRenderBase : function(e) { var target = $(e), img = $("img_" + e), o = $(e + "Overlay"); if (img) { img.parentNode.removeChild(img); } $P.clearBase(e); }, updateBase : function(base, player, id) { var target = $(base + "Overlay"); if (!target) { target = document.createElement("div"); target.setAttribute("id", base + "Overlay"); target.className = "overlay"; target.style.display = "none"; $(base).appendChild(target); } var peeps = target.childNodes[1]; if (!peeps || (peeps && peeps.nodeValue.indexOf(player) == -1)) { while (target.hasChildNodes()) { target.removeChild(target.lastChild); } var img = document.createElement("img"); img.className = "mugshot"; img.setAttribute("src", "/php/imgsize.php?w=21&h=25&img=" + "http://gdx.mlb.com/images/gameday/mugshots/mlb/" + id + ".jpg"); target.appendChild(img); target.appendChild(document.createTextNode(player)); target.appendChild(document.createElement("span")); target.parentNode.onclick = function() { var id = this.getAttribute("id"); $P.updateBase.show(this, $(id + "Overlay")); }; } $P.updateBase.show = function(base, target) { if ($P.overlay.timeout) { clearTimeout($P.overlay.timeout); } var divs = $("bases").getElementsByTagName("div"); for (var i = 0, j = divs.length; i < j; i++) { if ((divs[i].className == "overlay") && divs[i] !== target) { if (divs[i].style.display != "none") { divs[i].style.display = "none"; } } } target.style.display = (target.style.display == "block") ? "none" : "block"; }; }, clearBase : function(base) { var target = $(base + "Overlay"); if (target) { $(base).removeChild(target); } }, buildSuffix : function(e) { var suffix; switch (e) { case "1" : suffix = "st"; break; case "2" : suffix = "nd"; break; case "3" : suffix = "rd"; break; default : suffix = "th"; break; } return suffix; }, createGamesToday : function(e) { var games = e, target = $("PickleGames"); target = $E("ul", target) || document.createElement("ul"); if (games.length > 15) { target.setAttribute("id", "moreThan15"); } else if (games.length < 15) { target.setAttribute("id", "lessThan15"); } for (var i = 0; i < games.length; i++) { var g = games[i], home = g.getAttribute("home_team_city").substring(0, 3), away = g.getAttribute("away_team_city").substring(0, 3); switch (g.getAttribute("home_team_city")) { case "San Francisco" : case "San Diego" : case "Tampa Bay" : case "Kansas City" : home = g.getAttribute("home_team_city").split(" "); home = home[0].charAt(0) + home[1].charAt(0); break; case "LA Dodgers" : case "LA Angels" : case "NY Yankees" : case "NY Mets" : home = g.getAttribute("home_team_city").split(" "); home = home[0] + home[1].charAt(0); break; case "Chi White Sox": home = "CWS"; break; case "St. Louis" : home = "StL"; break; } switch (g.getAttribute("away_team_city")) { case "San Francisco" : case "San Diego" : case "Tampa Bay" : case "Kansas City" : away = g.getAttribute("away_team_city").split(" "); away = away[0].charAt(0) + away[1].charAt(0); break; case "LA Dodgers" : case "LA Angels" : case "NY Yankees" : case "NY Mets" : away = g.getAttribute("away_team_city").split(" "); away = away[0] + away[1].charAt(0); break; case "Chi White Sox": away = "CWS"; break; case "St. Louis" : away = "StL"; break; } var time; switch (g.getAttribute("status")) { case "Preview" : case "Pre-Game" : time = $P.setLocalTime(g.getAttribute("time"), g.getAttribute("ampm")); break; case "In Progress" : case "Warmup" : time = ((g.getAttribute("top_inning") == "Y") ? "Top" : "Bot") + " " + g.getAttribute("inning") + $P.buildSuffix(g.getAttribute("inning")); break; case "Game Over" : time = "Final"; break; case "Delayed Start" : time = "Delayed"; break; default : time = g.getAttribute("status"); break; } var exists = $(g.getAttribute("gameday_link")); if (exists) { var parent = $(g.getAttribute("gameday_link")), home_team = parent.getElementsByTagName("dt")[1].firstChild, away_team = $E("dt", parent).firstChild, home_runs = parent.getElementsByTagName("dd")[1].firstChild, away_runs = $E("dd", parent).firstChild, time_span = $E("span", parent).firstChild; if (home_runs && home_runs.nodeValue !== g.getAttribute("home_team_runs")) { home_runs.nodeValue = g.getAttribute("home_team_runs"); } if (away_runs && away_runs.nodeValue !== g.getAttribute("away_team_runs")) { away_runs.nodeValue = g.getAttribute("away_team_runs"); } if (time_span && time_span.nodeValue !== time) { time_span.nodeValue = time; } } else { var li = document.createElement("li"); li.setAttribute("id", g.getAttribute("gameday_link")); li.setAttribute("rel", g.getAttribute("home_team_city")); li.addEventListener("click", function() { var link = this.getAttribute("id"); if (link.charAt(link.length - 1) == "2") { newLink = link.substring(0, link.length - 2) + "_1"; $(newLink).addEventListener("click", function() { $P.showFirstOfTwo = true; $P.PickYourTeam.Go(this.getAttribute("rel"), true, "second"); }, false); } $P.PickYourTeam.Go(this.getAttribute("rel"), true); window.scrollTo(0, 1); }, false); li.innerHTML = '
' + away + '
' + g.getAttribute("away_team_runs") + '
' + home + '
' + g.getAttribute("home_team_runs") + '
' + time + ''; target.appendChild(li); } } if (!$E("ul", target)) { if (!$("last-child")) { var lastLI = document.createElement("li"); lastLI.setAttribute("id", "last-child"); lastLI.innerHTML = 'Tap on a game to view'; lastLI.addEventListener("click", function() { $P.Overlay.hide(); }, false); target.appendChild(lastLI); } $("PickleGames").style.background = "none"; $("PickleGames").appendChild(target); } }, createBoxScore : function(e, f) { var foot = $("BoxFooter"), plays = 4, i, j; if (!e) { var h2 = $("BoxTable"); if (h2) { h2.parentNode.removeChild(h2); } if (foot) { foot.parentNode.removeChild(foot); } h2 = document.createElement("h2"); h2.setAttribute("id", "BoxTable"); h2.appendChild(document.createTextNode("The box score will not be available until game time.")); $("PickleBox").appendChild(h2); h2.style.display = "block"; } else { var target = $("BoxTable"), linescore = $E("linescore", e), inning_line_score = linescore.getElementsByTagName("inning_line_score"), innings = []; for (i = 0, j = inning_line_score.length; i < j; i++) { innings.push(inning_line_score[i]); } if (target) { target.parentNode.removeChild(target); } if (foot) { foot.parentNode.removeChild(foot); } target = document.createElement("table"); target.setAttribute("id", "BoxTable"); target.setAttribute("cellpadding", "0"); target.setAttribute("cellspacing", "0"); target.innerHTML = ' ' + e.getAttribute("away_sname") + '' + e.getAttribute("home_sname") + ''; $("PickleBox").insertBefore(target, $("PickleBox").firstChild); var inningCount = 0; if (innings.length < 9) { while (innings.length < 9) { var fakeInning = document.createElement("inning_line_score"); fakeInning.setAttribute("away", ""); fakeInning.setAttribute("home", ""); fakeInning.setAttribute("inning", (innings.length + 1)); innings.push(fakeInning); } } else if (innings.length > 9) { while (innings.length > 9) { inningCount = (inningCount + 1); innings.shift(); } } var thead = $E("thead", target).getElementsByTagName("tr")[0], a_tbody = $E("tbody", target).getElementsByTagName("tr")[0], h_tbody = $E("tbody", target).getElementsByTagName("tr")[1]; for (i = 0, j = innings.length; i < j; i++) { var inning = innings[i]; if (!(inning.getAttribute("home"))) { inning.setAttribute("home", ""); } thead.innerHTML += '' + (i + 1 + inningCount) + ''; a_tbody.innerHTML += '' + inning.getAttribute("away") + ''; h_tbody.innerHTML += '' + inning.getAttribute("home") + ''; } thead.innerHTML += 'RHE'; a_tbody.innerHTML += '' + linescore.getAttribute("away_team_runs") + '' + linescore.getAttribute("away_team_hits") + '' + linescore.getAttribute("away_team_errors") + ''; h_tbody.innerHTML += '' + linescore.getAttribute("home_team_runs") + '' + linescore.getAttribute("home_team_hits") + '' + linescore.getAttribute("home_team_errors") + ''; if (gameInfo.status == "Final") { plays = 2; $("BoxTable").className += " final"; var pitchers = e.getElementsByTagName("pitcher"); var winner, loser, saver; for (i = 0, j = pitchers.length; i < j; i++) { var pitcher = pitchers[i]; if (new RegExp("W,").test(pitcher.getAttribute("note"))) { winner = pitcher; } else if (new RegExp("L,").test(pitcher.getAttribute("note"))) { loser = pitcher; } else if (new RegExp("S,").test(pitcher.getAttribute("note"))) { saver = pitcher; } } foot = document.createElement("div"); foot.setAttribute("id", "BoxFooter"); foot.innerHTML = ''; if (saver) { foot.getElementsByTagName("ul").innerHTML += '
  • SV:

    ' + saver.getAttribute("name") + " (" + saver.getAttribute("note").split("(S, ")[1] + '
  • '; } $("PickleBox").appendChild(foot); } } if (f && $E("score", f)) { $("BoxTable").className += " scores"; var ul = $("BoxPlays"); if (ul) { ul.parentNode.removeChild(ul); } ul = document.createElement("ul"); ul.setAttribute("id", "BoxPlays"); ul.innerHTML = '
  • Recent Scores

  • '; var els = f.getElementsByTagName("score"), scores = []; for (i = 0, j = els.length; i < j; i++) { scores.push(els[i]); } while (scores.length > plays) { scores.shift(); } for (i = 0, j = scores.length; i < j; i++) { var score = scores[i], tb = (score.getAttribute("top_inning") == "Y") ? "Top" : "Bot", inn = score.getAttribute("inn") + $P.buildSuffix(score.getAttribute("inn")), pbp = score.getAttribute("pbp"); if ((pbp === "") && $E("action", f)) { pbp = $E("action", f).getAttribute("des"); } var li = document.createElement("li"); li.setAttribute("id", "ab_" + score.getAttribute("atbat_num") + gameInfo.home.abbr); li.innerHTML = '
    ' + tb + ' ' + inn + '' + gameInfo.away.abbr + ' ' + score.getAttribute("away") + '' + gameInfo.home.abbr + ' ' + score.getAttribute("home") + '
    ' + pbp + '
    '; ul.appendChild(li); } $("PickleBox").appendChild(ul); } $("PickleBox").className = $("PickleBox").className.replace("loading", ""); }, setLocalTime : function(time, ampm) { if (/:/.test(time)) { time = time.split(":"); var offset = (new Date().getTimezoneOffset() / 60) - 4, hour = time[0], minutes = time[1]; hour = (hour - offset); if (hour <= 0) { hour = (12 + hour); } time = hour + ":" + minutes; } return time; }, trickle : function(target, event) { target.style.visibility = "visible"; // Set styles var margin; if (target == $("img_p")) { margin = -200; } else if (target == $("img_h")) { margin = -196; } else { margin = -191; } target.style.marginTop = margin + "px"; var tween = new Tween(target.style, "top", Tween.bounceEaseOut, 0, 185, 2, "px"); tween.start(); $P.overlay.array = $P.overlay.array || []; $P.overlay.array.push(target.parentNode.getAttribute("id")); if (!$P.overlay.timeout) { $P.overlay.timeout = setTimeout($P.overlay, 2000); } }, overlay : function() { if ($P.overlay.timeout) { clearTimeout($P.overlay.timeout); } var array = $P.overlay.array; $P.overlay.num = $P.overlay.num || 0; for (var i = 0, j = array.length; i < j; i++) { if ($(array[i] + "Overlay")) { $(array[i] + "Overlay").style.display = "none"; } } if (array[$P.overlay.num]) { var target = $(array[$P.overlay.num] + "Overlay"); if (target) { target.style.display = "block"; } $P.overlay.num = ($P.overlay.num + 1); $P.overlay.timeout = setTimeout($P.overlay, 2000); } }, PickYourTeam : function() { var parent = $("PickYourTeam"), options = parent.getElementsByTagName("option"), cancel = $E("a", parent.parentNode); for (var i = 0, j = options.length; i < j; i++) { if (Cookie.get("MyPickleviewTeam") == options[i].value) { parent.selectedIndex = i; break; } } parent.addEventListener("change", function() { if (parent.value !== "") { $P.PickYourTeam.Go(parent.value); this.blur(); } }, false); cancel.addEventListener("click", function(e) { $P.Overlay.hide(); e.preventDefault(); }, false); $P.PickYourTeam.Go = function(e, f) { $P.changeValueIs = false; if ((MyFavoriteTeam !== e) && ($P.myTeam !== e)) { MyFavoriteTeam = $P.myTeam = e; if (!f) { Cookie.set("MyPickleviewTeam", e, 365); } $P.unRenderBase("a"); $P.unRenderBase("b"); $P.unRenderBase("c"); $P.unRenderBase("p"); $P.unRenderBase("h"); if ($P.overlay.timeout) { clearTimeout($P.overlay.timeout); $P.overlay.timeout = $P.overlay.array = $P.overlay.num = null; } if ($P.PlayXML.trigger) { clearTimeout($P.PlayXML.trigger); $P.PlayXML.trigger = setTimeout($P.PlayXML, 12000); } if ($("pitch").firstChild) { $("pitch").firstChild.nodeValue = ""; } $P.day = false; $P.Talk(); $P.init(); } $P.Overlay.hide(); }; }, PostYourMessage : function() { var parent = $("PostYourMessage"), input = parent.getElementsByTagName("input"), textarea = parent.getElementsByTagName("textarea"), go = $E("a", parent), cancel = parent.getElementsByTagName("a")[1], tweet = $("t"), els = []; parent.addEventListener("submit", function(e) { $P.PostYourMessage.submit(e); e.preventDefault(); }, false); tweet.parentNode.addEventListener("click", function() { tweet.checked = (tweet.checked) ? false : true; }, false); if (Cookie.get("PickleAuth") && Cookie.get("PicklePass") && !$("welcome")) { parent.removeChild($E("fieldset", parent)); var field = $E("fieldset", parent); field.setAttribute("id", "welcome"); while (field.hasChildNodes()) { field.removeChild(field.lastChild); } textarea[0].style.height = 90 + "px"; var h3 = document.createElement("h3"), span = document.createElement("span"); h3.appendChild(document.createTextNode("Hi, " + Cookie.get("PickleAuth") + "!")); span.addEventListener("click", function() { Cookie.del("PickleAuth"); Cookie.del("PicklePass"); $P.Overlay.hide(); window.scrollTo(0, 1); location.reload(); }, false); span.appendChild(document.createTextNode("Logout")); h3.appendChild(span); field.appendChild(h3); $("s").addEventListener("focus", function(e) { if ($P.PostYourMessage.startChat) { clearTimeout($P.PostYourMessage.startChat); } stopChatUpdates(); window.scrollTo(0, $(this.getAttribute("id") + "_label").offsetTop); }, false); $("s").addEventListener("blur", function() { $P.PostYourMessage.startChat = setTimeout(startChatUpdates, 500); }, false); } else { if ($("u")) { els.push($("u")); els.push($("pw")); } els.push($("s")); for (var i = 0, j = els.length; i < j; i++) { els[i].addEventListener("focus", function(e) { if ($P.PostYourMessage.startChat) { clearTimeout($P.PostYourMessage.startChat); } stopChatUpdates(); window.scrollTo(0, $(this.getAttribute("id") + "_label").offsetTop); }, false); els[i].addEventListener("blur", function() { $P.PostYourMessage.startChat = setTimeout(startChatUpdates, 500); }, false); } } $P.PostYourMessage.go = function(e) { this.style.background = "url('/img/loader/post.gif') no-repeat center"; $P.PostYourMessage.submit(e); this.removeEventListener("click", $P.PostYourMessage.go, false); e.preventDefault(); }; go.addEventListener("click", $P.PostYourMessage.go, false); cancel.addEventListener("click", function(e) { $E("textarea", parent).value = ""; window.scrollTo(0, 1); setTimeout($P.Overlay.hide, 10); e.preventDefault(); }, false); $P.PostYourMessage.submit = function(e) { e = e || window.event; e.preventDefault(); var user = Cookie.get("PickleAuth") || $("u").value, pass = Cookie.get("PicklePass") || $("pw").value, message = $("s").value, url = "/php/post-status.php"; if (user.toLowerCase() == "pickleump" || user.toLowerCase() == "pickleview") { alert("Invalid Username!"); $P.Overlay.hide(); user = pass = message = ""; return; } if (!$("t").checked) { pass = "foomfg"; } else { pass = Cookie.get("PicklePass") || $("pw").value || "foomfg"; } var req = new XMLHttpRequest(), params = "&u=" + escape(user) + "&p=" + escape(pass) + "&s=" + escape(message); req.open("POST", url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { if (!Cookie.get("PickleAuth")) { Cookie.set("PickleAuth", $("u").value, 30); Cookie.set("PicklePass", $("pw").value, 30); } $P.Overlay.hide(); window.scrollTo(0, 1); $P.PostYourMessage(); $("s").value = ""; $E("a", parent).style.background = "none"; $E("a", parent).addEventListener("click", $P.PostYourMessage.go, false); } else { alert("Whoops! Something went wrong. Can you try again?"); console.log("Error: " + req.status + " on $P.PostYourMessage.submit()"); } } }; req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); req.setRequestHeader("Connection", "close"); req.send(params); }; }, BaseClick : function() { var parent = $("bases"), target = parent.getElementsByTagName("span"); setTimeout(function() { for (var i = 0, j = target.length; i < j; i++) { var img = $E("img", target[i]); if (img) { $P.trickle(img); } } }, 2000); }, Talk : function() { if ($P.ChatInterval) { clearTimeout($P.ChatInterval); } if ($P.FetchNewChats) { clearTimeout($P.FetchNewChats); } if (!Cookie.get("PickleviewPBP")) { startChatUpdates(); } }, FixFooter : function() { var parent = $("footer"), target = parent.getElementsByTagName("a"); for (var i = 0, j = target.length; i < j; i++) { target[i].addEventListener("click", function(e) { if (this.parentNode.className.indexOf("active") !== -1) { $P.Overlay.hide(); } else { for (i = 0, j = target.length; i < j; i++) { target[i].parentNode.className = target[i].parentNode.className.replace("active", ""); } this.parentNode.className += " active"; $P.PickleFooter(this.getAttribute("href").split("#")[1]); if ($P[this.getAttribute("href").split("#")[1]]) { $P[this.getAttribute("href").split("#")[1]](this); } } window.scrollTo(0, 1); e.preventDefault(); }, false); } }, PickleAbout : function() { $P.PickleAbout.Go = function(e) { var target = $("AboutInnerDiv"); if (!target) { var req = new XMLHttpRequest(); req.open("GET", "http://pickleview.com/about.php", true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { target = document.createElement("div"); target.setAttribute("id", "AboutInnerDiv"); target.innerHTML = req.responseText; $("PickleAbout").replaceChild(target, $E("img", $("PickleAbout"))); $("Back").addEventListener("click", function(e) { $P.Overlay.hide(); e.preventDefault(); }, false); } else { console.log("Error: " + req.status + " on $P.PickleAbout.Go()"); $P.PickleAbout.Go(); } } }; req.send(null); } this.className = "active"; $P.PickleFooter(this.getAttribute("href").split("#")[1]); window.scrollTo(0, 1); e.preventDefault(); }; $("About").addEventListener("click", $P.PickleAbout.Go, false); }, PickleFooter : function(e) { var o = $("options"); o.style.display = "block"; var target = $("options").getElementsByTagName("div"); for (var i = 0, j = target.length; i < j; i++) { if ((new RegExp("pickler")).test(target[i].className)) { target[i].style.display = "none"; } } $(e).style.display = "block"; }, PickleGames : function() { var req = new XMLHttpRequest(); req.open("GET", $P.GamesXML, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.createGamesToday(req.responseXML.getElementsByTagName("games")[0].getElementsByTagName("game")); } else { console.log("Error: " + req.status + " on $P.PickleGame()"); $P.PickleGames(); } } }; req.send(null); }, PickleBox : function() { $("PickleBox").className += " loading"; if ($("BoxTable")) { $("BoxTable").style.display = "none"; } if ($("BoxFooter")) { $("BoxFooter").style.display = "none"; } if ($("BoxPlays")) { $("BoxPlays").style.display = "none"; } var req = new XMLHttpRequest(), url = $P.linescore, score, string = (new RegExp("miniscoreboard.xml").test(url)) ? "miniscoreboard.xml" : "linescore.xml"; url = url.replace(string, "boxscore.xml"); score = url.replace("boxscore.xml", "inning/inning_Scores.xml"); req.open("GET", $P.url + "?output=" + url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { var e = (req.responseXML) ? req.responseXML.getElementsByTagName("boxscore")[0] : null; var req2 = new XMLHttpRequest(); req2.open("GET", $P.url + "?output=" + score, true); req2.onreadystatechange = function() { if (req2.readyState == 4) { if (req2.status == 200 || req2.status == 304) { var f = (req2.responseXML) ? req2.responseXML.getElementsByTagName("scores")[0] : null; $P.createBoxScore(e, f); } else { throw ("Error loading page\n"); } } }; req2.send(null); } else { console.log("Error: " + req.status + " on $P.PickleBox()"); $P.PickleBox(); } } }; req.send(null); }, Feed : function() { var target = $("PickleFeed").getElementsByTagName("a"); for (var i = 0, j = target.length; i < j; i++) { target[i].addEventListener("click", function(e) { var func = this.getAttribute("href").split("#")[1]; $P.DoFeed[func](); $P.Overlay.hide(); e.preventDefault(); }, false); } }, node : { show : function(e) { for (var i = 0, j = e.length; i < j; i++) { if (e[i].className === "hide") { e[i].className = ""; } } }, hide : function(e) { for (var i = 0, j = e.length; i < j; i++) { if (e[i].className !== "hide") { e[i].className = "hide"; } } } }, changeValue : { init : function(e, new_value) { if (!$P.changeValue.isBusy) { $P.changeValue.isBusy = true; var hide = document.createElement("span"); hide.setAttribute("id", "hide"); if (parseInt(new_value) > 9) { hide.appendChild(document.createTextNode("1")); e.insertBefore(hide, e.firstChild); } else if (parseInt(new_value) > 19) { hide.appendChild(document.createTextNode("2")); e.insertBefore(hide, e.firstChild); } var x = document.createElement("div"); x.setAttribute("id", "value_wrap"); x.innerHTML = '
    ' + e.lastChild.nodeValue + '
    ' + new_value + '
    '; var pos = $P.changeValue.pos(e); x.style.left = (pos[0]) + "px"; x.style.top = (pos[1] - 5) + "px"; x.style.width = e.offsetWidth + "px"; x.style.height = e.offsetHeight + "px"; e.appendChild(x); document.getElementById("old_value").style.width = (e.offsetWidth - 14) + "px"; document.getElementById("new_value").style.width = (e.offsetWidth - 1) + "px"; $P.changeValue.oElement = document.getElementById("change_value"); $P.changeValue.oElement.style.width = ($P.changeValue.oElement.offsetWidth + 1) + "px"; $P.changeValue.opacity = 0; $P.changeValue.leftValue = 0; $P.changeValue.fade.down(); } }, fade : { up : function() { var o = o || $P.changeValue.oElement, opacity = $P.changeValue.opacity; if (opacity > 0) { o.style.opacity = (opacity / 100); $P.changeValue.opacity = ($P.changeValue.opacity - 15); $P.changeValue.fade.up.timeout = setTimeout(function() { $P.changeValue.fade.up(o); }, 10); } else { o.style.opacity = 0; if ($P.changeValue.fade.up.timeout) { clearTimeout($P.changeValue.fade.up.timeout); } $P.changeValue.end(); } }, down : function() { var o = o || $P.changeValue.oElement, opacity = $P.changeValue.opacity; if (opacity < 100) { o.style.opacity = (opacity / 100); $P.changeValue.opacity = ($P.changeValue.opacity + 15); $P.changeValue.fade.down.timeout = setTimeout(function() { $P.changeValue.fade.down(o); }, 10); } else { o.style.opacity = 1; if ($P.changeValue.fade.down.timeout) { clearTimeout($P.changeValue.fade.down.timeout); } setTimeout($P.changeValue.slide, 1000); } } }, slide : function() { var e = document.getElementById("change_value"), left = $P.changeValue.leftValue; if (left > -100) { e.style.left = left + "%"; $P.changeValue.leftValue = ($P.changeValue.leftValue - 15); $P.changeValue.slide.timeout = setTimeout(function() { $P.changeValue.slide(e); }, 15); } else { e.style.left = -105 + "%"; $P.changeValue.oElement.parentNode.previousSibling.nodeValue = document.getElementById("new_value").firstChild.nodeValue; if ($("hide")) { $("hide").parentNode.removeChild($("hide")); } if ($P.changeValue.slide.timeout) { clearTimeout($P.changeValue.slide.timeout); } setTimeout($P.changeValue.fade.up, 10000); } }, end : function() { var x = document.getElementById("value_wrap"); if (x) { x.parentNode.removeChild(x); } $P.changeValue.isBusy = false; return; }, pos : function(e) { var curleft = curtop = 0; if (e.offsetParent) { curleft = e.offsetLeft; curtop = e.offsetTop; while (e = e.offsetParent) { curleft += e.offsetLeft; curtop += e.offsetTop; } } return [curleft, curtop]; } }, Overlay : { hide : function() { $("options").style.display = "none"; var target = $("footer").getElementsByTagName("a"); for (var i = 0, j = target.length; i < j; i++) { target[i].parentNode.className = target[i].parentNode.className.replace("active", ""); } window.scrollTo(0, 1); } }, Flag : { W3 : !!(document.getElementById && document.createElement), WK : !!(document.childNodes && !document.all && !navigator.taintEnabled) /* <-- Webkit */ }, DoFeed : { Twitter : function() { if (Cookie.get("PickleviewPBP")) { Cookie.del("PickleviewPBP"); } $P.Talk(); return; }, PBP : function() { if (!Cookie.get("PickleviewPBP")) { Cookie.set("PickleviewPBP", true, 365); $P.PlayByPlay = true; $P.Talk(); var req = new XMLHttpRequest(); req.open("GET", $P.url + "?output=" + $P.linescore, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200 || req.status == 304) { $P.game(req.responseXML); } else { console.log("Error: " + req.status + " on $P.DoFeed.PBP()"); $P.DoFeed.PBP(); } } }; req.send(null); } return; }, Cancel : function() { return; } } }; /** * @author: Jeremy Keith * @modified: Richard Herrera * @description: Color Fade Technique **/ var fade = function(e, r, g, b) { //var r, g, b; if (!r) { r = 255; } if (!g) { g = 0; } if (!b) { b = 0; } e.style.color = "rgb(" + r + "," + g + "," + b + ")"; setTimeout(function() { fade.up(e, r, g, b); }, 1000); fade.up = function(e, r, g, b) { if (e.fade) { clearTimeout(e.fade); } e.style.color = "rgb(" + r + "," + g + "," + b + ")"; if ((r <= 50) && (g <= 60) && (b <= 72)) { e.style.color = "rgb(47, 58, 70)"; if (repeat) { clearTimeout(repeat); } return; } var newRed = r + Math.floor((47 - r) / 20), newGreen = g + Math.floor((58 - g) / 20), newBlue = b + Math.floor((70 - b) / 20); var repeat = function() { fade.up(e, newRed, newGreen, newBlue); }; e.fade = setTimeout(repeat, 60); }; }; $P = Pickleview; if ($P.Flag.WK) { $E("html", document).setAttribute("id", "webkit"); } else if ($P.Flag.W3) { $E("html", document).setAttribute("id", "other"); } /** * @author Joe Hewitt joehewitt.com * @modified Richard Herrera doctyper.com * @description Polls for a change in screen size */ var updateLayout = function() { if ((window.innerWidth != $P.currentWidth) && document.getElementsByTagName("body")[0]) { $P.currentWidth = window.innerWidth; var orient; if ($P.currentWidth < 480) { orient = "profile"; var tweet = $("tweet"); if (tweet) { tweet.parentNode.parentNode.className = tweet.parentNode.parentNode.className.replace("active", ""); tweet.parentNode.parentNode.style.display = "none"; tweet.firstChild.nodeValue = ""; LandscapeMode.logTweets = false; } } else { // We are in landscape mode orient = "landscape"; LandscapeMode(); } document.getElementsByTagName("body")[0].setAttribute("orient", orient); window.scrollTo(0, 1); } }; var LandscapeMode = function() { LandscapeMode.logTweets = 0; var tweet = $("tweet"); if (tweet) { tweet.parentNode.parentNode.style.display = "block"; if (tweet.firstChild && tweet.firstChild.nodeValue == "NaN") { tweet.firstChild.nodeValue = ""; tweet.parentNode.parentNode.className = tweet.parentNode.parentNode.className.replace("active", ""); } } else { tweet = document.createElement("li"); tweet.setAttribute("class", "tweets"); tweet.innerHTML = 'Tweets '; tweet.style.display = "block"; tweet.firstChild.addEventListener("click", function(e) { window.scrollTo(0, 220); $("tweet").firstChild.nodeValue = " "; this.parentNode.className = this.parentNode.className.replace("active", ""); LandscapeMode.logTweets = 0; e.preventDefault(); }, false); $("footer").appendChild(tweet); } }; window.console = window.console || { log : function(e) { return; }, dir : function(e) { return; }, dirxml : function(e) { return; } }; window.addEventListener("load", function() { $P.init(); $P.PickYourTeam(); $P.Feed(); $P.PostYourMessage(); $P.BaseClick(); $P.Talk(); $P.FixFooter(); $P.PickleAbout(); if (navigator.userAgent.indexOf('iPhone') != -1) { setInterval(updateLayout, 400); } }, false);