jQuery(document).ready(function() { /* json structure { bracketid:{ roundid:{ pollid:answerid, pollid2:answerid2 }, roundid2:{ pollid3:answerid3, pollid4:answerid4 } } }*/ // fix for IE Object.keys = Object.keys || (function () { var hasOwnProperty = Object.prototype.hasOwnProperty, hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"), DontEnums = [ 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor' ], DontEnumsLength = DontEnums.length; return function (o) { if (typeof o != "object" && typeof o != "function" || o === null) throw new TypeError("Object.keys called on a non-object"); var result = []; for (var name in o) { if (hasOwnProperty.call(o, name)) result.push(name); } if (hasDontEnumBug) { for (var i = 0; i < DontEnumsLength; i++) { if (hasOwnProperty.call(o, DontEnums[i])) result.push(DontEnums[i]); } } return result; }; })(); // global variables so we can access them in the matchup template window.bracketid = jQuery('.bracket').data('bracketid'); window.roundid = jQuery('.round-active').first().data('roundid'); window.useLocalStorage = (function(){try{return ('localStorage' in window) && (window['localStorage'] !== null);}catch(e){return false;}})(); window.bracketCookieName = 'BRACKETS.POLL'; window.espnCookieName = 'ESPN.POLL'; window.roundCount = 0; window.totalMatchesInRound = parseInt(jQuery("#total_matches").html()); window.jsonObj = {}; // check for undefined's... if(jsonObj[bracketid] == undefined) { jsonObj[bracketid] = {}; } if(jsonObj[bracketid] != undefined) { if(jsonObj[bracketid][roundid] == undefined) { jsonObj[bracketid][roundid] = {}; } } window.updateBracketCookie = function updateBracketCookie() { if(useLocalStorage) { // use local storage localStorage.setItem(bracketCookieName, JSON.stringify(jsonObj)); } else{ // use the cookie espn.cookie.set(bracketCookieName, JSON.stringify(jsonObj), 21); } updateRoundCount(Object.keys(jsonObj[bracketid][roundid]).length); } // returns answerid if has a result, or true if it just knows you voted, else false // need to check both the ESPN.POLL cookie & our own BRACKETS.POLL window.checkHasVoted = function checkHasVoted(bracketid, roundid, pollid) { var hasVoted = false; bracketCookieValue = useLocalStorage ? localStorage.getItem(bracketCookieName) : espn.cookie.get(bracketCookieName); espnCookieValue = useLocalStorage ? localStorage.getItem(espnCookieName) : espn.cookie.get(espnCookieName); if(bracketid != null && roundid != null && pollid != null) { if(bracketCookieValue != null && bracketCookieValue != undefined) { jsonObj = JSON.parse(bracketCookieValue); if(jsonObj[bracketid] != undefined) { if(jsonObj[bracketid][roundid] != undefined) { if(jsonObj[bracketid][roundid][pollid] != undefined) { hasVoted = jsonObj[bracketid][roundid][pollid]; } } } } // check for undefined's again... if(jsonObj[bracketid] == undefined) { jsonObj[bracketid] = {}; } if(jsonObj[bracketid] != undefined) { if(jsonObj[bracketid][roundid] == undefined) { jsonObj[bracketid][roundid] = {}; } } // also check the espn.poll to see if it exists in the global poll cookie // if this cookie exists, we will manually have to not show results in the poll // this will not return us the voted answerid, just true if(hasVoted == false) { if(espnCookieValue != null && espnCookieValue != undefined) { encodedPollId = pollid.toString(32); if(typeof(espnCookieValue) === 'string') { var votedPollIds = espnCookieValue.split(','); if(typeof(votedPollIds) === 'object'){ for(i in votedPollIds){ if(votedPollIds[i] === encodedPollId){ hasVoted = true; break; } } } } } } } return hasVoted } function displayVoteContent(html) { jQuery('#mvc-vote-container').css('overflow','visible'); jQuery('#mvc-vote-container').html(html); jQuery('#mvc-vote-container #mvc-vote-content').fadeIn(); jQuery('.video-placeholder').each(function() { loadVideoIframe(jQuery(this)); }); updateVoteMatchupViews(); var pageName = jQuery('#pageName').html(); if (typeof anTrackPage === 'function') { anTrackPage(0,'espn','brackets','feature','','poll',pageName,'en',''); } } function openVoteContainer(html) { if (jQuery('#mvc-vote-container').length === 0) { if (html.indexOf('mcv12-finals-votes') === -1) { jQuery('
').appendTo(jQuery('#mcv-container')); } else { jQuery('
').appendTo(jQuery('#mcv-container')); } jQuery('#mvc-vote-container').animate({ //top: '-=178px', //left: '-=390px', top: '0px', left: '0px', width: "924px", height: "504px" },{ complete: function() { displayVoteContent(html); } }); } else { jQuery('#mvc-vote-container #mvc-vote-content').fadeOut(); displayVoteContent(html); } } function closeVoteContainer(html) { updateMatchupViews(); jQuery('#mvc-vote-container').removeClass('mcv-matchup-finals').remove(); jQuery('#mvc-vote-container #mvc-vote-content').fadeOut(400, function() { jQuery('#mvc-vote-container').animate({ top: '+=140px', left: '+=390px', width: "146px", height: "159px" },{ complete: function() { jQuery('#mvc-vote-container').remove(); } }); }); } function loadVideoIframe(element) { var videoId = jQuery(element).attr('data-videoid'); if (!!videoId) { jQuery(element).append(''); } } function updateRoundCount(newCount) { roundCount = newCount; jQuery('#completed_votes').html(roundCount); } function updateMatchupViews() { if(jQuery('.round-active li').length > 0) { jQuery('.round-active li').each(function () { var $this = jQuery(this), pollId = $this.attr('data-pollid'); if (!!pollId) { pollId = parseInt(pollId,10); hasVoted = checkHasVoted(bracketid, roundid, pollId) if(hasVoted != false) { $this.find('div.matchup').addClass("voted"); $this.find('.vote-view').hide(); $this.find('.matchup-view').show(); if(hasVoted != true) { $this.find('div.matchup .player-name[data-answerid="'+hasVoted+'"] div').addClass("winner"); $this.find('div.matchup .player-name:not([data-answerid="'+hasVoted+'"]) div').addClass("loser"); } } } }); } else { jQuery('.round-active').each(function () { var $this = jQuery(this); var pollId = 0; if(jQuery('.round-active').hasClass('round-4a')) { pollId = $this.find('.p1').attr('data-pollid'); } if (!!pollId) { pollId = parseInt(pollId,10); if(checkHasVoted(bracketid, roundid, pollId) != false) { $this.find('.vote-view').hide(); $this.find('.matchup-view').show(); } } }); } // update round count updateRoundCount(Object.keys(jsonObj[bracketid][roundid]).length); jQuery.each(jQuery('.round-active > .matchup-cont'), function() { pollid = jQuery(this).data("pollid"); hasVoted = checkHasVoted(bracketid, roundid, pollid); if(hasVoted == true) { jQuery(this).find('div.matchup').addClass("voted"); } else if(hasVoted != false) { jQuery(this).find('div.matchup').addClass("voted"); jQuery(this).find('div.matchup .player-name[data-answerid="'+hasVoted+'"] div').addClass("winner"); jQuery(this).find('div.matchup .player-name:not([data-answerid="'+hasVoted+'"]) div').addClass("loser"); } }); } function updateVoteMatchupViews() { jQuery('.more-matchups li').each(function () { var $this = jQuery(this), pollId = $this.attr('data-pollid'); if (!!pollId) { pollId = parseInt(pollId,10); if(checkHasVoted(bracketid, roundid, pollId) != false) { $this.addClass('voted'); } } }); jQuery('.more-matchups').show(); } function tweetButton(target, lang, url, originalUrl, text, count) { if (!!url && !!text) { var tweetButtonIframe = [''); tweetButtonIframe = tweetButtonIframe.join(''); jQuery(target).html(tweetButtonIframe); } } if(typeof(loadurl) !== 'undefined') { jQuery.ajax({ type: "GET", url: loadurl, dataType: "html", cache: true, success: function (response) { openVoteContainer(jQuery.trim(response)); } }); } if (jQuery('#mvc-vote-container').length > 0) { jQuery('.video-placeholder').each(function() { loadVideoIframe(jQuery(this)); }); updateVoteMatchupViews(); } jQuery('.matchup-link').live('click', function(e) { e.preventDefault(); url = jQuery(this).attr('href'); if (typeof(url) === 'undefined') { url = jQuery(this).find('a').attr('href'); } jQuery.ajax({ type: "GET", url: url, dataType: "html", cache: true, success: function (response) { openVoteContainer(jQuery.trim(response)); } }); return false; }); jQuery('#close-btn').live('click', function(e) { e.preventDefault(); closeVoteContainer(); }); jQuery('#next-btn').live('click', function(e) { e.preventDefault(); $active = jQuery('.more-matchups .active'); var $next = $active.next(); if ($next.length === 0 || $next.hasClass('hidden')) { $next = jQuery('.more-matchups li').first(); } $next.find('a').trigger('click'); }); jQuery('#prev-btn').live('click', function(e) { e.preventDefault(); $active = jQuery('.more-matchups .active'); var $prev = $active.prev(); if ($prev.length === 0 || $prev.hasClass('hidden')) { $prev = jQuery('.more-matchups li').last(); } $prev.find('a').trigger('click'); }); jQuery('.retweet').live('click',function(e) { window.open(jQuery(this).attr('href'),'reweet','width=550,height=400,scrollbars=no,resizable=yes'); e.preventDefault(); }); tweetButton(jQuery('.twitter-button'), "EN", 'http://es.pn/hF4Z2F', 'http://espn.go.com/sportsnation/feature/madden25cover', "Who will get your vote for the cover of Madden? Cast your votes here: http://es.pn/dRovcI", true); updateMatchupViews(); function trackClicks(linkname) { s_omni.linkTrackVars = 'channel, prop3, eVar2, eVar13, events'; s_omni.linkTrackEvents = 'linkclick'; //Set Variables s_omni.eVar2 = linkname; // name of link s_omni.prop3 = s_omni.eVar2; s_omni.eVar13 = s_omni.channel + ':madden25cover'; s_omni.events = 'linkclick'; s_omni.tl(true, 'o', 'madden25cover:' + linkname); } jQuery('.gamestop-link a').live('click', function(e) { trackClicks('gamestop'); anTrackLink(this,'espn','sportsnation/madden25', 'gamestop_outbound'); }); });