MediaWiki:Common.js

// Start overly-complicated collapsible tables // Todo: jQuery this thing /** Collapsible tables ********************************************************* * *  Description: Allows tables to be collapsed, showing only the header. See *              NavFrame. * Maintainers: User:R. Koot */ var hasClass = (function {    var reCache = {};    return function (element, className) {        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);   }; });

var autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show"; function collapseTable( tableIndex ) {    var Button = document.getElementById( "collapseButton" + tableIndex ); var Table = document.getElementById( "collapsibleTable" + tableIndex ); if ( !Table || !Button ) { return false; }    var Rows = Table.rows; if ( Button.firstChild.data == collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = "none"; }        Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; }        Button.firstChild.data = collapseCaption; } } function createCollapseButtons {    var tableIndex = 0; var NavigationBoxes = new Object; var Tables = document.getElementsByTagName( "table" ); for ( var i = 0; i < Tables.length; i++ ) { if ( hasClass( Tables[i], "collapsible" ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; if (!HeaderRow) continue; var Header = HeaderRow.getElementsByTagName( "th" )[0]; if (!Header) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); var Button    = document.createElement( "span" ); var ButtonLink = document.createElement( "a" ); var ButtonText = document.createTextNode( collapseCaption ); Button.style.styleFloat = "right"; Button.style.cssFloat = "right"; Button.style.fontWeight = "normal"; Button.style.textAlign = "right"; Button.style.width = "6em"; ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( "[" ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( "]" ) ); Header.insertBefore( Button, Header.childNodes[0] ); tableIndex++; }    }     for ( var i = 0;  i < tableIndex; i++ ) { if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { collapseTable( i ); }    } } $(createCollapseButtons);

// End collapsible tables

// Mouseover trick for multi-image item infoboxes $("#itemsmallimages img").mouseover(function {          $("#itemmainimage img:first").attr('src', $(this).attr('src'));       }   );

// Fancy diffs var fancyDiffs = { isBigDiff: false, isBigDiffThreshold: 72, toggle: function(element) { var expanded = element.hasClass('diff-expanded'); var contents = element.parent.children('.diff-contents'); if(expanded) { // Just collapse then element.removeClass('diff-expanded'); if(fancyDiffs.isBigDiff) { contents.hide; } else { contents.slideUp('fast'); }		} else if(element.hasClass('diff-data-loaded')) { // Stuff is already loaded, expand element.addClass('diff-expanded'); contents.slideDown('fast'); } else if(!element.hasClass('diff-data-requested')) { // Stuff is not loaded element.addClass('diff-data-requested'); var fileName = element.find('span').text.replace(/^\s+|\s+$/g); var patchName = element.closest('.diffname'); var diffName = wgPageName; if(patchName && patchName.length && patchName.attr('class')) { diffName = patchName.attr('class').substr(9); }			$.get('/index.php?title=Template:PatchDiff/' + encodeURIComponent(diffName.replace(/^Template:PatchDiff\//, '')) + '/' + encodeURIComponent(fileName) + '&action=raw', function(data) {				contents.html(data);				if(fancyDiffs.isBigDiff) {					contents.show;				} else {					contents.slideDown('fast');				}				element.removeClass('diff-data-requested').addClass('diff-data-loaded').addClass('diff-expanded');			}); }	},	init: function { var diffText = $('.diff-name-text'); if(diffText.length) { // Preload leetle gif $('body').append($(' ').attr('src', 'http://hydra-images.cursecdn.com/dota2.gamepedia.com/4/43/Patch_diff_loading.gif').css('display', 'none')); diffText.find('span').each(function {				$(this).text($(this).find('a').text.replace(/^\s+|\s+$/g));			}); diffText.click(function {				fancyDiffs.toggle($(this));				return false;			}); fancyDiffs.isBigDiff = $('.diff-file').length > fancyDiffs.isBigDiffThreshold; }	} }; $(fancyDiffs.init);

// End fancy diffs

// Wiki-logo correct lang links var languages = ["ar", "cs", "da", "de", "el", "es", "fi", "fr", "hu", "it", "ja", "ko", "nl", "no", "pl", "pt", "pt-br", "ro", "ru", "sv", "th", "tr", "vi", "zh-hans", "zh-hant"];

var lang = /\/([a-z-]+)\/?$/.exec(location.href); if (lang) { lang = lang[1] if (languages.indexOf(lang) != -1) { var logolink = $("#p-logo a"); logolink.attr("href", logolink.attr("href") + "/" + lang); } } // End Wiki-logo correct lang links

// EmbedVideo fixes var youtubeHelper = { chromeSize: 25, // This is the height (in pixels) of the chrome of YouTube's embedded video player. Update this whenever they release a new embedded video player maxWidth: 0.85, // Maximum fraction of the available width that the video may take infoboxes: ['.infobox', '.testchamber'], // Selectors of infobox-style boxes that should be deducted from the page's available width ratioR: /ratio-(\d+)x(\d+)/i, widthsR: /widths((?:\D+\d+)+)/i, setSize:function { var widths = youtubeHelper.widthsR.exec($(this).attr('class')); if(widths != null) { widths = widths[1].substr(1).split(/\D+/g); var availableWidth = $('#bodyContent').width; for(var i in youtubeHelper.infoboxes) { if($(youtubeHelper.infoboxes[i]).length) { availableWidth -= $(youtubeHelper.infoboxes[i]).width; }			}			availableWidth *= youtubeHelper.maxWidth; var intWidths = []; for(var w = 0; w < widths.length; w++) { intWidths[w] = parseInt(widths[w]); }			intWidths.sort(function(a, b){return b - a;}); for(var w = 0; w < intWidths.length; w++) { if(intWidths[w] <= availableWidth || w == intWidths.length-1) { youtubeHelper.setWidth(this, intWidths[w]); break; }			}		}		else { youtubeHelper.setWidth(this, parseFloat(obj.attr('width'))); }	},	setUrl:function { var obj = $(this).children('object'); if(!obj) return; obj.append($(' ')); obj.append($(' ')); var titleParts = wgPageName.split(/\//g); var lang = 'en'; if(titleParts.length == 2 && !wgCanonicalSpecialPageName) { lang = titleParts[titleParts.length-1]; }		var playerUrl = obj.children('param[name="movie"]').attr('value') + '&fs=1&theme=dark&color=white' + ($(this).hasClass('hd-on') ? '&hd=1' : '') + '&cc_load_policy=1&hl=' + lang + '&cc_lang_pref=' + lang; obj.children('param[name="movie"]').attr('value', playerUrl); obj.children('embed').attr('src', playerUrl).attr('allowscriptaccess', 'always').attr('allowfullscreen', 'true'); var resultHtml = $(this).html; $(this).html('').html(resultHtml); },	setWidth:function(youtube, width) { var obj = $(youtube).children('object'); if(!obj) return; if($(youtube).hasClass('youtube-audio')) { obj.attr('width', width).attr('height', youtubeHelper.chromeSize); // Set height obj.children('embed').attr('width', width).attr('height', youtubeHelper.chromeSize); // Set height }		else { var ratio = youtubeHelper.ratioR.exec($(youtube).attr('class')); if(ratio != null) { ratio = parseFloat(ratio[1])/parseFloat(ratio[2]); var newHeight = Math.round(width / ratio + youtubeHelper.chromeSize).toString; obj.attr('width', width).attr('height', newHeight); // Set height obj.children('embed').attr('width', width).attr('height', newHeight); // Set height }		}	},	resizeTimer:null, resize:function { if(youtubeHelper.resizeTimer != null) { clearTimeout(youtubeHelper.resizeTimer); }		youtubeHelper.resizeTimer = setTimeout(youtubeHelper.onResize, 100); },	onResize:function { $('.youtubebox').each(youtubeHelper.setSize); },	init:function { $('.youtubebox').each(youtubeHelper.setUrl); $(window).resize(youtubeHelper.resize); youtubeHelper.onResize; } }; $(youtubeHelper.init); // END EmbedVideo fixes

// Auto-expand "Partners" sidebar entry $('#p-Partners').addClass('persistent');

/* * Upcoming matches calendar * * Powered by Abios Gaming  * Authored by Rob Jackson  on behalf of Gamepedia  * * This script fetches data from Abios' API, caches that data in the user's browser * and processes and renders that data to the page. */

//

/** * lscache library * Copyright (c) 2011, Pamela Fox * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ !function(a,b){"function"==typeof define&&define.amd?define([],b):"undefined"!=typeof module&&module.exports?module.exports=b:a.lscache=b}(this,function{function a{var a="__lscachetest__",c=a;if(void 0!==m)return m;try{g(a,c),h(a),m=!0}catch(d){m=b(d)?!0:!1}return m}function b(a){return a&&"QUOTA_EXCEEDED_ERR"===a.name||"NS_ERROR_DOM_QUOTA_REACHED"===a.name||"QuotaExceededError"===a.name?!0:!1}function c{return void 0===n&&(n=null!=window.JSON),n}function d(a){return a+p}function e{return Math.floor((new Date).getTime/r)}function f(a){return localStorage.getItem(o+t+a)}function g(a,b){localStorage.removeItem(o+t+a),localStorage.setItem(o+t+a,b)}function h(a){localStorage.removeItem(o+t+a)}function i(a){for(var b=new RegExp("^"+o+t+"(.*)"),c=localStorage.length-1;c>=0;--c){var e=localStorage.key(c);e=e&&e.match(b),e=e&&e[1],e&&e.indexOf(p)<0&&a(e,d(e))}}function j(a){var b=d(a);h(a),h(b)}function k(a){var b=d(a),c=f(b);if(c){var g=parseInt(c,q);if(e>=g)return h(a),h(b),!0}}function l(a,b){u&&"console"in window&&"function"==typeof window.console.warn&&(window.console.warn("lscache - "+a),b&&window.console.warn("lscache - The error was: "+b.message))}var m,n,o="lscache-",p="-cacheexpiration",q=10,r=6e4,s=Math.floor(864e13/r),t="",u=!1,v={set:function(k,m,n){if(a){if("string"!=typeof m){if(!c)return;try{m=JSON.stringify(m)}catch(o){return}}try{g(k,m)}catch(o){if(!b(o))return void l("Could not add item with key '"+k+"'",o);var p,r=[];i(function(a,b){var c=f(b);c=c?parseInt(c,q):s,r.push({key:a,size:(f(a)||"").length,expiration:c})}),r.sort(function(a,b){return b.expiration-a.expiration});for(var t=(m||"").length;r.length&&t>0;)p=r.pop,l("Cache is full, removing item with key '"+k+"'"),j(p.key),t-=p.size;try{g(k,m)}catch(o){return void l("Could not add item with key '"+k+"', perhaps it's too big?",o)}}n?g(d(k),(e+n).toString(q)):h(d(k))}},get:function(b){if(!a)return null;if(k(b))return null;var d=f(b);if(!d||!c)return d;try{return JSON.parse(d)}catch(e){return d}},remove:function(b){a&&j(b)},supported:function{return a},flush:function{a&&i(function(a){j(a)})},flushExpired:function{a&&i(function(a){k(a)})},setBucket:function(a){t=a},resetBucket:function{t=""},enableWarnings:function(a){u=a}};return v});

//

/* countdown.js v2.5.2 http://countdownjs.org Copyright (c)2006-2014 Stephen M. McKamey. Licensed under The MIT License. var module,countdown=function(y){function C(a,b){var c=a.getTime;a.setMonth(a.getMonth+b);return Math.round((a.getTime-c)/864E5)}function z(a){var b=a.getTime,c=new Date(b);c.setMonth(a.getMonth+1);return Math.round((c.getTime-b)/864E5)}function A(a,b){b=b instanceof Date||null!==b&&isFinite(b)?new Date(+b):new Date;if(!a)return b;var c=+a.value||0;if(c)return b.setTime(b.getTime+c),b;(c=+a.milliseconds||0)&&b.setMilliseconds(b.getMilliseconds+c);(c=+a.seconds||0)&&b.setSeconds(b.getSeconds+ c);(c=+a.minutes||0)&&b.setMinutes(b.getMinutes+c);(c=+a.hours||0)&&b.setHours(b.getHours+c);(c=+a.weeks||0)&&(c*=7);(c+=+a.days||0)&&b.setDate(b.getDate+c);(c=+a.months||0)&&b.setMonth(b.getMonth+c);(c=+a.millennia||0)&&(c*=10);(c+=+a.centuries||0)&&(c*=10);(c+=+a.decades||0)&&(c*=10);(c+=+a.years||0)&&b.setFullYear(b.getFullYear+c);return b}function l(a,b){return v(a)+(1===a?w[b]:x[b])}function q{}function n(a,b,c,d,f,m){0<=a[c]&&(b+=a[c],delete a[c]);b/=f;if(1>=b+1)return 0;if(0<=a[d]){a[d]= +(a[d]+b).toFixed(m);switch(d){case "seconds":if(60!==a.seconds||isNaN(a.minutes))break;a.minutes++;a.seconds=0;case "minutes":if(60!==a.minutes||isNaN(a.hours))break;a.hours++;a.minutes=0;case "hours":if(24!==a.hours||isNaN(a.days))break;a.days++;a.hours=0;case "days":if(7!==a.days||isNaN(a.weeks))break;a.weeks++;a.days=0;case "weeks":if(a.weeks!==z(a.refMonth)/7||isNaN(a.months))break;a.months++;a.weeks=0;case "months":if(12!==a.months||isNaN(a.years))break;a.years++;a.months=0;case "years":if(10!== a.years||isNaN(a.decades))break;a.decades++;a.years=0;case "decades":if(10!==a.decades||isNaN(a.centuries))break;a.centuries++;a.decades=0;case "centuries":if(10!==a.centuries||isNaN(a.millennia))break;a.millennia++;a.centuries=0}return 0}return b}function D(a,b,c,d,f,m){var k=new Date;a.start=b=b||k;a.end=c=c||k;a.units=d;a.value=c.getTime-b.getTime;0>a.value&&(k=c,c=b,b=k);a.refMonth=new Date(b.getFullYear,b.getMonth,15,12,0,0);try{a.millennia=0;a.centuries=0;a.decades=0;a.years=c.getFullYear- b.getFullYear;a.months=c.getMonth-b.getMonth;a.weeks=0;a.days=c.getDate-b.getDate;a.hours=c.getHours-b.getHours;a.minutes=c.getMinutes-b.getMinutes;a.seconds=c.getSeconds-b.getSeconds;a.milliseconds=c.getMilliseconds-b.getMilliseconds;var g;0>a.milliseconds?(g=s(-a.milliseconds/1E3),a.seconds-=g,a.milliseconds+=1E3*g):1E3<=a.milliseconds&&(a.seconds+=p(a.milliseconds/1E3),a.milliseconds%=1E3);0>a.seconds?(g=s(-a.seconds/60),a.minutes-=g,a.seconds+=60*g):60<=a.seconds&&(a.minutes+= p(a.seconds/60),a.seconds%=60);0>a.minutes?(g=s(-a.minutes/60),a.hours-=g,a.minutes+=60*g):60<=a.minutes&&(a.hours+=p(a.minutes/60),a.minutes%=60);0>a.hours?(g=s(-a.hours/24),a.days-=g,a.hours+=24*g):24<=a.hours&&(a.days+=p(a.hours/24),a.hours%=24);for(0>a.days;)a.months--,a.days+=C(a.refMonth,1);7<=a.days&&(a.weeks+=p(a.days/7),a.days%=7);0>a.months?(g=s(-a.months/12),a.years-=g,a.months+=12*g):12<=a.months&&(a.years+=p(a.months/12),a.months%=12);10<=a.years&&(a.decades+=p(a.years/10),a.years%= 10,10<=a.decades&&(a.centuries+=p(a.decades/10),a.decades%=10,10<=a.centuries&&(a.millennia+=p(a.centuries/10),a.centuries%=10)));b=0;!(d&1024)||b>=f?(a.centuries+=10*a.millennia,delete a.millennia):a.millennia&&b++;!(d&512)||b>=f?(a.decades+=10*a.centuries,delete a.centuries):a.centuries&&b++;!(d&256)||b>=f?(a.years+=10*a.decades,delete a.decades):a.decades&&b++;!(d&128)||b>=f?(a.months+=12*a.years,delete a.years):a.years&&b++;!(d&64)||b>=f?(a.months&&(a.days+=C(a.refMonth,a.months)),delete a.months, 7<=a.days&&(a.weeks+=p(a.days/7),a.days%=7)):a.months&&b++;!(d&32)||b>=f?(a.days+=7*a.weeks,delete a.weeks):a.weeks&&b++;!(d&16)||b>=f?(a.hours+=24*a.days,delete a.days):a.days&&b++;!(d&8)||b>=f?(a.minutes+=60*a.hours,delete a.hours):a.hours&&b++;!(d&4)||b>=f?(a.seconds+=60*a.minutes,delete a.minutes):a.minutes&&b++;!(d&2)||b>=f?(a.milliseconds+=1E3*a.seconds,delete a.seconds):a.seconds&&b++;if(!(d&1)||b>=f){var h=n(a,0,"milliseconds","seconds",1E3,m);if(h&&(h=n(a,h,"seconds","minutes",60,m))&&(h= n(a,h,"minutes","hours",60,m))&&(h=n(a,h,"hours","days",24,m))&&(h=n(a,h,"days","weeks",7,m))&&(h=n(a,h,"weeks","months",z(a.refMonth)/7,m))){d=h;var e,l=a.refMonth,q=l.getTime,r=new Date(q);r.setFullYear(l.getFullYear+1);e=Math.round((r.getTime-q)/864E5);if(h=n(a,d,"months","years",e/z(a.refMonth),m))if(h=n(a,h,"years","decades",10,m))if(h=n(a,h,"decades","centuries",10,m))if(h=n(a,h,"centuries","millennia",10,m))throw Error("Fractional unit overflow");}}}finally{delete a.refMonth}return a} function e(a,b,c,d,f){var e;c=+c||222;d=0f?Math.round(f):20:0;var k=null;"function"===typeof a?(e=a,a=null):a instanceof Date||(null!==a&&isFinite(a)?a=new Date(+a):("object"===typeof k&&(k=a),a=null));var g=null;"function"===typeof b?(e=b,b=null):b instanceof Date||(null!==b&&isFinite(b)?b=new Date(+b):("object"===typeof b&&(g=b),b=null));k&&(a=A(k,b));g&&(b=A(g,a));if(!a&&!b)return new q;if(!e)return D(new q,a,b,c,d,f);var k=c&1?1E3/30:c&2?1E3:c&4?6E4:c&8?36E5:c&16?864E5:6048E5, h,g=function{e(D(new q,a,b,c,d,f),h)};g;return h=setInterval(g,k)}var s=Math.ceil,p=Math.floor,w,x,r,t,u,v,B;q.prototype.toString=function(a){var b=B(this),c=b.length;if(!c)return a?""+a:u;if(1===c)return b[0];a=r+b.pop;return b.join(t)+a};q.prototype.toHTML=function(a,b){a=a||"span";var c=B(this),d=c.length;if(!d)return(b=b||u)?"\x3c"+a+"\x3e"+b+"\x3c/"+a+"\x3e":b;for(var f=0;f<d;f++)c[f]="\x3c"+a+"\x3e"+c[f]+"\x3c/"+a+"\x3e";if(1===d)return c[0];d=r+c.pop;return c.join(t)+d};q.prototype.addTo= function(a){return A(this,a)};B=function(a){var b=[],c=a.millennia;c&&b.push(l(c,10));(c=a.centuries)&&b.push(l(c,9));(c=a.decades)&&b.push(l(c,8));(c=a.years)&&b.push(l(c,7));(c=a.months)&&b.push(l(c,6));(c=a.weeks)&&b.push(l(c,5));(c=a.days)&&b.push(l(c,4));(c=a.hours)&&b.push(l(c,3));(c=a.minutes)&&b.push(l(c,2));(c=a.seconds)&&b.push(l(c,1));(c=a.milliseconds)&&b.push(l(c,0));return b};e.MILLISECONDS=1;e.SECONDS=2;e.MINUTES=4;e.HOURS=8;e.DAYS=16;e.WEEKS=32;e.MONTHS=64;e.YEARS=128;e.DECADES=256; e.CENTURIES=512;e.MILLENNIA=1024;e.DEFAULTS=222;e.ALL=2047;e.setLabels=function(a,b,c,d,f,e){a=a||[];a.split&&(a=a.split("|"));b=b||[];b.split&&(b=b.split("|"));for(var k=0;10>=k;k++)w[k]=a[k]||w[k],x[k]=b[k]||x[k];r="string"===typeof c?c:r;t="string"===typeof d?d:t;u="string"===typeof f?f:u;v="function"===typeof e?e:v};(e.resetLabels=function{w=" millisecond; second; minute; hour; day; week; month; year; decade; century; millennium".split(";");x=" milliseconds; seconds; minutes; hours; days; weeks; months; years; decades; centuries; millennia".split(";"); r=" and ";t=", ";u="";v=function(a){return a}});y&&y.exports?y.exports=e:"function"===typeof window.define&&"undefined"!==typeof window.define.amd&&window.define("countdown",[],function{return e});return e}(module);

countdown.setLabels(   '|s|m|hr|d||||||',    '|s|m|hr|d||||||',    ' ',    ' ',    ' ');

//

// Map of game names to IDs in abios' data // see http://ext.abiosgaming.com/extension/games var AbiosGames = { 'dota_2'     : '1', 'lol'        : '2', 'sc2'        : '3', 'hon'        : '4', 'csgo'       : '5', 'hearthstone' : '6', 'wow'        : '7', 'smite'      : '8', 'hots'       : '9' };

var AbiosDataFeed = { vars: { debug: false, live_matches_url: 'http://ext.abiosgaming.com/extension/live-matches', cache_length: 5, // minutes games: [ // Games whose data we care about AbiosGames.dota_2 ]   },    getLiveMatches: function{ var games = AbiosDataFeed.vars.games, cache_key = 'abios_matches' + JSON.stringify(games), dfd = jQuery.Deferred;

if (AbiosDataFeed.vars.debug) { console.group("AbiosDataFeed getLiveMatches"); console.info("Requesting live matches for games: %s", AbiosDataFeed.vars.games); }

// If data is in cache, serve it! var data = lscache.get(cache_key); if (data) { if (AbiosDataFeed.vars.debug) { console.info("Data retrieved from cache."); }           dfd.resolve(data); }       else { if (AbiosDataFeed.vars.debug) { console.info("Data not in cache, requesting from API."); }

$.ajax({               url: this.vars.live_matches_url,                type: 'GET',                data: {                    games: games                },                success: function(data) {                    if (AbiosDataFeed.vars.debug) {                        console.info("Data received for: %s; caching.", cache_key);                    }                    lscache.set(cache_key, data, AbiosDataFeed.vars.cache_length);                    dfd.resolve(data);                }            }); }

if (AbiosDataFeed.vars.debug) { console.groupEnd; }

// Returning a deferred so we don't have to wrestle with 50,000 // callback functions return dfd.promise; } };

//

var UpcomingMatches = { vars: { limit: 20 // How many rows to render },   templates: { row: ' \ __TOURNAMENT_NAME__ \ __TEAM_1_NAME__  \ vs \  __TEAM_2_NAME__ \ __MATCH_TIMESTAMP__ \ '   },    renderTo: function(selector, limit){ // Render the live data feed to the given selector limit = limit || UpcomingMatches.vars.limit; var $target = jQuery(selector);

AbiosDataFeed.getLiveMatches.done(function(live_matches){           live_matches = live_matches.slice(0, limit);            $.each(live_matches, function(i){

// Ensure all the data we require is available from the feed. If not skip this row if (undefined === this.event      || null === this.event       ||                    undefined === this.event.wiki  || null === this.event.wiki  ||                    undefined === this.event.title || null === this.event.title ||                    undefined === this.displayed   || null === this.displayed   ||                    undefined === this.start       || null === this.start       ||                    undefined === this.end         || null === this.end         ||                    undefined === this.game_id     || null === this.game_id                ) { console.info("Skipping row due to incomplete data: %s", JSON.stringify(this)); return; }

var tournament_url = this.event.wiki.indexOf('gamepedia.com') !== -1 ? this.event.wiki : ('/' + this.event.title), tournament_name = this.event.title, team_1_url = this.displayed.comp_a ? ('/' + this.displayed.comp_a.name) : false, team_1_name = this.displayed.comp_a ? this.displayed.comp_a.name : '–', team_2_url = this.displayed.comp_b ? ('/' + this.displayed.comp_b.name) : false, team_2_name = this.displayed.comp_b ? this.displayed.comp_b.name : '–', timestamp_start = this.start, timestamp_end = this.end, livestream_url = this.caster ? this.caster._self : this.event._self, srcA, srcB;

// Determine image sources (copied straight from abios' chrome extension) if (this.displayed.comp_a == null || (this.displayed.comp_a.team != null && this.displayed.comp_a.team.image == null) || (this.displayed.comp_a.team == null && this.displayed.comp_a.image == null)) srcA = "http://static.abiosgaming.com/images/Competitors/icons/unknown-" + this.game_id + ".png"; else srcA = "http://static.abiosgaming.com/images/" + this.displayed.comp_a.team.image.folder + "/icons/" + this.displayed.comp_a.team.image.filename;

if (this.displayed.comp_b == null || (this.displayed.comp_b.team != null && this.displayed.comp_b.team.image == null) || (this.displayed.comp_b.team == null && this.displayed.comp_b.image == null)) srcB = "http://static.abiosgaming.com/images/Competitors/icons/unknown-" + this.game_id + ".png"; else srcB = "http://static.abiosgaming.com/images/" + this.displayed.comp_b.team.image.folder + "/icons/" + this.displayed.comp_b.team.image.filename;

var row_html = UpcomingMatches.templates.row;

row_html = row_html.replace(/__TOURNAMENT_URL__/g, tournament_url); row_html = row_html.replace(/__TOURNAMENT_NAME__/g, tournament_name); row_html = row_html.replace(/__TEAM_1_URL__/g, team_1_url); row_html = row_html.replace(/__TEAM_1_NAME__/g, team_1_name); row_html = row_html.replace(/__TEAM_1_SRC__/g, srcA); row_html = row_html.replace(/__TEAM_2_URL__/g, team_2_url); row_html = row_html.replace(/__TEAM_2_NAME__/g, team_2_name); row_html = row_html.replace(/__TEAM_2_SRC__/g, srcB); row_html = row_html.replace(/__MATCH_TIMESTAMP__/g, timestamp_start);

var $row = $(row_html);

// If any of the teams are blank, remove the link and replace it with an ndash if (team_1_url === false) { $row.find('.team:first a').replaceWith($(' – ')); }               if (team_2_url === false) { $row.find('.team:last a').replaceWith($(' – ')); }

// Start the countdown var row_countdown = countdown(new Date(timestamp_start * 1000),                   function(ts) {                        // Check if match is live, over, or coming up                        var now = Math.floor(new Date.getTime/1000);                        if (timestamp_end !== null && timestamp_end < now) { // Match over                            clearInterval(row_countdown);                            $row.find('.countdown span').html("Finished");                        }                        else if (timestamp_start <= now && timestamp_end > now) { // Live                            $row.find('.countdown span').html('LIVE</a>');                        }                        else {                            $row.find('.countdown span').html(ts.toHTML);                        }                    },                    countdown.DAYS|countdown.HOURS|countdown.MINUTES);

$target.append($row); });       });    } };

//

jQuery(document).ready(function{   if (jQuery('#upcoming_matches').length) {        UpcomingMatches.renderTo('#upcoming_matches tbody');    } });

/* * END Upcoming matches calendar