MediaWiki:Common.js — различия между версиями

Материал из War Thunder Wiki
Перейти к: навигация, поиск
Строка 126: Строка 126:
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
 
ttxZebra();
 
ttxZebra();
$('#ttx-short').css('background-color','#263238');
+
$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-short').css('color','#EEEEEE');
 
 
var cookie = getCookie("ttxCollapsed");
 
var cookie = getCookie("ttxCollapsed");
 
if (cookie != undefined && navigator.cookieEnabled){
 
if (cookie != undefined && navigator.cookieEnabled){
 
if (cookie == 0){
 
if (cookie == 0){
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
ttxZebra();
+
$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-short').css('background-color','#263238');
 
$('#ttx-short').css('color','#EEEEEE');
 
 
$('#ttx-detail').removeAttr("style");
 
$('#ttx-detail').removeAttr("style");
 
} else {
 
} else {
 
$('.ttx-table-collapse').removeClass('ttx-collapsed');
 
$('.ttx-table-collapse').removeClass('ttx-collapsed');
ttxZebra();
+
$('#ttx-detail').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-detail').css('background-color','#263238');
 
$('#ttx-detail').css('color','#EEEEEE');
 
 
$('#ttx-short').removeAttr("style");
 
$('#ttx-short').removeAttr("style");
 
}
 
}
 +
ttxZebra();
 
}
 
}
 
$('.ttx-switch-size-button').click(function() {
 
$('.ttx-switch-size-button').click(function() {
Строка 148: Строка 144:
 
  case "ttx-short":
 
  case "ttx-short":
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
 
$('.ttx-table-collapse').addClass('ttx-collapsed');
$('#ttx-short').css('background-color','#263238');
+
$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-short').css('color','#EEEEEE');
 
 
$('#ttx-detail').removeAttr("style");
 
$('#ttx-detail').removeAttr("style");
 
document.cookie = "ttxCollapsed=0; path=/; expires=0";
 
document.cookie = "ttxCollapsed=0; path=/; expires=0";
ttxZebra();
 
 
break;
 
break;
 
  case "ttx-detail":
 
  case "ttx-detail":
 
$('.ttx-table-collapse').removeClass('ttx-collapsed');
 
$('.ttx-table-collapse').removeClass('ttx-collapsed');
$('#ttx-detail').css('background-color','#263238');
+
$('#ttx-detail').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-detail').css('color','#EEEEEE');
 
 
$('#ttx-short').removeAttr("style");
 
$('#ttx-short').removeAttr("style");
 
document.cookie = "ttxCollapsed=1; path=/; expires=0";
 
document.cookie = "ttxCollapsed=1; path=/; expires=0";
ttxZebra();
 
 
break;
 
break;
 
}
 
}
 +
ttxZebra();
 
});
 
});
 
});
 
});

Версия 21:06, 5 марта 2019

/* Код открытия внешних ссылок в новой вкладке */
function externalLinks() {
	$('a').each(function() {
	  var a = new RegExp('/' + window.location.host + '/');
	  if(!a.test(this.href) && this.href != '') {
		  $(this).click(function(event) {
			  event.preventDefault();
			  event.stopPropagation();
			  window.open(this.href, '_blank');
		  });
	  }
	});
}


/* Код замены символов */
function charReplace() {
	if(!($("#content").html().indexOf('</textarea>') + 1)) {
		$('#content').find("*").each(function(indx, element){
		if (($(this).children().length == 0) && ($(this).html().search(/[▀▂▅▃▄␠]/) != -1)){
			$(this).contents().filter(function() {
				return this.nodeType === 3;
			}).replaceWith(function() {
				return this.nodeValue.replace(/([▀▂▅▃▄␠])/g,"<span style='font-family:wtfSymbols;'>$1</span>");
			});
		}
	});
	}
}

/* Код получения cookie */
function getCookie(name) {
	var matches = document.cookie.match(new RegExp(
		"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	));
	return matches ? decodeURIComponent(matches[1]) : undefined;
}

function ttxZebra() {
	$('.ttx-table-line:nth-child(odd)').css('background-color', 'inherit');

	count = 0;

	$('.ttx-table-line').each(function(){
		if (!($(this).hasClass("ttx-collapsed"))){
			if (count % 2 == 0) {
				$(this).css('background-color','#DBE0E2');
			} else {
				$(this).css('background-color','inherit');
			}
			count++;
		}
	});
}

/* Код смены режима для карточек ТТХ */
function ttxSwichMode() {
    $(document).ready(function(){
		$('.ttx-unvisible').css('display','none');
		$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
		$('.ttx-ab, .ttx-sb').css('display','none');
		ttxZebra();
		var cookie = getCookie("ttxMode");
		if (cookie != undefined && navigator.cookieEnabled){
			switch (cookie) {
				case "ab":
					$('#ttx-ab-button').css('background-color','#263238').css('color','#EEEEEE');
					$('#ttx-rb-button, #ttx-sb-button').removeAttr("style");
					$('.ttx-ab').css('display','');
					$('.ttx-not-ab').addClass('ttx-collapsed');
					$('.ttx-rb, .ttx-sb').css('display','none');
					break;
				case "rb":
					$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
					$('#ttx-ab-button, #ttx-sb-button').removeAttr("style");
					$('.ttx-rb').css('display','');
					$('.ttx-not-ab').removeClass('ttx-collapsed');
					$('.ttx-ab, .ttx-sb').css('display','none');
					break;
				case "sb":
					$('#ttx-sb-button').css('background-color','#263238').css('color','#EEEEEE');
					$('#ttx-ab-button, #ttx-rb-button').removeAttr("style");
					$('.ttx-sb').css('display','');
					$('.ttx-not-ab').removeClass('ttx-collapsed');
					$('.ttx-ab, .ttx-rb').css('display','none');
					break;
			}
			ttxZebra();
		}
        $('.ttx-switch-mode-button').click(function() {
            switch ($(this).attr('id')) {
			  case "ttx-ab-button":
				$('#ttx-ab-button').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-rb-button, #ttx-sb-button').removeAttr("style");
				$('.ttx-not-ab').addClass('ttx-collapsed');
				$('.ttx-ab').css('display','');
				$('.ttx-rb, .ttx-sb').css('display','none');
				document.cookie = "ttxMode=ab; path=/; expires=0";
				break;
			  case "ttx-rb-button":
				$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-ab-button, #ttx-sb-button').removeAttr("style");
				$('.ttx-not-ab').removeClass('ttx-collapsed');
				$('.ttx-rb').css('display','');
				$('.ttx-ab, .ttx-sb').css('display','none');
				document.cookie = "ttxMode=rb; path=/; expires=0";
				break;
			  case "ttx-sb-button":
				$('#ttx-sb-button').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-ab-button, #ttx-rb-button').removeAttr("style");
				$('.ttx-not-ab').removeClass('ttx-collapsed');
				$('.ttx-sb').css('display','');
				$('.ttx-ab, .ttx-rb').css('display','none');
				document.cookie = "ttxMode=sb; path=/; expires=0";
				break;
			}
			ttxZebra();
        });
    });
}


/* Код разворачивающихся блоков ТТХ */
function ttxCollapseBlock(){
	$(document).ready(function(){
		$('.ttx-table-collapse').addClass('ttx-collapsed');
		ttxZebra();
		$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
		var cookie = getCookie("ttxCollapsed");
		if (cookie != undefined && navigator.cookieEnabled){
			if (cookie == 0){
				$('.ttx-table-collapse').addClass('ttx-collapsed');
				$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-detail').removeAttr("style");
			} else {
				$('.ttx-table-collapse').removeClass('ttx-collapsed');
				$('#ttx-detail').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-short').removeAttr("style");
			}
			ttxZebra();
		}
		$('.ttx-switch-size-button').click(function() {
			switch ($(this).attr('id')) {
			  case "ttx-short":
				$('.ttx-table-collapse').addClass('ttx-collapsed');
				$('#ttx-short').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-detail').removeAttr("style");
				document.cookie = "ttxCollapsed=0; path=/; expires=0";
				break;
			  case "ttx-detail":
				$('.ttx-table-collapse').removeClass('ttx-collapsed');
				$('#ttx-detail').css('background-color','#263238').css('color','#EEEEEE');
				$('#ttx-short').removeAttr("style");
				document.cookie = "ttxCollapsed=1; path=/; expires=0";
				break;
			}
			ttxZebra();
		});
	});
}

/* Код кнопки "Купить" ТТХ карточек */
function ttxBuyButton() {
	var logout = document.getElementById('pt-logout');
	var el = document.getElementsByClassName("ttx-buy-button");
	var i;
	if (logout == null && getCookie('identity_name') === undefined) {
		var os = 'https://warthunder.ru/ru/free_registration?r=wiki';
		var log = '';
		if (navigator.userAgent.indexOf ('PlayStation')!= -1) os = 'https://store.playstation.com/ru-ru/product/EP4432-CUSA00182_00-WARTHUNDER000000';
		if (navigator.userAgent.indexOf ('Android')!= -1) os = 'https://play.google.com/store/apps/details?id=com.gaijinent.WarThunderCompanion';
		if (navigator.userAgent.indexOf ('iPhone')!= -1) os = 'https://itunes.apple.com/us/app/assistant-for-war-thunder/id899236988?l=ru&ls=1&mt=8';
		if (navigator.userAgent.indexOf ('iPad')!= -1) os = 'https://itunes.apple.com/us/app/assistant-for-war-thunder/id899236988?l=ru&ls=1&mt=8';
		if ((navigator.userAgent.indexOf ('Android')!= -1) || (navigator.userAgent.indexOf ('iPhone')!= -1) || (navigator.userAgent.indexOf ('iPad')!= -1)) {
			log = 'СКАЧАТЬ&nbsp;ASSISTANT';
		} else {
			log = 'СКАЧАТЬ&nbsp;ИГРУ';
		}
		for (i = 0; i < el.length; i++){
			el[i].innerHTML = log;
			el[i].setAttribute('onclick', "window.open ('" + os + "');");
		}
	} else {
		log = 'КУПИТЬ';
		for (i = 0; i < el.length; i++){
			var link = el[i].getAttribute('data-title');
			el[i].innerHTML = log;
			el[i].setAttribute('onclick', "yaCounter48855122.reachGoal('BUY_BUTTON',{URL:document.location.href}); window.open ('" + link + "'); return true;");
		}
	}
}

/* Код веток техники */
function treeGroup() {
	$(document).ready(function(){
		$('.tree-group-collapse').css('display', 'none');
		$('.tree-group-collapse').css('position', 'absolute');
		$(".tree-group").click(function (e) {
			$(".tree-group-collapse").slideUp();
			$(this).siblings(".tree-group-collapse").slideToggle("slow");
			e.stopPropagation();
		});
		$(document).on("click", "body", function(event) {
			if (event.target.className != 'tree-item-js')
				$(".tree-group-collapse").slideUp();
		});
	});
}

function ttxCockpit() {
	$(document).ready(function() {
		$('.ttx-cockpit').click(function( event ) {
			var cockpitId = $(this).attr('data-id');
			if(!($('#ttx-popup')[0])) {
				$('<div id="ttx-popup"></div><span id="ttx-popup-close">✖</span><div id="ttx-popup-overlay"></div>').prependTo('.content-area');
			}
			$("<iframe width='100%' height='100%' src='https://roundme.com/embed/" + cockpitId + "' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>").prependTo('#ttx-popup');
			$('#ttx-popup-overlay').fadeIn(400,
				function(){
					$('#ttx-popup').css('display', 'block').animate({opacity: 1}, 200); 
			});
		});
	});
	
	$(document).on("click", '#ttx-popup-close, #ttx-popup-overlay', function(){
		$('#ttx-popup').animate({opacity: 0}, 200, 
				function(){ 
					$('#ttx-popup').remove();
					$('#ttx-popup-close').css('display', 'none');
					$('#ttx-popup-overlay').fadeOut(400);
				}
			);
	});
}

function gun_go() {
	var kfbr = 1900;
	var caliber = Number( document.getElementById('gun_caliber').value );
	var mass = Number( document.getElementById('gun_mass').value );
	var speed = Number( document.getElementById('gun_speed').value );
	var tnt = Number( document.getElementById('gun_tnt').value );
	var apcbc = document.getElementById('gun_APCBC').checked;
	
	tnt = ( tnt / mass ) * 100;
	
	var kf_apcbc = ( apcbc ) ? 1 : 0.9;
	
	if ( tnt < 0.65 ) {
		knap = 1;
	} else if ( tnt < 1.6 ) {
		knap = 1 + ( tnt - 0.65 ) * ( 0.93 - 1 ) / ( 1.6 - 0.65 );
	} else if ( tnt < 2 ) {
		knap = 0.93 + ( tnt - 1.6 ) * ( 0.9 - 0.93 ) / ( 2 - 1.6 );
	} else if ( tnt < 3 ) {
		knap = 0.9 + ( tnt - 2 ) * ( 0.85 - 0.9 ) / ( 3 - 2 );
	} else if ( tnt < 4 ) {
		knap = 0.85 + ( tnt - 3 ) * ( 0.75 - 0.85 ) / ( 4 - 3 );
	} else {
		knap = 0.75;
	}
	
	document.getElementById('gun_rezult').value = ( ( ( Math.pow( speed , 1.43 ) * Math.pow( mass , 0.71 ) ) / ( Math.pow( kfbr , 1.43 ) * Math.pow( caliber / 100 , 1.07 ) ) ) * 100 * knap * kf_apcbc ).toFixed(2);
}

function gunHtml() {
if(document.getElementById('gun_test')){document.getElementById('gun_test').innerHTML = '<table cellpadding="5" style="border: 1px solid #a2a9b1;margin: 5px;width: 520px;"><tr><td style="width: 180px;">Калибр (мм):</td><td><input id="gun_caliber" type="number" style="width: 100px; height: 30px;" value="57"></td><td style="text-align: center;">Пробитие (мм):</td></tr><tr><td>Масса (кг):</td><td><input id="gun_mass" type="number" style="width: 100px; height: 30px;" value="3.14"></td><td rowspan="3"><input id="gun_rezult" type="text" style="width: 200px;height: 90px;border: 0;background: #f6f6f6;text-align: center;font-size: 40px;" disabled></td></tr><tr><td>Скорость (м/с):</td><td><input id="gun_speed" type="number" style="width: 100px; height: 30px;" value="990"></td></tr><tr><td>Масса ВВ (кг):</td><td><input id="gun_tnt" type="number" style="width: 100px; height: 30px;" value="0.1"></td></tr><tr><td><span title="Остроголовый снаряд с бронебойным наконечником и баллистическим колпачком" style="border-bottom: 1px dotted; cursor: help; white-space: nowrap">APCBC</span>:</td><td><input id="gun_APCBC" type="checkbox"></td><td><input id="gun_but" class="ttx-buy-button" type="button" value="РАССЧИТАТЬ" onclick="gun_go();" style="width: 200px; height: 30px;border:0;" value=""></td></tr></table>';}
}

function gun2_go() {
	var caliber = Number( document.getElementById('gun2_caliber').value );
	var shell_mass = Number( document.getElementById('gun2_shell_mass').value );
	var core_mass = Number( document.getElementById('gun2_core_mass').value );
	var speed = Number( document.getElementById('gun2_speed').value );
	
	var pallet_mass = shell_mass - core_mass;
	var kfbr = 3000;
	var part_pallet_mass = ( core_mass / shell_mass ) * 100;
	var kf_pallet_mass = ( part_pallet_mass > 36.0 ) ? 0.5 : 0.4;
	var calculated_mass = core_mass + ( kf_pallet_mass * pallet_mass );
	
	
	document.getElementById('gun2_rezult').value = ( ( Math.pow( speed , 1.43 ) * Math.pow( calculated_mass , 0.71 ) ) / ( Math.pow( kfbr , 1.43 ) * Math.pow( caliber / 10000 , 1.07 ) ) ).toFixed(2);
}

function gun2Html() {
if(document.getElementById('gun2_test')){document.getElementById('gun2_test').innerHTML = '<table cellpadding="5" style="border: 1px solid #a2a9b1;margin: 5px;width: 520px;"><tr><td>Калибр сердечника (мм):</td><td><input id="gun2_caliber" type="number" style="width: 100px; height: 30px;" value="28"></td><td style="text-align: center;">Пробитие (мм):</td></tr><tr><td>Масса снаряда (кг):</td><td><input id="gun2_shell_mass" type="number" style="width: 100px; height: 30px;" value="4.15"></td><td rowspan="2"><input id="gun2_rezult" type="text" style="width: 200px;height: 90px;border: 0;background: #f6f6f6;text-align: center;font-size: 40px;" disabled></td></tr><tr><td>Масса сердечника (кг):</td><td><input id="gun2_core_mass" type="number" style="width: 100px; height: 30px;" value="1.1"></td></tr><tr><td>Скорость (м/с):</td><td><input id="gun2_speed" type="number" style="width: 100px; height: 30px;" value="930"></td><td><input id="gun2_but" class="ttx-buy-button" type="button" value="РАССЧИТАТЬ" onclick="gun2_go();" style="width: 200px; height: 30px;border:0;" value=""></td></tr></table>';}
}

function gunHtmlEn() {
if(document.getElementById('gun_test_en')){document.getElementById('gun_test_en').innerHTML = '<table cellpadding="5" style="border: 1px solid #a2a9b1;margin: 5px;width: 520px;"><tr><td style="width: 180px;">Calibre (mm):</td><td><input id="gun_caliber" type="number" style="width: 100px; height: 30px;" value="57"></td><td style="text-align: center;">Armour piercing (mm):</td></tr><tr><td>Weight (kg):</td><td><input id="gun_mass" type="number" style="width: 100px; height: 30px;" value="3.14"></td><td rowspan="3"><input id="gun_rezult" type="text" style="width: 200px;height: 90px;border: 0;background: #f6f6f6;text-align: center;font-size: 40px;" disabled></td></tr><tr><td>Speed (m/s):</td><td><input id="gun_speed" type="number" style="width: 100px; height: 30px;" value="990"></td></tr><tr><td>Weight of explosive mass (kg):</td><td><input id="gun_tnt" type="number" style="width: 100px; height: 30px;" value="0.1"></td></tr><tr><td>APCBC:</td><td><input id="gun_APCBC" type="checkbox"></td><td><input id="gun_but" class="ttx-buy-button" type="button" value="CALCULATE" onclick="gun_go();" style="width: 200px; height: 30px;border:0;" value=""></td></tr></table>';}
}

function gun2HtmlEn() {
if(document.getElementById('gun2_test_en')){document.getElementById('gun2_test_en').innerHTML = '<table cellpadding="5" style="border: 1px solid #a2a9b1;margin: 5px;width: 520px;"><tr><td style="width: 180px;">Core Calibre (mm):</td><td><input id="gun2_caliber" type="number" style="width: 100px; height: 30px;" value="28"></td><td style="text-align: center;">Armour piercing (mm):</td></tr><tr><td>Shell mass (kg):</td><td><input id="gun2_shell_mass" type="number" style="width: 100px; height: 30px;" value="4.15"></td><td rowspan="2"><input id="gun2_rezult" type="text" style="width: 200px;height: 90px;border: 0;background: #f6f6f6;text-align: center;font-size: 40px;" disabled></td></tr><tr><td>Core weight (kg):</td><td><input id="gun2_core_mass" type="number" style="width: 100px; height: 30px;" value="1.1"></td></tr><tr><td>Speed (m/s):</td><td><input id="gun2_speed" type="number" style="width: 100px; height: 30px;" value="930"></td><td><input id="gun2_but" class="ttx-buy-button" type="button" value="CALCULATE" onclick="gun2_go();" style="width: 200px; height: 30px;border:0;" value=""></td></tr></table>';}
}

$(document).ready(function(){
    externalLinks();
    charReplace();
    ttxSwichMode();
    ttxCollapseBlock();
    ttxBuyButton();
    treeGroup();
    ttxCockpit();
gunHtml();
gun2Html();
gunHtmlEn();
gun2HtmlEn();
});