Difference between revisions of "MediaWiki:Common.js"

From QWiki
m
m (Blanked the page)
Line 1: Line 1:
/* Any JavaScript here will be loaded for users using the LiquiFlow skin */
 
  
/* Main Page latest uploads */
 
$(document).ready(function() {
 
if($('#latest-uploads').length) {
 
$.getJSON(mw.util.wikiScript( 'api' ) + '?action=query&list=logevents&leaction=upload/upload&lelimit=10&continue=&format=json', function(data) {
 
data = data.query.logevents;
 
var imagenames = [];
 
var imageurls = [];
 
$.each(data, function() {
 
imagenames.push(this.title);
 
});
 
$.getJSON(mw.util.wikiScript( 'api' ) + '?action=query&prop=imageinfo&titles=' + imagenames.join('|') + '&iiprop=url&iiurlheight=150px&format=json', function(fileurls) {
 
fileurls = fileurls.query.pages;
 
var output = '';
 
$.each(fileurls, function(j, fileurl) {
 
if(typeof fileurl.imageinfo !== 'undefined') {
 
imageurls[fileurl.title] = fileurl.imageinfo[0].thumburl;
 
}
 
});
 
$.each(fileurls, function(i, fileurl) {
 
if(typeof fileurl.imageinfo !== 'undefined') {
 
output += '<div><a href="http://wiki.teamliquid.net/commons/' + fileurl.title + '"><img src="' + fileurl.imageinfo[0].thumburl + '"><br><p>' + fileurl.title + '</p></a></div>';
 
}
 
});
 
$('#latest-uploads').html(output);
 
});
 
});
 
}
 
});
 
 
/* Redirect Special:Upload to Special:Login for logged out people */
 
window.addEventListener("load", function() {
 
if((mw.config.get('wgPageName') == 'Special:Upload') && (mw.config.get('wgNamespaceNumber') == -1) && (typeof mw.user.isAnon == 'function') && (mw.user.isAnon())) {
 
    window.location.replace(mw.config.get('wgServer') + $('#mw-content-text a').attr('href'));
 
}
 
});
 
 
/* Tools */
 
var wikis = {
 
//'clashroyale': 'Clash Royale',
 
'commons': 'Liquipedia Commons',
 
'counterstrike': 'Counter-Strike',
 
'dota2': 'Dota 2',
 
'fighters': 'Fighting Games',
 
'hearthstone': 'Hearthstone',
 
'heroes': 'Heroes',
 
'overwatch': 'Overwatch',
 
'rocketleague': 'RocketLeague',
 
'smash': 'Smash',
 
'starcraft': 'StarCraft Brood War',
 
'starcraft2': 'StarCraft II',
 
'warcraft': 'Warcraft',
 
};
 
if($('#checkforpageexistence').length) {
 
$('#checkforpageexistence').append('<form id="checkforpageexistenceform"><input id="checkforpageexistenceinput" class="form-control"><button id="checkforpageexistencebutton" class="btn btn-primary" type="submit">Search</button></form><div id="checkforpageexistenceresult"></div>');
 
document.getElementById('checkforpageexistenceform').addEventListener("submit", checkforpageexistence);
 
}
 
function checkforpageexistence(e) {
 
e.preventDefault();
 
$('#checkforpageexistenceresult').html('<ul id="checkforpageexistenceresultlist"></ul>');
 
$.each(wikis, function(index, name) {
 
$.getJSON('http://wiki.teamliquid.net/' + index + '/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=' + $('#checkforpageexistenceinput').val(), function(data) {
 
if(typeof data.query != 'undefined') {
 
if(typeof data.query.pages['-1'] == 'undefined') {
 
$('#checkforpageexistenceresultlist').append('<li><a href="http://wiki.teamliquid.net/' + index + '/' + $('#checkforpageexistenceinput').val() + '" style="color:#006400;">'+ name + ': Yes</a></li>');
 
} else {
 
$('#checkforpageexistenceresultlist').append('<li><a href="http://wiki.teamliquid.net/' + index + '/' + $('#checkforpageexistenceinput').val() + '" style="color:#ff0000;">'+ name + ': No</a></li>');
 
}
 
} else {
 
$('#checkforpageexistenceresultlist').html('<li style="color:#0000ff;">You need to put in a valid page title</li>');
 
}
 
});
 
});
 
return false;
 
}
 
 
/*******************************************************************************
 
Template(s): Countdown Time code
 
Author(s): Kenjin`-
 
*******************************************************************************/
 
function DateError(message) {
 
this.message = message;
 
this.name = "DateError";
 
}
 
;(function(w, doc, isAlreadyDeleted) {
 
var datetimes = [].slice.call(doc.querySelectorAll('.datetime'));
 
var countdowns = [].slice.call(doc.querySelectorAll('.countdown'));
 
var streamLink = [].slice.call(doc.querySelectorAll('.streamLink'));
 
 
var times = [], tempDate, tempTimezone, tempStream, tempStreams, streams = [];
 
var timeNow = new Date();
 
var endTime;
 
isAlreadyDeleted = [];
 
ClassIsAlreadySet = [];
 
 
for (var i = 0, length = datetimes.length; i < length; i++) {
 
tempDate = datetimes[i];
 
//console.log(datetimes[i].childNodes.length);
 
elemsChildNodes = datetimes[i].childNodes;
 
 
for (j = 0; j < elemsChildNodes.length; j++) {
 
if (elemsChildNodes[j].nodeName === 'ABBR') {
 
tempTimezone = elemsChildNodes[j].getAttribute("title").trim();
 
break;
 
} else
 
tempTimezone = false;
 
}
 
 
// Check if the class is set
 
isAlreadyDeleted[i] = 0;
 
ClassIsAlreadySet[i] = 0;
 
// UTC Time from the Event is in times now
 
try {
 
times[i] = stringToDate(tempDate, tempTimezone);
 
} catch(error) {
 
countdowns[i].innerHTML = 'ERROR';
 
}
 
}
 
 
for (var j = 0, lengthStream = streamLink.length; j < lengthStream; j++) {
 
tempStream = streamLink[j];
 
//console.log(datetimes[j].childNodes.length);
 
elemsChildNodesStream = streamLink[j].childNodes;
 
 
if(elemsChildNodesStream.length > 0){
 
for (var k = 0; k < elemsChildNodesStream.length; k++) {
 
tempStreams = elemsChildNodesStream[k];
 
}
 
} else {
 
tempStreams = 0;
 
}
 
 
streams[j] = tempStreams;
 
}
 
 
setInterval(updateCountdowns(times, countdowns, timeNow, streams, isAlreadyDeleted), 1000);
 
 
 
 
})(window,document);
 
 
function stringToDate(tempDate, tempTimezone) {
 
var tempDateinnerhTML,
 
posTimezone,
 
tempPosTimezone,
 
UTCTime = 0;
 
 
if (tempDate.childNodes !== undefined && typeof tempDate.childNodes[1] !== 'undefined' && typeof tempDate.childNodes[1].childNodes[0] !== 'undefined' && tempDate.childNodes[1].childNodes[0].nodeValue !== null) {
 
tempDateinnerhTML = tempDate.childNodes[0].nodeValue + tempDate.childNodes[1].childNodes[0].nodeValue;
 
} else {
 
tempDateinnerhTML = tempDate.childNodes[0].nodeValue;
 
}
 
 
if (tempTimezone !== false) {
 
posTimezone = tempTimezone.indexOf("(UTC") + 1;
 
 
if (posTimezone > 0) {
 
tempPosTimezone = tempTimezone.slice(posTimezone, -1);
 
UTCTime = tempPosTimezone.substring(3);
 
}
 
} else {
 
posTimezone = tempDate.innerHTML.trim().indexOf("(UTC") + 1;
 
 
if (posTimezone > 0) {
 
tempPosTimezone = tempDate.innerHTML.trim().slice(posTimezone, -1);
 
UTCTime = tempPosTimezone.substring(3, 5);
 
}
 
}
 
 
if (tempDateinnerhTML == null) {
 
throw new DateError("Date is null");
 
}
 
 
// Creating DateObject from tempDate
 
var str = tempDateinnerhTML.trim().split(" ");
 
 
for (var j = 0; j < str.length; j++)
 
str[j] = str[j].trim();
 
 
str = str.filter(function(e) { return e; });
 
 
if (tempDateinnerhTML.indexOf(':') === -1) {
 
return 0;
 
} else {
 
if (('TBA' in oc(str)) || ('TBD' in oc(str))) {
 
return 0;
 
} else {
 
var index2 = str.indexOf('-');
 
 
var placeholder_temp2 = 0;
 
if (index2 !== -1) {
 
str.splice(index2, 1);
 
placeholder_temp2 = 1;
 
}
 
if (str.length === 6)
 
str.splice(str.length - 2, 1, 'GMT');
 
if (str.length === 5)
 
str.splice(str.length - 1, 1, 'GMT');
 
if (str.length === 4)
 
str.splice(str.length, 1, 'GMT');
 
 
var date_temp_2 = str.join(" ");
 
 
//get the UTC time, and setHours according to it
 
endTime = new Date(date_temp_2);
 
endTime.setHours(endTime.getHours() - UTCTime);
 
}
 
return endTime;
 
}
 
}
 
 
function oc(a) {
 
var o = {};
 
for (var i = 0; i < a.length; i++) {
 
o[a[i]] = '';
 
}
 
return o;
 
}
 
 
function hasClass(element, cls) {
 
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
 
}
 
 
function updateCountdowns(times, countdowns, timeNow, streams, isAlreadyDeleted) {
 
 
return function() {
 
var cssClass = [].slice.call(document.querySelectorAll('.cssTestClass'));
 
 
//console.log(cssClass);
 
 
if (cssClass) {
 
for (var x = 0; x < cssClass.length; x++) {
 
cssClass[x].nextElementSibling.parentNode.removeChild(cssClass[x].nextElementSibling);
 
cssClass[x].parentNode.removeChild(cssClass[x]);
 
}
 
}
 
 
var calculatedDifference, calculatedDifferenceB, time, timeIfEventIsOver, countdown_h, streamLinkBaseUrl;
 
 
for (var i = 0, length = countdowns.length; i < length; i++) {
 
calculatedDifference = 0;
 
time = times[i];
 
 
timeIfEventIsOver = time - timeNow;
 
timeIfEventIsOver = Math.floor(timeIfEventIsOver / 1000);
 
 
countdown_h = Math.floor(timeIfEventIsOver / 3600);
 
if (countdown_h < -12) {
 
calculatedDifference = 'Done';
 
} else if (isNaN(countdown_h))
 
calculatedDifference = 'ERROR';
 
else {
 
calculatedDifference = calculateDifference(time);
 
}
 
// calculate the difference
 
// and update the countdown div/span
 
if (calculatedDifference === 'Done') {
 
if (isAlreadyDeleted[i] === 0) {
 
countdowns[i].parentNode.removeChild(countdowns[i]);
 
isAlreadyDeleted[i] = '1';
 
}
 
} else {
 
if (calculatedDifference !== 'LIVE!') {
 
countdowns[i].innerHTML = calculatedDifference;
 
} else {
 
if (ClassIsAlreadySet[i] === 0) {
 
calculatedDifferenceB = (streams[i] && streams[i] != 0);
 
if (calculatedDifferenceB) {
 
switch (mw.config.get( 'wgScriptPath' )) {
 
case "/dota2":
 
streamLinkBaseUrl = "http://www.liquiddota.com/stream/";
 
break;
 
case "/hearthstone":
 
streamLinkBaseUrl = "http://www.liquidhearth.com/stream/";
 
break;
 
default:
 
streamLinkBaseUrl = "http://www.teamliquid.net/video/streams/";
 
break;
 
}
 
calculatedDifference = '<a class="hasStream" href="'+streamLinkBaseUrl+streams[i].data+'" target="_blank">LIVE!</a>'
 
} else {
 
calculatedDifference = "LIVE!";
 
}
 
countdowns[i].innerHTML = calculatedDifference;
 
countdowns[i].className += " EventIsLive";
 
ClassIsAlreadySet[i] = 1;
 
}
 
}
 
}
 
}
 
};
 
}
 
 
function calculateDifference(diffTime) {
 
 
var tage = 'd';
 
var string;
 
var countdown_d, countdown_h, countdown_m, countdown_s, countdown_w;
 
var output_s, output_m, output_h, error = '1';
 
timeNow = new Date();
 
 
diffTime -= timeNow;
 
// calculate difference and save it as String in "string"
 
diffTime = Math.floor(diffTime / 1000);
 
 
if (diffTime >= 0) {
 
 
countdown_w = Math.floor(diffTime / 604800);
 
diffTime = diffTime % 604800;
 
countdown_d = Math.floor(diffTime / 86400);
 
diffTime = diffTime % 86400;
 
countdown_h = Math.floor(diffTime / 3600);
 
diffTime = diffTime % 3600;
 
countdown_m = Math.floor(diffTime / 60);
 
countdown_s = diffTime % 60;
 
 
if (countdown_s < 10) output_s = '0' + countdown_s;
 
else output_s = countdown_s;
 
if (countdown_m < 10) output_m = '0' + countdown_m;
 
else output_m = countdown_m;
 
if (countdown_h < 10) output_h = '0' + countdown_h;
 
else output_h = countdown_h;
 
 
if (countdown_d >= 1 && countdown_w >= 1)
 
string = countdown_w + 'w ' + countdown_d + tage;
 
else if (countdown_d === 0 && countdown_w >= 1)
 
string = countdown_w + 'w ' + countdown_d + tage;
 
else if (countdown_d > 0 && countdown_w === 0)
 
string = countdown_d + tage + ' ' + output_h + 'h ' + output_m + 'm';
 
else
 
string = output_h + 'h ' + output_m + 'm ' + output_s + 's';
 
} else {
 
//after 12h the div/span says "done" instead of live
 
string = 'LIVE!';
 
}
 
return string;
 
}
 
 
function isInt(n) {
 
return typeof n === 'number' && n % 1 === 0;
 
}
 
 
/*******************************************************************************
 
Template(s): Liquid Layout for Boxes code
 
Author(s): Kenjin and stijn
 
*******************************************************************************/
 
$(window).on('resize', function() {
 
$('.justify-wrap').each(function() {
 
var boxes = $(this).find('> div');
 
var boxCount = boxes.size();
 
var windowSize = $(this).parent().width();
 
var boxWidth = boxes.eq(1).width();
 
 
//save box padding upon first resize
 
if(!$(this).data('boxPadding'))
 
$(this).data('boxPadding', parseInt(boxes.eq(1).css('padding-right')) + parseInt(boxes.eq(1).css('padding-left')));
 
var boxPadding = $(this).data('boxPadding');
 
//take box model into account when calculating width
 
//padding is calculated earlier and reset to be used as margin
 
var realWidth = boxWidth + boxPadding +
 
parseInt(boxes.eq(1).css('border-left-width')) +
 
parseInt(boxes.eq(1).css('border-right-width'));
 
//halt reformatting if box is wider than window (no visible effect anyway)
 
if(realWidth > windowSize) {
 
return false;
 
}
 
//find the least amount of boxes that fit on a row, while
 
//still using the least amount of rows
 
var maxBoxes = Math.ceil(boxCount / Math.ceil(boxCount / Math.floor(windowSize / realWidth)));
 
var perRow = (boxCount < maxBoxes) ? boxCount : maxBoxes;
 
console.log(windowSize);
 
//calculate margin between boxes, clamped by box size (max) and padding (min)
 
/*
 
var margin = Math.floor((windowSize - ((perRow) * realWidth)) / (perRow + 0.5));
 
if(margin > realWidth) margin = realWidth;
 
if(margin < boxPadding) margin = boxPadding;
 
*/
 
var margin = boxPadding;
 
boxes.each(function(i) {
 
$(this).css('padding-left', 0).css('padding-right', 0).css('margin-right', 0);
 
$(this).css('display', 'block').css('float', 'left');
 
if(i % maxBoxes == 0) {
 
$(this).css('clear', 'left').css('margin-left', 0);
 
} else {
 
$(this).css('clear', 'none').css('margin-left', margin + 'px');
 
}
 
});
 
});
 
});
 
$(document).ready(function() {
 
$(window).trigger('resize');
 
});
 
 
/*******************************************************************************
 
Template(s): Hides stuff for logged out people
 
Author(s): Chapatiyaq
 
*******************************************************************************/
 
$(document).ready(function () {
 
mw.loader.using('mediawiki.user', function() {
 
$('.hidden-when-logged-in').toggle( mw.user.isAnon() );
 
$('.shown-when-logged-in').toggle( !mw.user.isAnon() );
 
});
 
});
 
 
/*******************************************************************************
 
Template(s): Timeline
 
Author(s): ???
 
*******************************************************************************/
 
$(document).ready(function () {
 
if($('.scrollTimeline').length > 0) {
 
$('.scrollTimeline')[0].scrollLeft = $('.timeline').width();
 
}
 
});
 
 
/*******************************************************************************
 
Template(s): Participants Tables
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
$(document).ready(function() {
 
$('.participants-table-button-left').addClass('inactive');
 
$('.participants-table-button-left').click(function() {
 
if($(window).width() < 600) {
 
var scroller = $(this).closest('.participants-table-wrapper').children('.participants-table-scroller');
 
scroller.scrollLeft(scroller.scrollLeft() - 0.83 * $(window).width());
 
}
 
});
 
$('.participants-table-button-right').click(function() {
 
if($(window).width() < 600) {
 
var scroller = $(this).closest('.participants-table-wrapper').find('.participants-table-scroller');
 
scroller.scrollLeft(scroller.scrollLeft() + 0.83 * $(window).width());
 
}
 
});
 
$('.participants-table-scroller').scroll(function() {
 
$(this).closest('.participants-table-wrapper').find('.participants-table-button-left').removeClass('inactive');
 
$(this).closest('.participants-table-wrapper').find('.participants-table-button-right').removeClass('inactive');
 
if($(this).scrollLeft() == 0) {
 
$(this).closest('.participants-table-wrapper').find('.participants-table-button-left').addClass('inactive');
 
}
 
if($(this).scrollLeft() == $(this).find('.participants-table').width() - $(this).closest('.participants-table-wrapper').width()) {
 
$(this).closest('.participants-table-wrapper').find('.participants-table-button-right').addClass('inactive');
 
}
 
});
 
});
 
 
/*******************************************************************************
 
Template(s): Heroes portal on the Heroes of the Storm wiki
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
$(document).ready(function () {
 
$('.hexagon-button').click(function(){
 
$(this).parent().parent().parent().toggleClass('show-' + $(this).data('show'));
 
});
 
});
 
 
/*******************************************************************************
 
Template(s): Well... you know what this is :P
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
var date = new Date();
 
if(date.getMonth() + "-" + date.getDate() == "3-1") {
 
$('#brand-logo').attr('src', $('#brand-logo').attr('src').replace('liquipedia', 'lickypiddy'));
 
}
 
 
/*******************************************************************************
 
Template(s): insert current ti prizepool on main page
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
/* insert current ti prizepool on main page */
 
/*$(document).ready(function() {
 
if (('#currenttiprizepool').length) {
 
$.getJSON('//wiki.teamliquid.net/dota2/api.php?action=query&prop=revisions&rvprop=content&format=json&maxage=60&smaxage=60&titles=The International/2015/prizepool', function (result) {
 
var content = result['query']['pages']['25304']['revisions'][0]['*'];
 
$('#currenttiprizepool').text(' - Current prize pool: $' + content);
 
});
 
}
 
});*/
 
 
/* testing something */
 
if(mw.config.get('wgUserName') == 'FO-nTTaX') {
 
/*$('table').each(function() {
 
$this = $(this);
 
if(!$this.hasClass('navbox')
 
  && !$this.hasClass('logo')
 
  && !$this.hasClass('list')
 
  && !$this.parents('.navbox').length
 
  ) {
 
if(!$this.parent().hasClass('table-responsive')) {
 
$this.wrap('<div class="table-responsive"></div>');
 
}
 
}
 
});*/
 
}
 
 
/*******************************************************************************
 
Template(s): Dismissable SiteNotice
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
$(document).ready(function() {
 
$('#siteNotice').prepend('<div id="closeSiteNotice" style="float:right;cursor:pointer;font-size:14px;border:1px solid #333333;margin:10px;line-height:10px;padding:5px;" title="Close Notice">&times;</div>');
 
 
$('#closeSiteNotice').click(function() {
 
$('#siteNotice').fadeOut(500);
 
var d = new Date(+new Date + 12096e5);
 
document.cookie='showSiteNotice=false; domain=wiki.teamliquid.net; expires=' + d.toUTCString() + '; path=/' + window.location.href.split('/')[3] + '/';
 
});
 
 
if(document.cookie.indexOf('showSiteNotice=false') != -1) {
 
$('#siteNotice').hide();
 
}
 
});
 
 
/*******************************************************************************
 
Template(s): Popups for all Brackets
 
Author(s): Anomek, FO-nTTaX
 
*******************************************************************************/
 
var bracketGame;
 
$.fn.justtext = function() {
 
return $(this).clone().children().remove('div.bracket-score').end().text().trim();
 
};
 
$(document).ready(function() {
 
$('.bracket-game').each( function() {
 
if ($(this).find('.bracket-popup-wrapper').length > 0) {
 
var margin = $(this).find(':first-child').height() - 6;
 
$(this).prepend('<div class="icon" style="margin-top:' + margin + 'px;"></div>');
 
$(this).find('.bracket-team-top, .bracket-team-bottom, .bracket-player-top, .bracket-player-bottom').each(function() {
 
$(this).css('cursor', 'pointer');
 
$(this).attr('title', 'Click for further information');
 
});
 
}
 
});
 
$('tr.match-row').each( function() {
 
if ($(this).find('.bracket-popup-wrapper').length > 0) {
 
$(this).children('td:eq(2)').prepend('<div style="position:relative"><div class="match-row-icon"></div></div>');
 
$(this).children('td.matchlistslot').find('a').attr('href', 'javascript:;');
 
}
 
$(this).attr('title', 'Click for further information');
 
});
 
$('html').click(function () {
 
if (bracketGame != null) {
 
bracketGame.find('.bracket-popup-wrapper').toggle();
 
bracketGame = null;
 
}
 
});
 
$('.bracket-team-top, .bracket-team-bottom, .bracket-player-top, .bracket-player-bottom, .bracket-game .icon').click(
 
function (event) {
 
var bracket = $(this).closest('.bracket, .crosstable td'), bracketWrapper = $(this).closest('.bracket-wrapper, .crosstable'),
 
detailsWidth, spaceOnTheRight, popupOnTheRight = true;
 
if (bracketGame != null) {
 
bracketGame.find('.bracket-popup-wrapper').toggle();
 
if (bracketGame[0] === $(this).closest('.bracket-game')[0]) {
 
bracketGame = null;
 
return;
 
}
 
}
 
bracketGame = $(this).closest('.bracket-game');
 
positionBracketPopup();
 
bracketGame.children('.bracket-popup-wrapper').css('margin-left', '');
 
bracketGame.children('.bracket-popup-wrapper').toggle();
 
if(popupOnTheRight && bracketGame.offset().left + bracketGame.outerWidth() + detailsWidth > bracketWrapper.outerWidth() + bracketWrapper.offset().left) {
 
bracketWrapper.scrollLeft(bracketWrapper.scrollLeft() + detailsWidth);
 
}
 
positionBracketPopup();
 
event.stopPropagation();
 
});
 
$('tr.match-row').click(function (event) {
 
if (bracketGame != null) {
 
bracketGame.find('.bracket-popup-wrapper').toggle();
 
if (bracketGame[0] === $(this)[0]) {
 
bracketGame = null;
 
return;
 
}
 
}
 
bracketGame = $(this);
 
positionGroupTablePopup();
 
bracketGame.find('.bracket-popup-wrapper').css('margin-left', '');
 
bracketGame.find('.bracket-popup-wrapper').toggle();
 
positionGroupTablePopup();
 
event.stopPropagation();
 
});
 
$('.bracket-popup-wrapper').click(function (event) {
 
event.stopPropagation();
 
});
 
});
 
 
$(window).scroll(function() {
 
positionBracketPopup();
 
positionGroupTablePopup();
 
});
 
$('.bracket-wrapper').scroll(function() {
 
positionBracketPopup();
 
});
 
$(window).resize(function() {
 
positionBracketPopup();
 
positionGroupTablePopup();
 
});
 
 
function positionBracketPopup() {
 
if((bracketGame != null) && (bracketGame.find('.icon').length)) {
 
if($(document).width() > 600) {
 
var bracket = bracketGame.closest('.bracket, .crosstable td'), bracketWrapper = bracketGame.closest('.bracket-wrapper, .crosstable'),
 
detailsHeight, detailsWidth, spaceOnTheRight, popupOnTheRight = true;
 
detailsHeight = bracketGame.children('.bracket-popup-wrapper').height();
 
detailsWidth = bracketGame.children('.bracket-popup-wrapper').width();
 
bracketGame.children('.bracket-popup-wrapper').css('top', bracketGame.find('.icon').offset().top + (bracketGame.find('.icon').height() / 2) - (detailsHeight / 2) - $(window).scrollTop());
 
spaceOnTheRight = Math.max($(window).width(), bracket.offset().left + bracketWrapper.outerWidth()) - (bracketGame.offset().left + bracketGame.outerWidth());
 
if((spaceOnTheRight < detailsWidth && bracketGame.offset().left > detailsWidth) || (bracketGame.offset().left + bracketGame.width() > $('#main-content').offset().left + $('#main-content').width())) {
 
bracketGame.children('.bracket-popup-wrapper').css('left', bracketGame.offset().left - detailsWidth - 1);
 
} else {
 
bracketGame.children('.bracket-popup-wrapper').css('left', bracketGame.offset().left + bracketGame.width());
 
}
 
bracketGame.children('.bracket-popup-wrapper').removeClass('bracket-popup-mobile');
 
} else {
 
if(!bracketGame.children('.bracket-popup-wrapper').hasClass('bracket-popup-mobile')) {
 
bracketGame.children('.bracket-popup-wrapper').addClass('bracket-popup-mobile');
 
}
 
bracketGame.children('.bracket-popup-wrapper').css('top', '').css('left', '');
 
}
 
}
 
}
 
function positionGroupTablePopup() {
 
if((bracketGame != null) && (bracketGame.find('.match-row-icon').length)) {
 
if($(document).width() > 600) {
 
var row = bracketGame, detailsWidth;
 
detailsWidth = bracketGame.find('.bracket-popup-wrapper').width();
 
bracketGame.find('.bracket-popup-wrapper').css('top', row.offset().top + row.height() - $(window).scrollTop());
 
bracketGame.find('.bracket-popup-wrapper').css('left', row.offset().left + (row.width() / 2) - (detailsWidth / 2));
 
bracketGame.find('.bracket-popup-wrapper').removeClass('bracket-popup-mobile');
 
} else {
 
if(!bracketGame.find('.bracket-popup-wrapper').hasClass('bracket-popup-mobile')) {
 
bracketGame.find('.bracket-popup-wrapper').addClass('bracket-popup-mobile');
 
}
 
bracketGame.find('.bracket-popup-wrapper').css('top', '').css('left', '');
 
}
 
}
 
}
 
 
/*******************************************************************************
 
Template(s): Highlighting for all Brackets
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
var highlightingsearch = [];
 
var highlightingstandardicon = [
 
'Csgologo_std.png', //CS:GO
 
'Csslogo_std.png', //CS:Source
 
'Cstrikelogo_std.png', //CS:1.6
 
'Dotalogo_std.png', //Dota 2
 
'Fistlogo_std.png', //Fighting Games
 
'Hotslogo_std.png', //Heroes of the Storm
 
'Logo_filler_std.png', //Blank file, SC, SC2
 
'Overwatchlogo_std.png', //Overwatch
 
'Rllogo_std.png', //Rocketleague
 
'Warcraft_std.png' //Warcraft
 
];
 
$(document).ready(function() {
 
 
$('tr.match-row').hover(function () {
 
$(this).addClass('bracket-hover');
 
if ($(this).closest('tr.match-row').find('.bracket-popup-wrapper').length) {
 
$(this).css('cursor', 'pointer');
 
}
 
}, function () {
 
$(this).removeClass('bracket-hover');
 
});
 
 
if($('.bind-highlighting').length > 0) {
 
var highlightingbinds = [];
 
$('.bind-highlighting').each(function () {
 
var to = $(this).children('.bind-highlighting-to');
 
var from = $(this).children('.bind-highlighting-from');
 
 
var icto = $(to).find('.team-template-image img');
 
if (icto.length == 1) {
 
var icsrcto = icto.attr('src').split('/');
 
icsrcto = icsrcto[icsrcto.length - 1];
 
icsrcto = icsrcto.replace("-icon", "_std");
 
if (icsrcto.indexOf('-') != -1) {
 
icsrcto = icsrcto.split('-');
 
icsrcto = icsrcto[icsrcto.length - 1];
 
}
 
if (highlightingstandardicon.indexOf(icsrcto) != -1) {
 
icsrcto = $(to).justtext();
 
}
 
} else {
 
var icsrcto = $(to).justtext();
 
}
 
var icfrom = $(from).find('.team-template-image img');
 
if (icfrom.length == 1) {
 
var icsrcfrom = icfrom.attr('src').split('/');
 
icsrcfrom = icsrcfrom[icsrcfrom.length - 1];
 
icsrcfrom = icsrcfrom.replace("-icon", "_std");
 
if (icsrcfrom.indexOf('-') != -1) {
 
icsrcfrom = icsrcfrom.split('-');
 
icsrcfrom = icsrcfrom[icsrcfrom.length - 1];
 
}
 
if (highlightingstandardicon.indexOf(icsrcfrom) != -1) {
 
icsrcfrom = $(from).justtext();
 
}
 
} else {
 
var icsrcfrom = $(from).justtext();
 
}
 
highlightingbinds[icsrcfrom] = icsrcto;
 
});
 
}
 
$('.bracket-team-top, .bracket-team-bottom, .bracket-team-middle, .bracket-player-top, .bracket-player-bottom, .bracket-player-middle, .matchlistslot, .matchslot, .grouptableslot').each(function() {
 
var ic = $(this).find('.team-template-image img');
 
if (ic.length == 1) {
 
var icsrc = ic.attr('src').split('/');
 
icsrc = icsrc[icsrc.length - 1];
 
icsrc = icsrc.replace("-icon", "_std");
 
if (icsrc.indexOf('-') != -1) {
 
icsrc = icsrc.split('-');
 
icsrc = icsrc[icsrc.length - 1];
 
}
 
if (highlightingstandardicon.indexOf(icsrc) != -1) {
 
icsrc = $(this).justtext();
 
}
 
if ((typeof highlightingbinds !== 'undefined') && (icsrc in highlightingbinds)) {
 
icsrc = highlightingbinds[icsrc];
 
}
 
if (!Array.isArray(highlightingsearch[icsrc])) {
 
highlightingsearch[icsrc] = [];
 
}
 
highlightingsearch[icsrc].push(this);
 
$(this).data('highlightingkey', icsrc);
 
} else {
 
var icsrc = $(this).justtext();
 
if ((typeof highlightingbinds !== 'undefined') && (icsrc in highlightingbinds)) {
 
icsrc = highlightingbinds[icsrc];
 
}
 
if (!Array.isArray(highlightingsearch[icsrc])) {
 
highlightingsearch[icsrc] = [];
 
}
 
highlightingsearch[icsrc].push(this);
 
$(this).data('highlightingkey', icsrc);
 
 
/* Starcraft/Warcraft specific start */
 
if ((!$(this).hasClass('grouptableslot')) && (!$(this).hasClass('matchlistslot'))) {
 
$(this).data('background-color', $(this).css('background-color'));
 
switch ($(this).data('background-color')) {
 
case 'rgb(242, 184, 184)':
 
$(this).data('background-color-hover', 'rgb(250,217,217)'); //Zerg/Orc
 
break;
 
case 'rgb(184, 242, 184)':
 
$(this).data('background-color-hover', 'rgb(217,250,217)'); //Protoss/Nightelf
 
break;
 
case 'rgb(184, 184, 242)':
 
$(this).data('background-color-hover', 'rgb(217,217,250)'); //Terran/Human
 
break;
 
case 'rgb(242, 184, 242)':
 
$(this).data('background-color-hover', 'rgb(250,217,250)'); //Undead
 
break;
 
case 'rgb(242, 242, 184)':
 
$(this).data('background-color-hover', 'rgb(250,250,217)'); //Random
 
break;
 
default:
 
$(this).data('background-color-hover', 'rgb(250,250,250)'); //normal
 
break;
 
}
 
}
 
/* Starcraft/Warcraft specific end */
 
}
 
});
 
$('.bracket-team-top, .bracket-team-bottom, .bracket-team-middle, .bracket-player-top, .bracket-player-bottom, .bracket-player-middle, .matchlistslot, .matchslot, .grouptableslot').hover(function() {
 
var icsrc = $(this).data('highlightingkey');
 
if (typeof icsrc !== 'undefined') {
 
var filter = ['BYE', 'TBD', 'TBA', '', 'LOGO_FILLER_STD.PNG'];
 
if (filter.indexOf(icsrc.toUpperCase()) == -1) {
 
$.each(highlightingsearch[icsrc], function() {
 
$(this).addClass('bracket-hover');
 
/* Starcraft specific start */
 
if (typeof $(this).data('background-color-hover') !== 'undefined') {
 
$(this).css('background-color', $(this).data('background-color-hover'));
 
}
 
/* Starcraft specific end */
 
});
 
}
 
}
 
}, function() {
 
var icsrc = $(this).data('highlightingkey');
 
if (typeof icsrc !== 'undefined') {
 
$.each(highlightingsearch[icsrc], function() {
 
$(this).removeClass('bracket-hover');
 
/* Starcraft specific start */
 
if (typeof $(this).data('background-color-hover') !== 'undefined') {
 
$(this).css('background-color', $(this).data('background-color'));
 
}
 
/* Starcraft specific end */
 
});
 
}
 
});
 
 
 
});
 
 
/*******************************************************************************
 
Template(s): Toggle groups (see Template:Toggle group start)
 
Author(s): Chapatiyaq
 
*******************************************************************************/
 
var toggleShowCaption = 'show all', toggleHideCaption = 'hide all';
 
$('.toggle-group').each( function(index) {
 
var toggleDefaultState = $(this).is('.toggle-state-hide') ? 'Hide' : 'Show',
 
    $button = $('<span>')
 
.html('[')
 
.append($('<a>').addClass('toggle-button').text(window['toggle' + toggleDefaultState + 'Caption']).data('toggle-group-index', index).attr('href', 'javascript:'))
 
.append(']');
 
$(this).prepend($button);
 
$(this).attr('id', 'toggle-group-' + index);
 
});
 
$('.toggle-button').click( function() {
 
var toggleAction = $(this).text();
 
$('#toggle-group-' + $(this).data('toggle-group-index')).find('.collapseButton a').each( function() {
 
if (($(this).text() == collapseCaption && toggleAction == toggleHideCaption) || ($(this).text() == expandCaption && toggleAction == toggleShowCaption)) {
 
$(this)[0].click();
 
}
 
});
 
$(this).text($(this).text() == toggleShowCaption ? toggleHideCaption : toggleShowCaption);
 
});
 
 
/*******************************************************************************
 
Template(s): All Crosstables
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
var selector = '.crosstable';
 
 
$(selector).find('th, td').hover(function() {
 
var crosstable = $(this).closest(selector);
 
var rawrow = $(this).closest('tr').index();
 
var rawcol = $(this).index();
 
crosstable.addClass('row-' + (rawrow + 1)).addClass('col-' + (rawcol + 1));
 
crosstable.find('tr:nth-child(' + rawrow + ') td:nth-child(' + rawcol + ')').addClass('crosstable-top-left');
 
crosstable.find('tr:nth-child(' + rawrow + ') td:nth-child(' + (rawcol + 2) + ')').addClass('crosstable-top-right');
 
crosstable.find('tr:nth-child(' + (rawrow + 2) + ') td:nth-child(' + rawcol + ')').addClass('crosstable-bottom-left');
 
crosstable.find('tr:nth-child(' + (rawrow + 2) + ') td:nth-child(' + (rawcol + 2) + ')').addClass('crosstable-bottom-right');
 
}, function() {
 
var crosstable = $(this).closest(selector);
 
var rawrow = $(this).closest('tr').index();
 
var rawcol = $(this).index();
 
crosstable.removeClass('row-' + (rawrow + 1)).removeClass('col-' + (rawcol + 1));
 
crosstable.find('tr:nth-child(' + rawrow + ') td:nth-child(' + rawcol + ')').removeClass('crosstable-top-left');
 
crosstable.find('tr:nth-child(' + rawrow + ') td:nth-child(' + (rawcol + 2) + ')').removeClass('crosstable-top-right');
 
crosstable.find('tr:nth-child(' + (rawrow + 2) + ') td:nth-child(' + rawcol + ')').removeClass('crosstable-bottom-left');
 
crosstable.find('tr:nth-child(' + (rawrow + 2) + ') td:nth-child(' + (rawcol + 2) + ')').removeClass('crosstable-bottom-right');
 
});
 
 
/*******************************************************************************
 
Template(s): Liquipedia links
 
Author(s): ???
 
*******************************************************************************/
 
 
jQuery(document).ready(function() {
 
var sCurrentWiki = window.location.href.split('/')[3];
 
var iNumberOfLinks = jQuery('.liquipedia-links > li > a').length;
 
jQuery('.liquipedia-links > li > a').each(function() {
 
var $this = jQuery(this);
 
var sWiki = jQuery(this).attr('href').split('/')[3];
 
if(sWiki != sCurrentWiki) {
 
var sPageName = jQuery(this).text();
 
jQuery.getJSON('http://wiki.teamliquid.net/' + sWiki + '/api.php?action=query&titles=' + sPageName + '&prop=pageprops&format=json', function(data) {
 
jQuery.each(data.query.pages, function(iKey, oVal) {
 
var sPageNameFixed;
 
if((typeof oVal.pageprops !== 'undefined') && (typeof oVal.pageprops.displaytitle !== 'undefined')) {
 
sPageNameFixed = oVal.pageprops.displaytitle;
 
} else {
 
sPageNameFixed = oVal.title;
 
}
 
$this.html('&raquo; ' + sPageNameFixed);
 
jQuery('#scroll-wrapper-menu > ul > li > ul > li > a[href^="http://wiki.teamliquid.net/'+sWiki+'/"]').parent().after($this.parent());
 
});
 
});
 
}
 
});
 
jQuery('#brand-desktop').append('<span class="badge wiki-backgroundcolor-navbar-badge liquipedia-links-badge">' + iNumberOfLinks + '</span>');
 
});
 
 
/*******************************************************************************
 
Template(s): Prize pool tables
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
$(document).ready(function () {
 
$('table.prizepooltable').each(function (index) {
 
$(this).addClass('collapsed');
 
var cutafter;
 
if (($(this).attr('data-cutafter')) && ($(this).data('cutafter') == '')) {
 
cutafter = 5;
 
} else {
 
cutafter = parseInt($(this).data('cutafter')) +  1;
 
}
 
$(this).data('definedcutafter', cutafter + 2);
 
if ($(this).find('tr').length > cutafter) {
 
$(this).find('tr:nth-child('+cutafter+')').after('<tr><td colspan="'+$(this).find('tr:first-child th').length+'" class="prizepooltabletoggle"><small class="prizepooltableshow">place '+cutafter+' to '+ ($(this).find('tr').length - 1) +' <i class="fa fa-chevron-down"></i></small><small class="prizepooltablehide">place '+cutafter+' to '+ ($(this).find('tr').length - 1) +' <i class="fa fa-chevron-up"></i></small></td></tr>');
 
$(this).closest('table.prizepooltable').find('tr:nth-child(n+'+ $(this).closest('table.prizepooltable').data('definedcutafter') +')').css('display', 'none');
 
}
 
});
 
$('.prizepooltabletoggle').click(function() {
 
$(this).closest('table.prizepooltable').toggleClass('collapsed');
 
$(this).closest('table.prizepooltable').find('tr:nth-child(n+'+ $(this).closest('table.prizepooltable').data('definedcutafter') +')').toggle();
 
});
 
});
 
 
/*******************************************************************************
 
Template(s): Tab Templates
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
$(document).ready (function() {
 
$('div.tabs-dynamic ul.nav-tabs > li').each(
 
function () {
 
$(this).parent().parent().children('div.tabs-content').children('div:eq(' + $(this).index() + ')').prepend('<h6 style="display:none;">' + $(this).html() + '</h6>');
 
$(this).html('<a href="javascript:;">' + $(this).html() + '</a>');
 
}
 
);
 
$('div.tabs-dynamic ul.nav-tabs > li:not(.show-all)').click(
 
function () {
 
var i = $(this).index() + 1;
 
$(this).parent().children('li').removeClass('active');
 
$(this).addClass('active');
 
$(this).parent().parent().children('div.tabs-content').children('div').removeClass('active');
 
$(this).parent().parent().children('div.tabs-content').children('div.content' + i).addClass('active');
 
$(this).parent().parent().find('div.tabs-content > div > h6:first-child').hide();
 
}
 
);
 
$('div.tabs-dynamic ul.nav-tabs > li.show-all').click(
 
function () {
 
$(this).parent().children('li').removeClass('active');
 
$(this).addClass('active');
 
$(this).parent().parent().children('div.tabs-content').children('div').addClass('active');
 
$(this).parent().parent().find('div.tabs-content > div > h6:first-child').show();
 
}
 
);
 
$('div.tabs-dynamic').each(function(index) {
 
var h = $(this).children('ul.nav-tabs').children('li.active').index() + 1;
 
$(this).children('div.tabs-content').children('div.content' + h).addClass('active');
 
});
 
var hash = location.hash.slice(1);
 
if (hash.substring(0, 4) == 'tab-') {
 
var hasharr = hash.split('-scrollto-');
 
var tabno = hasharr[0].replace('tab-', '');
 
    $('div.tabs-dynamic ul.nav-tabs li').removeClass('active');
 
$('div.tabs-dynamic ul.nav-tabs li.tab' + tabno).addClass('active');
 
$('div.tabs-dynamic div.tabs-content div').removeClass('active');
 
$('div.tabs-dynamic div.tabs-content div.content' + tabno).addClass('active');
 
if (hasharr.length == 2) {
 
var scrollto = '#' + hasharr[1];
 
setTimeout(function(){$(window).scrollTop($(scrollto).offset().top)}, 500);
 
}
 
}
 
});
 
$('.tabs-dynamic .nav-tabs > li a, .matchlistslot a').attr('href', 'javascript:;');
 
 
/*******************************************************************************
 
Template(s): Toggles for templates
 
Author(s): Various, Wikipedia
 
*******************************************************************************/
 
var toggleMapListSetup = function() {
 
var btn = $('a[id^="collapseButton"]');
 
btn.each(function() {
 
var table = $(this).closest('table');
 
var m = $('.maprow', table);
 
if (m.length) {
 
m.hide(); // Collapse maps by default
 
var span = $('<span>', {
 
'class': 'mapsCollapseButton',
 
'css': {
 
'font-weight': 'normal',
 
'float': 'right',
 
'margin-right': '7px',
 
'cursor': 'pointer'
 
}
 
});
 
table.data('maps-collapsed', true);
 
var toggleMaps = function() {
 
table.find('.maprow').toggle();
 
table.data('maps-collapsed', !table.data('maps-collapsed'));
 
$(this).text(function(i, txt) {
 
return txt.replace(/\+|−/, function(a) {
 
return a === '+' ? '−' : '+';
 
});
 
});
 
};
 
var a = $('<a>+maps</a>').click(toggleMaps);
 
span.append('[', a, ']');
 
$(this).parent().after(span);
 
if (table.hasClass('uncollapsed-maps')) {
 
a.trigger('click');
 
}
 
}
 
});
 
};
 
/** Collapsible tables *********************************************************
 
*
 
* From English Wikipedia, 2008-09-15
 
*
 
*  Description: Allows tables to be collapsed, showing only the header. See
 
*              [[Wikipedia:NavFrame]].
 
*  Maintainers: [[User:R. Koot]]
 
*/
 
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;
 
$('.mapsCollapseButton', Table).hide();
 
} else {
 
for ( var i = 1; i < Rows.length; i++ ) {
 
if ( hasClass( Rows[i], "maprow" ) ) {
 
// Skip showing for this row if the maps are in collapsed state
 
if ($(Table).data('maps-collapsed')) {
 
continue;
 
}
 
}
 
Rows[i].style.display = Rows[0].style.display;
 
}
 
Button.firstChild.data = collapseCaption;
 
$('.mapsCollapseButton', Table).show();
 
}
 
}
 
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.className = "collapseButton"; //Styles are declared in Common.css
 
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++;
 
}
 
}
 
// Create [+maps] buttons after setting up the table collapse buttons,
 
// but before initial collapseTable calls
 
toggleMapListSetup();
 
for ( var i = 0;  i < tableIndex; i++ ) {
 
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
 
collapseTable( i );
 
}
 
}
 
}
 
/** Test if an element has a certain class **************************************
 
*
 
* Description: Uses regular expressions and caching for better performance.
 
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 
*/
 
var hasClass = (function () {
 
var reCache = {};
 
return function (element, className) {
 
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
 
};
 
})();
 
/** Dynamic Navigation Bars (experimental) *************************************
 
*
 
*  Description: See [[Wikipedia:NavFrame]].
 
*  Maintainers: UNMAINTAINED
 
*/
 
// set up the words in your language
 
var NavigationBarHide = '[' + collapseCaption + ']';
 
var NavigationBarShow = '[' + expandCaption + ']';
 
// shows and hides content and picture (if available) of navigation bars
 
// Parameters:
 
//    indexNavigationBar: the index of navigation bar to be toggled
 
function toggleNavigationBar(indexNavigationBar)
 
{
 
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
 
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 
if (!NavFrame || !NavToggle) {
 
return false;
 
}
 
// if shown now
 
if (NavToggle.firstChild.data == NavigationBarHide) {
 
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 
if ( hasClass( NavChild, 'NavPic' ) ) {
 
NavChild.style.display = 'none';
 
}
 
if ( hasClass( NavChild, 'NavContent') ) {
 
NavChild.style.display = 'none';
 
}
 
}
 
NavToggle.firstChild.data = NavigationBarShow;
 
// if hidden now
 
} else if (NavToggle.firstChild.data == NavigationBarShow) {
 
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 
if (hasClass(NavChild, 'NavPic')) {
 
NavChild.style.display = 'block';
 
}
 
if (hasClass(NavChild, 'NavContent')) {
 
NavChild.style.display = 'block';
 
}
 
}
 
NavToggle.firstChild.data = NavigationBarHide;
 
}
 
}
 
// adds show/hide-button to navigation bars
 
function createNavigationBarToggleButton()
 
{
 
var indexNavigationBar = 0;
 
// iterate over all < div >-elements
 
var divs = document.getElementsByTagName("div");
 
for (var i = 0; NavFrame = divs[i]; i++) {
 
// if found a navigation bar
 
if (hasClass(NavFrame, "NavFrame")) {
 
indexNavigationBar++;
 
var NavToggle = document.createElement("a");
 
NavToggle.className = 'NavToggle';
 
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
 
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
var isCollapsed = hasClass( NavFrame, "collapsed" );
 
/*
 
* Check if any children are already hidden.  This loop is here for backwards compatibility:
 
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
 
* to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
 
* the content visible without JavaScript support), the new recommended way is to add the class
 
* "collapsed" to the NavFrame itself, just like with collapsible tables.
 
*/
 
for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
 
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
 
if ( NavChild.style.display == 'none' ) {
 
isCollapsed = true;
 
}
 
}
 
}
 
if (isCollapsed) {
 
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
 
NavChild.style.display = 'none';
 
}
 
}
 
}
 
var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
 
NavToggle.appendChild(NavToggleText);
 
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
 
for(var j=0; j < NavFrame.childNodes.length; j++) {
 
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
 
NavFrame.childNodes[j].appendChild(NavToggle);
 
}
 
}
 
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
 
}
 
}
 
}
 
 
$(document).ready(function () {
 
if($('.scrollTimeline').length > 0) {
 
$('.scrollTimeline')[0].scrollLeft = $('.timeline').width();
 
}
 
});
 
$(document).ready (function() {
 
createCollapseButtons();
 
createNavigationBarToggleButton();
 
/* Force scroll to anchor, if there is one, after divs and tables are collapsed */
 
if (location.hash) {
 
var selector = location.hash.replace( /(:|\.|\[|\])/g, "\\$1" );
 
if ($(selector).length > 0)
 
$(document).scrollTop($(selector).offset().top);
 
}
 
});
 
 
/*******************************************************************************
 
Template(s): All Infoboxes
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
function positionInfobox() {
 
var infobox = $('.fo-nttax-infobox-wrapper').eq(0);
 
$('#main-content').css('min-height', infobox.outerHeight() + 10);
 
var infoboxLeft = $('.main-content').offset().left + $('.main-content').outerWidth();
 
if(infoboxLeft + infobox.outerWidth(true) < $(window).width()) {
 
infobox.addClass('popout');
 
} else {
 
infobox.removeClass('popout');
 
}
 
}
 
$(document).ready(function() {
 
positionInfobox();
 
});
 
$(window).resize(function() {
 
positionInfobox();
 
});
 
 
/*******************************************************************************
 
Template(s): Main Page
 
Author(s): FO-nTTaX
 
*******************************************************************************/
 
/* This day */
 
$(document).ready(function() {
 
var date = new Date();
 
var day = date.getDate();
 
var month = date.getMonth();
 
var monthp = (date.getMonth() + 1);
 
var months = [
 
'January',
 
'February',
 
'March',
 
'April',
 
'May',
 
'June',
 
'July',
 
'August',
 
'September',
 
'October',
 
'November',
 
'December',
 
];
 
var datestring = '(' + months[month] + ' ' + get_ordinal(day) + ')';
 
if($('#this-day-date').text() != datestring) {
 
var trivialink = mw.util.getUrl('Liquipedia:This_day/' + monthp + '/' + day);
 
var triviastring = 'Add trivia about this day <a href="' + trivialink + '" title="Liquipedia:This day/' + monthp + '/' + day + '">here</a>.';
 
var apiurl = mw.util.wikiScript('api') + '?action=parse&format=json&page=Liquipedia:This_day/' + monthp + '/' + day;
 
$.getJSON(apiurl, function(data) {
 
if(typeof data.parse != 'undefined') {
 
$('#this-day-date').text(datestring);
 
$('#this-day-trivialink').html(triviastring);
 
$('#this-day-facts').html(data.parse.text['*'].replace('<p><br />\n</p>', ''));
 
}
 
});
 
}
 
});
 
 
function get_ordinal(i) {
 
if(i == 1 || i == 21 || i == 31) {
 
return i + 'st';
 
} else if(i == 2 || i == 22) {
 
return i + 'nd';
 
} else if(i == 3 || i == 23) {
 
return i + 'rd';
 
} else {
 
return i + 'th';
 
}
 
}
 
/* Share birthdays */
 
$(document).ready(function() {
 
$('.share-birthday').css('cursor', 'pointer');
 
$('body').on('click', '.share-birthday', function() {
 
var url = 'http://wiki.teamliquid.net' + mw.config.get('wgArticlePath').replace('$1', $(this).data('page'));
 
var twitterhandlearr = $(this).data('url').replace('#!/', '').replace(']', '').split('twitter.com/');
 
twitterhandle = twitterhandlearr[twitterhandlearr.length - 1];
 
var text = 'Happy birthday, @' + twitterhandle + '!';
 
Share.twitter(url, text);
 
});
 
});
 
 
/*******************************************************************************
 
Template(s): Select all for pre elements
 
Author(s): Chapatiyaq
 
*******************************************************************************/
 
$(document).ready( function() {
 
 
$( 'pre.selectall' ).each( function() {
 
var $wrapper, $relative;
 
 
$wrapper = $( '<div class="selectall-wrapper"></div>' ).insertBefore( $(this) );
 
$(this).detach().appendTo( $wrapper );
 
 
$(this).before( $( '<a class="selectall-button" href="javascript:;">Select all</a>' ) );
 
 
$relative = $( '<div class="selectall-relative"></div>' ).insertBefore( $(this) );
 
$(this).detach().appendTo( $relative );
 
});
 
 
$( 'div.selectall-wrapper' ).on( 'blur', 'textarea.selectall-duplicate', function() {
 
$(this).remove();
 
});
 
 
$( 'a.selectall-button' ).on( 'click', function() {
 
var $wrapper = $(this).closest( 'div.selectall-wrapper' ),
 
$pre = $wrapper.find( 'pre.selectall' );
 
 
$( '<textarea>' )
 
.attr( 'readonly', true )
 
.addClass( 'selectall-duplicate' )
 
.text( $pre.text() )
 
.appendTo( $wrapper.find( 'div.selectall-relative' ) )
 
.css( {
 
'padding': $pre.css( 'padding' ),
 
'line-height': $pre.css( 'line-height' ),
 
'font-family': $pre.css( 'font-family' ),
 
'font-size': $pre.css( 'font-size' )
 
})
 
.focus().select();
 
});
 
});
 

Revision as of 18:44, 18 September 2018