/* Код открытия внешних ссылок в новой вкладке */
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 addSymbols() {
if( $( '#wpTextbox1' )[0] ) {
setTimeout(function(){
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'characters',
'page': 'symbols',
'characters': [ '▀', '▂', '▅', '▃', '▄', '␠', '', '⋠', '␗' ]
});
}, 500);
}
}
/* Код получения 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");
for (var i = 0; i < el.length; i++){
var link = el[i].getAttribute('data-title');
el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('BUY_BUTTON',{URL:document.location.href});}window.open ('" + link + "');return true;");
}
}
/* Код кнопки "Найти на бирже" ТТХ карточек */
function ttxMarketButton() {
var el = document.getElementsByClassName("ttx-marketplace-button");
var i;
for (i = 0; i < el.length; i++){
var link = el[i].getAttribute('data-title');
el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('MARKET_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() {
if (event.target.className != 'tree-item-js')
$(".tree-group-collapse").slideUp();
});
});
}
/* Код просмоторщика панорам */
var panorama, viewer;
function ttxCockpit() {
function onProgress ( event ) {
progress = event.progress.loaded / event.progress.total * 100;
document.getElementById('ttx-panorama-loading-progress-line').style.width = progress + '%';
if ( progress == 100 ) {
document.getElementById('ttx-panorama-container').style.opacity = '1';
}
}
var cockpitBtn = document.querySelector(".ttx-cockpit");
if ( cockpitBtn === null ) return;
mw.loader.load( 'https://wiki.warthunder.ru/index.php?title=MediaWiki:Panorama.js&action=raw&ctype=text/javascript' );
cockpitBtn.onclick = function( e ) {
if (typeof yaCounter48855122 != 'undefined') {
yaCounter48855122.reachGoal('COCKPIT_BUTTON',{URL:document.location.href});
}
var cockpitPopup = document.getElementById('ttx-popup');
if ( cockpitPopup === null ) {
var functionClose = function() {
$('#ttx-popup').animate({opacity: 0}, 200, function(){
$('#ttx-popup').css('display', 'none');
$('#ttx-popup-close').css('display', 'none');
$('#ttx-popup-background').fadeOut(400);
});
}
var cockpitImage = document.querySelector(".ttx-cockpit").getAttribute('data-image');
cockpitPopup = document.createElement('div');
cockpitPopup.id = 'ttx-popup';
cockpitPopup.style.cssText = 'display:none;';
cockpitPopupClose = document.createElement('span');
cockpitPopupClose.id = 'ttx-popup-close';
cockpitPopupClose.innerHTML = '✖';
cockpitPopupClose.onclick = functionClose;
cockpitPopupClose.style.cssText = 'display:none;';
cockpitPopupBackground = document.createElement('div');
cockpitPopupBackground.id = 'ttx-popup-background';
cockpitPopupBackground.onclick = functionClose;
cockpitPopupBackground.style.cssText = 'display:none;';
cockpitPanoramaContainer = document.createElement('div');
cockpitPanoramaContainer.id = 'ttx-panorama-container';
cockpitPanoramaContainer.style.opacity = '0';
cockpitPanoramaLoading = document.createElement('div');
cockpitPanoramaLoading.id = 'ttx-panorama-loading';
cockpitPanoramaLoadingText = document.createElement('span');
cockpitPanoramaLoadingText.id = 'ttx-panorama-loading-text';
cockpitPanoramaLoadingText.innerHTML = 'LOADING...';
cockpitPanoramaLoadingProgress = document.createElement('div');
cockpitPanoramaLoadingProgress.id = 'ttx-panorama-loading-progress';
cockpitPanoramaLoadingProgressLine = document.createElement('div');
cockpitPanoramaLoadingProgressLine.id = 'ttx-panorama-loading-progress-line';
cockpitPanoramaLoadingProgress.appendChild(cockpitPanoramaLoadingProgressLine);
cockpitPanoramaLoading.appendChild(cockpitPanoramaLoadingText);
cockpitPanoramaLoading.appendChild(cockpitPanoramaLoadingProgress);
cockpitPopup.appendChild(cockpitPanoramaContainer);
cockpitPopup.appendChild(cockpitPanoramaLoading);
document.querySelector(".content-area").appendChild(cockpitPopup);
document.querySelector(".content-area").appendChild(cockpitPopupClose);
document.querySelector(".content-area").appendChild(cockpitPopupBackground);
}
$('#ttx-popup-background').fadeIn(400, function(){
$('#ttx-popup').css('display', 'block').animate({opacity: 1}, 200);
$('#ttx-popup-close').css('display', 'block').animate({opacity: 1}, 200);
if (typeof panorama === 'undefined') {
panorama = new PANOLENS.ImagePanorama( cockpitImage );
panorama.addEventListener( 'progress', onProgress );
viewer = new PANOLENS.Viewer({
container: document.getElementById('ttx-panorama-container')
});
viewer.add( panorama );
viewer.tweenControlCenter( new THREE.Vector3(25000.0, 1000, 0), 0 );
}
});
}
}
/* Skin-gallery */
function skinGallery() {
var el = document.querySelectorAll(".skin_gallery .skin");
for (var i = 0; i < el.length; i++) {
var type = '';
switch ( el[i].getAttribute('data-type') ) {
case 'live':
type = 'SKIN_LIVE';
break;
case 'market':
type = 'SKIN_MARKET';
break;
default:
continue;
}
var link = el[i].getAttribute('data-link');
el[i].querySelector('.skin_img').setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('" + type + "',{URL:document.location.href});}window.open('" + link + "');return true;");
}
}
$(document).ready(function(){
externalLinks();
ttxSwichMode();
ttxCollapseBlock();
ttxBuyButton();
treeGroup();
ttxCockpit();
ttxMarketButton();
addSymbols();
skinGallery();
});