MediaWiki:Common.js
Nota: Depois de salvar, você terá de limpar o cache do seu navegador para ver as alterações.
- Firefox / Safari: pressione Shift enquanto clica em Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (Command-R para Mac);
- Google Chrome: pressione Ctrl-Shift-R (Command-Shift-R em um Mac)
- Internet Explorer: pressione Ctrl enquanto clica em Recarregar ou pressione Ctrl-F5;
- Opera: limpe o cache em Ferramentas → Preferências (Tools → Preferences)
/* Any JavaScript here will be loaded for all users on every page load. */
/* ----- BEGIN Jiri_Starrider's JS, please do not touch. Ask me first before editing.-----*/
function showModulesTree() {
$('.js-modules-tree').each(function(){
var $this = $(this), contentWidth, contentHeight, iframe, contentPadding;
$this.html('<div class="b-modulestree"><iframe frameborder="0" style="border-width: 0; width: 1000px; min-width: 100%; height: 695px;" src="https://armor.kiev.ua/wot/tanks/modulestree.php?l=en&vehicle=' + $.trim($(this).text()) + '"></iframe></div>');
iframe = $this.find('iframe');
contentWidth = iframe.width();
contentHeight = iframe.height();
contentPadding = parseInt(iframe.parent().css('padding-bottom'));
$this.height(contentHeight + contentPadding);
$this.data('jsp','').jScrollPane({showArrows:false, contentWidth: contentWidth, contentHeight: contentHeight});
$(window).resize(function(){
$this.data('jsp').reinitialise();
});
});
}
addOnloadHook(showModulesTree);
/* ----- END Jiri_Starrider's JS edits, feel free to edit below.-----*/
/* BEGIN n1sK's js, please leave it alone, if you really must edit it ask me first.*/
/* Collapsible tables js*/
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" ) ) {
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++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
addOnloadHook( createCollapseButtons );
var NavigationBarHide = collapseCaption;
var NavigationBarShow = expandCaption;
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
if (NavToggle.firstChild.data == NavigationBarHide) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
var divs = document.getElementsByTagName("div");
for (var i = 0; NavFrame = divs[i]; i++) {
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" );
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);
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);
}
}
}
addOnloadHook( createNavigationBarToggleButton );
var hasClass = (function() {
var reCache = {};
return function( element, className ) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/* END n1sK's js, feel free to edit below.*/
/* BEGIN SNIB's MAGIC */
function toggleSidebar() {
try {
if(document.getElementById('switcherTop').style.display == 'none')
{
var stock = document.getElementsByClassName('stock');
for (i=0;i<stock.length;i++) stock[i].style.display = 'none';
var top = document.getElementsByClassName('top');
for (i=0;i<top.length;i++) top[i].style.display = 'inline';
document.getElementById('switcherStock').style.display = 'none';
document.getElementById('switcherTop').style.display = '';
}
else
{
var stock = document.getElementsByClassName('stock');
for (i=0;i<stock.length;i++) stock[i].style.display = '';
var top = document.getElementsByClassName('top');
for (i=0;i<top.length;i++) top[i].style.display = 'none';
document.getElementById('switcherStock').style.display = '';
document.getElementById('switcherTop').style.display = 'none';
}
}catch(err){}
}
$(function() {
try{
$('#switcher').attr('onclick', 'toggleSidebar();');
}catch(err){}
});
$(function() {
var first;
first = $("#history").html();
if(first){
first = first.split(/\n/);
if(first.length == 0) {
first = null;
return;
}
for (var i = 0 ; i < first.length ; i++) {
if(first[i].substring(0,4) != '<div'){
first = first[i];
break;
}
}
if(first == null || first == '') return;
$("#history").hide();
$("#readMore").before('<div id="first">'+first+'</div>').show();
first = null;
$('#readMore').click(function(){
$("#first").remove();
$("#readMore").remove();
$("#history").show('slow');
});
}
});
var mwpanel = document.getElementById('mw-panel');
if(mwpanel) {
var appendContent = document.getElementById('appendContent');
if(appendContent) {
mwpanel.appendChild(appendContent);
}
}
/* END SNIB's MAGIC */
/* Modules tree */
function modulesBlock() {
var currentModulesBlock = 1;
var modulesBlock = [];
modulesBlock[1] = $('#modulesBlock').html();
modulesBlock[2] = false;
var vehicle = $('#codeValue').text();
$('#modulesBlockH2').append('<span id="modulesBlockChange"><div class="switcherCtrlBtn active" id="modulesBlockChange_1"><span>Tech List</span></div><div class="switcherCtrlBtn" id="modulesBlockChange_2"><span>Tech Tree</span></div></span>');
$('#modulesBlockChange .switcherCtrlBtn').click(function(){
if ($(this).hasClass('active')) return false;
currentModulesBlock = $(this).attr("id") == 'modulesBlockChange_1' ? 1 : 2;
if (modulesBlock[currentModulesBlock] == false ) {
modulesBlock[currentModulesBlock] = '<iframe frameborder="0" style="border-width: 0; width: 100%; min-width: 780px; height: 620px;" src="https://armor.kiev.ua/wot/tanks/modulestree.php?l=en&vehicle=' + vehicle + '"></iframe>';
}
$('#modulesBlock').html(modulesBlock[currentModulesBlock]);
$('#modulesBlockChange .switcherCtrlBtn').removeClass('active');
$(this).addClass('active');
return false;
});
$('.treeFrame').each(function(indx){
$(this).html('<iframe frameborder="0" style="border-width: 0; width: 100%; min-width: 1010px; height: 750px;" src="' + $(this).html() + '"></iframe>');
});
$('.modulesTreeFrame').each(function(indx){
$(this).html('<iframe frameborder="0" style="border-width: 0; width: 100%; min-width: 820px; height: 620px;" src="' + $(this).html() + '"></iframe>');
});
}
/* Popup */
function addPopupWindow() {
$('body').append(
'<div id="popupWindow"><table><tr><td style="vertical-align: middle;">'+
'<div id="popupOverlay"></div>'+
'<div id="popupWrapper">'+
'<div id="popupContent"></div>'+
'<img src="//wiki.gcdn.co/images/b/bd/Close.png" class="closeBtn">'+
'</div>'+
'</td></tr></table></div>'
);
//Закрыть попап кнопкой
$('.closeBtn').click(function(index) {
$('#popupWindow').hide();
});
//Закрыть попап фоном
$('#popupOverlay').click(function(index) {
$('#popupWindow').hide();
});
}
/* Model3DViewer */
function addModel3DViewer() {
$('.Model3DViewer').click(function(){
document.getElementById("popupContent").innerHTML = '<iframe width="'+(document.documentElement.clientWidth-150)+'px" height="'+(document.documentElement.clientHeight-150)+'px" id="Model3D" src="https://sketchfab.com/models/'+$(this).children('div.Model3D').text()+'/embed?autostart=1&preload=1" frameborder="0" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
$('#popupWrapper').show();
$('#popupWindow').show();
});
}
/* ready */
$(document).ready( function(){
modulesBlock();
addPopupWindow();
addModel3DViewer();
});
/* Modules tree end */
/* Haswell's Stuff of the new age */
/* WG.net API access, credit to OOPMan */
function populatePlayerCount() {
var games = {
"#Game_Population_WoT": "wot",
"#Game_Population_WoWP": "wowp",
"#Game_Population_WoWS": "wows",
"#Game_Population_WoTB": "wotb"
},
requests = {
"https://api.worldoftanks.com/wgn/servers/info/": "4c9d8794681a6a9045dc37acffd5a53b",
"https://api.worldoftanks.eu/wgn/servers/info/": "4c9d8794681a6a9045dc37acffd5a53b",
"https://api.worldoftanks.asia/wgn/servers/info/": "4c9d8794681a6a9045dc37acffd5a53b",
"https://api.worldoftanks.ru/wgn/servers/info/": "4c9d8794681a6a9045dc37acffd5a53b"
},
requestParameters = {
language: "en"
};
$.each(games || {}, function (selector, gameId) {
if ($(selector).length) {
$.each(requests || [], function (url, appId) {
var data = $.extend({
application_id: appId,
game: gameId
},
requestParameters || {});
$.get(url, data, function (data, textStatus, jqXHR) {
if (data.status == "ok") {
var gameDataContainer = $(selector).parents("div.wot-frame-1");
$.each(data.data[gameId] || [], function (index, server) {
var serverName = server.server;
gameDataContainer.find('tr[data-server="' + serverName + '"] .population-count-container').html(server.players_online);
});
}
});
});
}
});
}
$(document).ready(populatePlayerCount);
/* WOWS */
function tthTopStock() {
$('#toStock').click(function(){
$('#stockTTH').show();
$('#topTTH').hide();
});
$('#toTop').click(function(){
$('#stockTTH').hide();
$('#topTTH').show();
});
}
$(document).ready(tthTopStock);
/*BEGIN Cadu's functions*/
/* Switch between different divs */
function switcher() {
try{if (localStorage.o_debug_switcher == 1) {return 0;}} catch (e) {} // debug
$('.switcher').each(function () {
var sWidth = $(this).find('.sw_data-width').text();
var sHeight = $(this).find('.sw_data-height').text();
var sMenuposition = $(this).find('.sw_data-menuposition').text();
if (sWidth != "") {
$(this).find('.switcherWrap').css('width',sWidth);
$(this).find('.subSwitcher').css('width',sWidth);
}
if (sHeight != "") {
$(this).find('.switcherFrame').css('height',sHeight);
$(this).find('.subSwitcher').css('height',sHeight);
}
$(this).find('.subSwitcher:first').show();
$(this).find('.switcherControlButton:first').addClass('active');
if (sMenuposition != "") {
if (sMenuposition == 'top') {
$(this).find('.switcherControl').detach().prependTo($(this).find('.switcherWrap'));
if ($(this).find('.switcherInner.thumbinner')) {
$(this).find('.switcherControl.thumbcaption').css('padding-top',0);
}
}
else if (sMenuposition == 'left' || sMenuposition == 'right') {
var maxWidth = 0;
$(this).find('.switcherControlButton').each(function () {
var width = $(this).outerWidth();
maxWidth = Math.max(maxWidth, width);
});
maxWidth *= 3;
$(this).find('.switcherControlButton').css('width', maxWidth + 'px');
$(this).find('.switcherWrap').css({'display': 'flex', 'justify-content': 'center', 'flex-wrap': 'nowrap', 'flex-direction': (sMenuposition == 'left' ? 'row-reverse' : 'row'),});
}
}
if ($(this).find('.subSwitcherBackground a img').length) {
$(this).find('.switcherFrame').css('backgroundImage', 'url('+$(this).find('.subSwitcherBackground a img').attr('src')+')');
}
$(this).removeClass('hidden');
})
$('.switcherControlButton').click(function () {
var buttonCkickId=$(this).find('.sw_data-id').text();
$(this).parent().children('.switcherControlButton').removeClass('active'); //hurr
$(this).addClass('active');
$(this).parent().parent().find('.subSwitcher').each(function() { //durr
if(buttonCkickId == $(this).find('.sw_data-id').text()) $(this).show();
else $(this).hide();
});
});
}
function switcher_original() {
try{if (localStorage.o_debug_switcher == 1) {return 0;}} catch (e) {} // debug
$('.switcher').each(function () {
if ($(this).data('width') != undefined && $(this).data('width') != "") {
$(this).find('.switcherWrap').css('width',$(this).data('width'));
$(this).find('.subSwitcher').css('width',$(this).data('width'));
}
if ($(this).data('height') != undefined && $(this).data('height') != "") {
$(this).find('.switcherFrame').css('height',$(this).data('height'));
$(this).find('.subSwitcher').css('height',$(this).data('height'));
}
$(this).find('.subSwitcher:first').show();
$(this).find('.switcherControlButton:first').addClass('active');
if ($(this).data('menuposition') !== undefined) {
if ($(this).data('menuposition') == 'top') {
$(this).find('.switcherControl').detach().prependTo($(this).find('.switcherWrap'));
if ($(this).find('.switcherInner.thumbinner')) {
$(this).find('.switcherControl.thumbcaption').css('padding-top',0);
}
}
else if ($(this).data('menuposition') == 'left' || $(this).data('menuposition') == 'right') {
var maxWidth = 0;
$(this).find('.switcherControlButton').each(function () {
var width = $(this).outerWidth();
maxWidth = Math.max(maxWidth, width);
});
maxWidth *= 3;
$(this).find('.switcherControlButton').css('width', maxWidth + 'px');
$(this).find('.switcherWrap').css({'display': 'flex', 'justify-content': 'center', 'flex-wrap': 'nowrap', 'flex-direction': (sMenuposition == 'left' ? 'row-reverse' : 'row'),});
}
}
console.log($(this).find('.subSwitcherBackground a img').length);
if ($(this).find('.subSwitcherBackground a img').length) {
$(this).find('.switcherFrame').css('backgroundImage', 'url('+$(this).find('.subSwitcherBackground a img').attr('src')+')');
}
$(this).removeClass('hidden');
})
$('.switcherControlButton').click(function () {
var buttonCkickId=$(this).data('id');
$(this).parent().children('.switcherControlButton').removeClass('active'); //hurr
$(this).addClass('active');
$(this).parent().parent().find('.subSwitcher').each(function() { //durr
if (buttonCkickId == $(this).data('id')) {
$(this).show();
} else {
$(this).hide();
}
});
});
}
/** ready */
$(document).ready( function() {
switcher();
});
/* ready **/
$(document).ready(function() {
// Iterate over all cells within each wikitable
$('.wikitable.checkbox-table').each(function() {
var $table = $(this);
$table.find('td').each(function() {
var $cell = $(this);
var $img = $cell.find('img'); // Find img tag within the cell
// Check if the cell contains an image
if ($img.length > 0) {
var alt = $img.attr('alt'); // Get the alt attribute
// Hide the standard checkbox
$cell.find('input[type="checkbox"]').hide();
// Create a label around/on top of the image to act as the clickable area
var $label = $('<label class="checkbox-label"></label>');
$label.insertBefore($img);
$label.append($img);
// Find the hidden checkbox and associate it with the label
var $checkbox = $cell.find('input[type="checkbox"]');
$label.attr('for', $checkbox.attr('id'));
}
});
});
// Handle cell click behavior
$('.wikitable.checkbox-table td').click(function() {
var $cell = $(this);
var $checkbox = $cell.find('input[type="checkbox"]');
var isChecked = $checkbox.prop('checked');
var $table = $cell.closest('.wikitable.checkbox-table');
// Remove the "active" class from all parent divs within the same table
$table.find('.insideCheckboxTable').removeClass('active');
// Toggle the checked state of the checkbox
$checkbox.prop('checked', !isChecked);
// Print the image source filename attached to the checked checkbox into a div with class "imgname"
if (!isChecked) {
var $img = $cell.find('img');
var filename = $img.attr('alt');
// Target only the visible imgname divs (exclude those within a parent div with display: none)
$('.imgname').filter(function() {
// Check if any parent div has display: none
var $parentDivs = $(this).parents('div');
for (var i = 0; i < $parentDivs.length; i++) {
var display = window.getComputedStyle($parentDivs[i]).getPropertyValue('display');
if (display === 'none') {
return false; // Exclude if any parent div has display: none
}
}
return true; // Include if no parent div has display: none
}).text(filename); // Set the text to the filename
// Toggle the class "active" on the parent div of the label element
$cell.find('.insideCheckboxTable').addClass('active');
} else {
// If the checkbox is unchecked, clear the content of the "imgname" div
$('.imgname').empty(); // Target the div outside the table
}
// Uncheck all checkboxes within the same table (wikitable)
$table.find('input[type="checkbox"]').not($checkbox).prop('checked', false);
});
});
$(document).ready(function() {
// Iterate over all cells within each wikitable
$('.wikitable.checkbox-table td').each(function() {
var $td = $(this);
// Check if the td contains a div with class "floatnone"
var $floatNoneDiv = $td.find('.floatnone');
if ($floatNoneDiv.length > 0) {
// Add class "insideCheckboxTable" to the existing div
$floatNoneDiv.addClass('insideCheckboxTable');
}
});
});
// Function to transclude the template on the page
function transcludeTemplate(templateCall, targetElement, lang) {
// Use the MediaWiki API to parse the template call
var apiUrl = mw.config.get('wgScriptPath') + '/api.php';
var requestData = {
action: 'parse',
text: templateCall,
format: 'json',
uselang: lang // Specify the language code here
};
// Send a POST request to the API endpoint
$.post(apiUrl, requestData, function(response) {
// Check if the API request was successful
if (response && response.parse && response.parse.text) {
// Get the parsed content from the API response
var parsedContent = response.parse.text['*'];
// Append the parsed content to the target element
$(targetElement).append(parsedContent);
} else {
console.error('Error parsing template:', response);
}
});
}
// Function to process patchRenderer divs
function processPatchRenderer() {
var patchRendererDivs = document.querySelectorAll('.patchRenderer');
patchRendererDivs.forEach(function(patchRendererDiv) {
// Array to store all parameter pairs
var parameterPairs = [];
// Find all switcher divs under the patchRendererDiv
var switcherDivs = patchRendererDiv.querySelectorAll('.switcher');
switcherDivs.forEach(function(switcherDiv) {
// Find all subSwitcher divs under the switcherDiv
var subSwitcherDivs = switcherDiv.querySelectorAll('.subSwitcher');
subSwitcherDivs.forEach(function(subSwitcherDiv) {
// Find imgname and subpagename divs
var imgNameDiv = subSwitcherDiv.querySelector('.imgname');
var subpagenameDiv = subSwitcherDiv.querySelector('.subpagename');
if (imgNameDiv && subpagenameDiv) {
var imgNameContent = imgNameDiv.textContent.trim();
var subpagenameContent = subpagenameDiv.textContent.trim();
// Escape special characters in template parameters
var escapedSubpagename = mw.html.escape(subpagenameContent);
var escapedImgName = mw.html.escape(imgNameContent);
// Construct parameter pair and add to array
var parameterPair = escapedSubpagename + '#' + escapedImgName;
parameterPairs.push(parameterPair);
} else {
console.log("imgname or subpagename div not found in subSwitcher div");
}
});
});
// Construct the template call with all parameters
var lang = 'pt-br';
var templateCall = '{{WoWSPatchRenderer|' + parameterPairs.join('|') + '}}';
console.log(templateCall);
transcludeTemplate(templateCall, patchRendererDiv, lang);
});
}
// Call the function when the page is fully loaded
document.addEventListener('DOMContentLoaded', function () {
processPatchRenderer();
});
$('.b-button').on('click', function() {
$('.patchRenderer').children().not('.switcher, .l-button').remove();
processPatchRenderer();
console.log("Render end");
});
/*END of Cadu block */