Difference between revisions of "MediaWiki:Common.js"

From War Thunder Wiki
Jump to: navigation, search
 
(27 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Код открытия внешних ссылок в новой вкладке */
 
/* Код открытия внешних ссылок в новой вкладке */
 
function externalLinks() {
 
function externalLinks() {
$('a').each(function() {
+
    var links = document.getElementsByTagName('a');
  var a = new RegExp('/' + window.location.host + '/');
+
    for (var i = 0; i < links.length; i++) {
  if(!a.test(this.href) && this.href != '') {
+
        var a = new RegExp('/' + window.location.host + '/');
  $(this).click(function(event) {
+
        if( !a.test(links[i].href) && links[i].href != '' ) {
  event.preventDefault();
+
            links[i].target = '_blank';
  event.stopPropagation();
+
        }
  window.open(this.href, '_blank');
+
    }
  });
 
  }
 
});
 
 
}
 
}
  
 
+
function addSymbols() {
/* Код замены символов */
+
    if( $( '#wpTextbox1' )[0] ) {
function charReplace() {
+
        setTimeout(function(){
if(!($("#content").html().indexOf('</textarea>') + 1)) {
+
            $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
$('#content').find("*").each(function(indx, element){
+
                'section': 'characters',
if (($(this).children().length == 0) && ($(this).html().search(/[▀▂▅▃▄␠]/) != -1)){
+
                'page': 'symbols',
$(this).contents().filter(function() {
+
                'characters': [ '▀', '▂', '▅', '▃', '▄', '␠', '', '⋠', '␗', '◄', '' ]
return this.nodeType === 3;
+
            });
}).replaceWith(function() {
+
        }, 500);
return this.nodeValue.replace(/([▀▂▅▃▄␠])/g,"<span style='font-family:wtfSymbols;'>$1</span>");
+
    }
});
 
}
 
});
 
}
 
 
}
 
}
  
Line 58: Line 51:
 
     $(document).ready(function(){
 
     $(document).ready(function(){
 
$('.ttx-unvisible').css('display','none');
 
$('.ttx-unvisible').css('display','none');
$('#ttx-rb-button').css('background-color','#263238');
+
$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-rb-button').css('color','#EEEEEE');
+
$('.ttx-ab, .ttx-sb').css('display','none');
$('.ttx-ab').css('display','none');
 
$('.ttx-sb').css('display','none');
 
 
ttxZebra();
 
ttxZebra();
 
var cookie = getCookie("ttxMode");
 
var cookie = getCookie("ttxMode");
Line 67: Line 58:
 
switch (cookie) {
 
switch (cookie) {
 
case "ab":
 
case "ab":
$('#ttx-ab-button').css('background-color','#263238');
+
$('#ttx-ab-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-ab-button').css('color','#EEEEEE');
+
$('#ttx-rb-button, #ttx-sb-button').removeAttr("style");
$('#ttx-rb-button').removeAttr("style");
 
$('#ttx-sb-button').removeAttr("style");
 
 
$('.ttx-ab').css('display','');
 
$('.ttx-ab').css('display','');
 
$('.ttx-not-ab').addClass('ttx-collapsed');
 
$('.ttx-not-ab').addClass('ttx-collapsed');
$('.ttx-rb').css('display','none');
+
$('.ttx-rb, .ttx-sb').css('display','none');
$('.ttx-sb').css('display','none');
 
ttxZebra();
 
 
break;
 
break;
 
case "rb":
 
case "rb":
$('#ttx-rb-button').css('background-color','#263238');
+
$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-rb-button').css('color','#EEEEEE');
+
$('#ttx-ab-button, #ttx-sb-button').removeAttr("style");
$('#ttx-ab-button').removeAttr("style");
+
$('.ttx-rb').css('display','');
$('#ttx-sb-button').removeAttr("style");
 
$('.ttx-ab').css('display','none');
 
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
$('.ttx-rb').css('display','');
+
$('.ttx-ab, .ttx-sb').css('display','none');
$('.ttx-sb').css('display','none');
 
ttxZebra();
 
 
break;
 
break;
 
case "sb":
 
case "sb":
$('#ttx-sb-button').css('background-color','#263238');
+
$('#ttx-sb-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-sb-button').css('color','#EEEEEE');
+
$('#ttx-ab-button, #ttx-rb-button').removeAttr("style");
$('#ttx-ab-button').removeAttr("style");
+
$('.ttx-sb').css('display','');
$('#ttx-rb-button').removeAttr("style");
 
$('.ttx-ab').css('display','none');
 
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
$('.ttx-rb').css('display','none');
+
$('.ttx-ab, .ttx-rb').css('display','none');
$('.ttx-sb').css('display','');
 
ttxZebra();
 
 
break;
 
break;
 
}
 
}
 +
ttxZebra();
 
}
 
}
 
         $('.ttx-switch-mode-button').click(function() {
 
         $('.ttx-switch-mode-button').click(function() {
 
             switch ($(this).attr('id')) {
 
             switch ($(this).attr('id')) {
 
  case "ttx-ab-button":
 
  case "ttx-ab-button":
$('#ttx-ab-button').css('background-color','#263238');
+
$('#ttx-ab-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-ab-button').css('color','#EEEEEE');
+
$('#ttx-rb-button, #ttx-sb-button').removeAttr("style");
$('#ttx-rb-button').removeAttr("style");
+
$('.ttx-not-ab').addClass('ttx-collapsed');
$('#ttx-sb-button').removeAttr("style");
 
 
$('.ttx-ab').css('display','');
 
$('.ttx-ab').css('display','');
$('.ttx-not-ab').addClass('ttx-collapsed');
+
$('.ttx-rb, .ttx-sb').css('display','none');
$('.ttx-rb').css('display','none');
 
$('.ttx-sb').css('display','none');
 
 
document.cookie = "ttxMode=ab; path=/; expires=0";
 
document.cookie = "ttxMode=ab; path=/; expires=0";
ttxZebra();
 
 
break;
 
break;
 
  case "ttx-rb-button":
 
  case "ttx-rb-button":
$('#ttx-rb-button').css('background-color','#263238');
+
$('#ttx-rb-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-rb-button').css('color','#EEEEEE');
+
$('#ttx-ab-button, #ttx-sb-button').removeAttr("style");
$('#ttx-ab-button').removeAttr("style");
 
$('#ttx-sb-button').removeAttr("style");
 
$('.ttx-ab').css('display','none');
 
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
 
$('.ttx-rb').css('display','');
 
$('.ttx-rb').css('display','');
$('.ttx-sb').css('display','none');
+
$('.ttx-ab, .ttx-sb').css('display','none');
 
document.cookie = "ttxMode=rb; path=/; expires=0";
 
document.cookie = "ttxMode=rb; path=/; expires=0";
ttxZebra();
 
 
break;
 
break;
 
  case "ttx-sb-button":
 
  case "ttx-sb-button":
$('#ttx-sb-button').css('background-color','#263238');
+
$('#ttx-sb-button').css('background-color','#263238').css('color','#EEEEEE');
$('#ttx-sb-button').css('color','#EEEEEE');
+
$('#ttx-ab-button, #ttx-rb-button').removeAttr("style");
$('#ttx-ab-button').removeAttr("style");
 
$('#ttx-rb-button').removeAttr("style");
 
$('.ttx-ab').css('display','none');
 
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
 
$('.ttx-not-ab').removeClass('ttx-collapsed');
$('.ttx-rb').css('display','none');
 
 
$('.ttx-sb').css('display','');
 
$('.ttx-sb').css('display','');
 +
$('.ttx-ab, .ttx-rb').css('display','none');
 
document.cookie = "ttxMode=sb; path=/; expires=0";
 
document.cookie = "ttxMode=sb; path=/; expires=0";
ttxZebra();
 
 
break;
 
break;
 
}
 
}
 +
ttxZebra();
 
         });
 
         });
 
     });
 
     });
 
}
 
}
 +
  
 
/* Код разворачивающихся блоков ТТХ */
 
/* Код разворачивающихся блоков ТТХ */
Line 149: Line 119:
 
$('.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() {
Line 171: Line 137:
 
  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();
 
});
 
});
 
});
 
});
Line 194: Line 157:
 
var logout = document.getElementById('pt-logout');
 
var logout = document.getElementById('pt-logout');
 
var el = document.getElementsByClassName("ttx-buy-button");
 
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;
 
var i;
if (logout == null) {
+
for (i = 0; i < el.length; i++){
var os = 'https://warthunder.com/en/free_registration/?r=wiki#/';
+
var link = el[i].getAttribute('data-title');
var log = '';
+
el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('MARKET_BUTTON',{URL:document.location.href});}window.open ('" + link + "');return true;");
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 = 'DOWNLOAD ASSISTANT';
 
} else {
 
log = 'DOWNLOAD A&nbsp;GAME';
 
}
 
for (i = 0; i < el.length; i++){
 
el[i].innerHTML = log;
 
el[i].setAttribute('onclick', "window.open ('" + os + "');");
 
}
 
} else {
 
log = 'BUY';
 
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;");
 
}
 
 
}
 
}
 
}
 
}
Line 238: Line 190:
 
}
 
}
  
 +
/* Код просмоторщика панорам */
 +
var panorama, viewer;
 
function ttxCockpit() {
 
function ttxCockpit() {
$(document).ready(function() {
+
    function onProgress ( event ) {
$('.ttx-cockpit').click(function( event ) {
+
        progress = event.progress.loaded / event.progress.total * 100;
var cockpitId = $(this).attr('data-id');
+
        document.getElementById('ttx-panorama-loading-progress-line').style.width = progress + '%';
if(!($('#ttx-popup')[0])) {
+
        if ( progress == 100 ) {
$('<div id="ttx-popup"></div><span id="ttx-popup-close"></span><div id="ttx-popup-overlay"></div>').prependTo('.content-area');
+
            document.getElementById('ttx-panorama-container').style.opacity = '1';
}
+
        }
$("<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(){
+
    var cockpitBtn = document.querySelector(".ttx-cockpit");
$('#ttx-popup').css('display', 'block').animate({opacity: 1}, 200);  
+
    if ( cockpitBtn === null ) return;
});
+
   
});
+
    mw.loader.load( '/index.php?title=MediaWiki:Panorama.js&action=raw&ctype=text/javascript' );
});
+
    cockpitBtn.onclick = function( e ) {        
+
        if (typeof yaCounter48855122 != 'undefined') {
$(document).on("click", '#ttx-popup-close, #ttx-popup-overlay', function(){
+
            yaCounter48855122.reachGoal('COCKPIT_BUTTON',{URL:document.location.href});
$('#ttx-popup').animate({opacity: 0}, 200,  
+
        }
function(){  
+
       
$('#ttx-popup').remove();
+
        var cockpitPopup = document.getElementById('ttx-popup');
$('#ttx-popup-close').css('display', 'none');
+
        if ( cockpitPopup === null ) {
$('#ttx-popup-overlay').fadeOut(400);
+
            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;");
 +
    }
 +
}
 +
 
 +
function specsSlider() {
 +
    if( document.querySelector( '.specs_card_main_slider' ) ) {
 +
        var node = document.querySelector( '.specs_card_main_slider_container' );
 +
       
 +
        var imgArr = document.querySelectorAll( '.specs_card_main_slider_system div' );
 +
       
 +
        if ( imgArr.length < 1 ) {
 +
            return;
 +
        }
 +
       
 +
        var labels_container = document.createElement('div');
 +
        labels_container.className = 'labels_container';
 +
       
 +
        var labels = document.createElement('div');
 +
        labels.className = 'labels';
 +
       
 +
        var functionSelect = function(e) {
 +
            document.querySelector('.specs_card_main_slider .labels label.checked').classList.remove('checked');
 +
            var checked_id = document.querySelector('.specs_card_main_slider_container input:checked').id;
 +
            document.querySelector('.specs_card_main_slider label[for=' + checked_id + ']').classList.add('checked');
 +
        };
 +
       
 +
        var addLinkImg = function( elem, node, labelList, index ) {
 +
            var input = document.createElement('input');
 +
            input.type = 'radio';
 +
            input.name = 'slider';
 +
            input.id = 'slider_input_' + String(index);
 +
            input.onchange = functionSelect;
 +
           
 +
            var img = document.createElement('div');
 +
            img.className = 'slide';
 +
            img.appendChild( elem );
 +
           
 +
            var label = document.createElement('label');
 +
            label.htmlFor = 'slider_input_' + String(index);
 +
            label.id = 'label_' + String(index);
 +
            if ( labelList.childElementCount === 0 ) {
 +
                label.className = 'checked';
 +
                input.checked = true;
 +
                input.autofocus = true;
 +
            } else if ( labelList.childElementCount === 1 ) {
 +
                label.className = 'checked';
 +
                input.checked = true;
 +
                input.autofocus = true;
 +
                labelList.querySelector('#label_0').className = '';
 +
            }
 +
 
 +
 
 +
            node.appendChild(input);
 +
            node.appendChild(img);
 +
           
 +
            labelList.appendChild(label);
 +
        };
 +
       
 +
        var addImg = function( lnk, node, labelList, index ) {
 +
            var input = document.createElement('input');
 +
            input.type = 'radio';
 +
            input.name = 'slider';
 +
            input.id = 'slider_input_' + String(index);
 +
            input.onchange = functionSelect;
 +
           
 +
            var img = document.createElement('div');
 +
            img.style.backgroundImage = 'url(' + String(lnk)  + ')';
 +
            img.className = 'slide';
 +
           
 +
            var label = document.createElement('label');
 +
            label.htmlFor = 'slider_input_' + String(index);
 +
            label.id = 'label_' + String(index);
 +
            if ( labelList.childElementCount === 0 ) {
 +
                label.className = 'checked';
 +
                input.checked = true;
 +
                input.autofocus = true;
 +
            } else if ( labelList.childElementCount === 1 ) {
 +
                label.className = 'checked';
 +
                input.checked = true;
 +
                input.autofocus = true;
 +
                labelList.querySelector('#label_0').className = '';
 +
            }
 +
 
 +
 
 +
            node.appendChild(input);
 +
            node.appendChild(img);
 +
           
 +
            labelList.appendChild(label);
 +
        };
 +
       
 +
        var add360 = function( lnk, node, labelList, index ) {
 +
            function onProgress ( e ) {
 +
                progress = e.progress.loaded / e.progress.total * 100;
 +
                e.target.container.parentElement.querySelector('.specs_360_loading_progress_line').style.width = progress + '%';
 +
                if ( progress == 100 ) {
 +
                    e.target.container.parentElement.querySelector('.specs_360_loading').style.opacity = '0';
 +
                }
 +
            }
 +
           
 +
            jQuery.getScript( '/index.php?title=MediaWiki:Panorama.js&action=raw&ctype=text/javascript' ).done(function( script, textStatus ) {
 +
                var input = document.createElement('input');
 +
                input.type = 'radio';
 +
                input.name = 'slider';
 +
                input.id = 'slider_input_' + String(index);
 +
                if ( labelList.childElementCount === 0 ) {
 +
                    input.checked = true;
 +
                    input.autofocus = true;
 +
                }
 +
                input.onchange = functionSelect;
 +
               
 +
                var div = document.createElement('div');
 +
                div.className = 'slide';
 +
               
 +
                var container360 = document.createElement('div');
 +
                container360.style.width = '100%';
 +
                container360.style.height = '100%';
 +
                container360.id = 'specs_360_container_' + String(index);
 +
                container360.allowFullscreen = true;
 +
                container360.frameBorder = '0';
 +
                container360.setAttribute('mozallowfullscreen', true);
 +
                container360.setAttribute('webkitallowfullscreen', true);
 +
                container360.setAttribute('data-link', lnk);
 +
               
 +
                container360Loading = document.createElement('div');
 +
                container360Loading.className = 'specs_360_loading';
 +
               
 +
                container360LoadingText = document.createElement('span');
 +
                container360LoadingText.className = 'specs_360_loading_text ';
 +
                container360LoadingText.innerHTML = 'LOADING...';
 +
               
 +
                container360LoadingProgress = document.createElement('div');
 +
                container360LoadingProgress.className = 'specs_360_loading_progress';
 +
               
 +
                container360LoadingProgressLine = document.createElement('div');
 +
                container360LoadingProgressLine.className = 'specs_360_loading_progress_line';
 +
               
 +
                container360LoadingProgress.appendChild(container360LoadingProgressLine);
 +
                container360Loading.appendChild(container360LoadingText);
 +
                container360Loading.appendChild(container360LoadingProgress);
 +
               
 +
                div.appendChild(container360);
 +
               
 +
                div.appendChild(container360Loading);
 +
               
 +
                var label = document.createElement('label');
 +
                label.htmlFor = 'slider_input_' + String(index);
 +
                label.id = 'label_' + String(index);
 +
                label.className = 'label360';
 +
                label.onclick = function( e ) {
 +
                    var elem_id = e.target.id.replace('label_', '');
 +
                    var container_360 = document.getElementById('specs_360_container_' + elem_id);
 +
                    if ( container_360.innerHTML != '' ) {
 +
                        return;
 +
                    }
 +
                   
 +
                    if (typeof yaCounter48855122 != 'undefined') {
 +
                        yaCounter48855122.reachGoal('COCKPIT_BUTTON',{URL:document.location.href});
 +
                    }
 +
                   
 +
                    var panorama, viewer;
 +
                    panorama = new PANOLENS.ImagePanorama( container_360.getAttribute('data-link') );
 +
                    panorama.addEventListener( 'progress', onProgress );
 +
                    viewer = new PANOLENS.Viewer({
 +
                        container: container_360
 +
                    });
 +
                    viewer.add( panorama );
 +
                    viewer.tweenControlCenter( new THREE.Vector3(25000.0, 1000, 0), 0 );
 +
                };
 +
               
 +
                node.appendChild(input);
 +
                node.appendChild(div);
 +
               
 +
                labelList.appendChild(label);
 +
            });
 +
        }
 +
       
 +
        for ( var i = 0; i < imgArr.length; i++ ) {
 +
            var item = imgArr[i];
 +
           
 +
            if (
 +
                item.childElementCount == 1
 +
            ) {
 +
                if ( item.children[0].tagName == 'IMG' ) {
 +
                    addImg( item.children[0].src, node, labels, i );
 +
                } else if (
 +
                    item.children[0].tagName == 'A' &&
 +
                    item.children[0].childElementCount == 1 &&
 +
                    item.children[0].children[0].tagName == 'IMG'
 +
                ) {
 +
                    addLinkImg( item.children[0], node, labels, i );
 +
                }
 +
            } else {
 +
                var match = item.innerText.match(/([a-z0-9]*)\:\/\/(.*)\n?/);
 +
                var protocol = match[1];
 +
               
 +
                switch ( protocol ) {
 +
                    case '360':
 +
                        add360( match[2], node, labels, i );
 +
                        break;
 +
                }
 +
            }
 +
        }
 +
       
 +
        labels_container.appendChild( labels );
 +
       
 +
        node.appendChild( labels_container );
 +
        document.querySelector( '.specs_card_main_slider_system' ).remove();
 +
    }
 +
}
 +
 
 +
/* Код кнопки "Купить" ТТХ карточек */
 +
function specsBuyButton() {
 +
    var el = document.getElementsByClassName("general_info_buy_button");
 +
    for (var i = 0; i < el.length; i++){
 +
        var link = 'https://store.gaijin.net/story.php?id=' + el[i].getAttribute('data-link') + '&partner=Wiki&partner_val=mufby3bs';
 +
        el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('BUY_BUTTON',{URL:document.location.href});}window.open('" + link + "');return true;");
 +
    }
 +
}
 +
 
 +
/* Код кнопки "Найти на бирже" ТТХ карточек */
 +
function specsMarketButton() {
 +
    var el = document.getElementsByClassName("general_info_market_button");
 +
    for (var i = 0; i < el.length; i++){
 +
        var link = 'https://trade.gaijin.net/?n=' + el[i].getAttribute('data-link') + '&viewitem=&a=1067';
 +
        el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('MARKET_BUTTON',{URL:document.location.href});}window.open('" + link + "');return true;");
 +
    }
 +
}
 +
 
 +
function specsOpenInGame() {
 +
    var logout = document.getElementById('pt-logout');
 +
    if ( logout == null ) {
 +
        var login_link = document.querySelector('#pt-login a').href;
 +
        var popup_html = '<div class="ogp_popup_container"><div class="ogp_popup_center"><div class="ogp_popup"><div class="ogp_close" onclick="closeOgpPopup();"></div><div class="ogp_logo"><a href="https://warthunder.ru" target="_blank"><img src="https://wiki.warthunder.com/images/9/9d/Ogp_logo.png"></a></div><div class="ogp_block desc"><img src="https://wiki.warthunder.com/images/9/91/Msg-info.png"><span>How to view the vehicle in the game:</span></div><div class="ogp_divider"></div><div class="ogp_block user"><div><b>Already have a Gaijin account?</b></div><div><ol><li><a href="' + login_link + '">Log in</a> on Wiki</li><li>Log in with the same account in War Thunder</li></ol></div></div><div class="ogp_divider"></div><div class="ogp_block"><div><b>Not registered in War Thunder?</b></div><div>More than 1,800 tanks, aircraft, helicopters and ships are waiting in the game!</div><div class="ogp_button">REGISTER</div></div></div></div></div><div class="ogp_background" onclick="closeOgpPopup();"></div>';
 +
        var el = document.querySelectorAll('.general_info_game_button');
 +
        for (var i = 0; i < el.length; i++){
 +
            el[i].onclick = function(e) {
 +
                var divc = document.createElement('div');
 +
                divc.innerHTML = popup_html;
 +
                document.querySelector('.content-area').appendChild(divc);
 +
                document.querySelector('.ogp_button').onclick = function() {
 +
                    if (typeof yaCounter48855122 != 'undefined') {
 +
                        yaCounter48855122.reachGoal('OIG_REG',{URL:document.location.href});
 +
                    }
 +
                    window.open('https://warthunder.com/en/play4free?r=wiki#');
 +
                }
 +
            };
 +
        }
 +
    } else {
 +
        var el = document.querySelectorAll('.general_info_game_button');
 +
        for (var i = 0; i < el.length; i++){
 +
            el[i].onclick = function(e) {
 +
                var xhr = new XMLHttpRequest();
 +
                var unit_id = document.querySelector('.specs_card_main').getAttribute('data-code');
 +
                if (typeof yaCounter48855122 != 'undefined') {
 +
                    yaCounter48855122.reachGoal('OIG_SHOW',{URL:document.location.href,CODE:unit_id});
 +
                }
 +
                xhr.open('GET', '/Special:GameObjectView?object_id=' + unit_id, false);
 +
                xhr.send();
 +
 
 +
                try {
 +
                    var msg_container = document.querySelector('.general_info_message');
 +
                    if (xhr.status != 200) {
 +
                        msg_container.innerText = 'Refresh the page or try again later';
 +
                        msg_container.classList.remove('ok');
 +
                        msg_container.classList.add('error');
 +
                    } else {
 +
                        var response = JSON.parse(xhr.responseText);
 +
                        if (response.status == 200) {
 +
                            if ( response.details.status == 'failed' ) {
 +
                                if ( response.details.error == 'SERVER_ERROR_INTERNAL' ) {
 +
                                    msg_container.innerText = 'The game is not running or is running not under the current account';
 +
                                    msg_container.classList.remove('ok');
 +
                                    msg_container.classList.add('error');
 +
                                } else {
 +
                                    msg_container.innerText = 'Refresh the page or try again later';
 +
                                    msg_container.classList.remove('ok');
 +
                                    msg_container.classList.add('error');
 +
                                }
 +
                            } else if ( response.details.status == 'ERROR' ) {
 +
                                xhr.open('GET', '/api.php?action=logout', false);
 +
                                xhr.send();
 +
                               
 +
                                msg_container.innerText = 'Re-log in to the WIKI (click "Log out" and log in again)';
 +
                                msg_container.classList.remove('ok');
 +
                                msg_container.classList.add('error');
 +
                            } else if ( response.details.status == 'ok' ) {
 +
                                if ( response.details.reply.result == 'unit_not_found' ) {
 +
                                    msg_container.innerText = 'The vehicle was not found. Refresh the page or try again later';
 +
                                    msg_container.classList.remove('ok');
 +
                                    msg_container.classList.add('error');
 +
                                } else if ( response.details.reply.result == 'success' ) {
 +
                                    msg_container.innerText = 'The vehicle is shown in the game window!';
 +
                                    msg_container.classList.remove('error');
 +
                                    msg_container.classList.add('ok');
 +
                                } else {
 +
                                    msg_container.innerText = 'Refresh the page or try again later';
 +
                                    msg_container.classList.remove('ok');
 +
                                    msg_container.classList.add('error');
 +
                                }
 +
                            } else {
 +
                                msg_container.innerText = 'Refresh the page or try again later';
 +
                                msg_container.classList.remove('ok');
 +
                                msg_container.classList.add('error');
 +
                            }
 +
                        } else if (response.status == 403) {
 +
                            msg_container.innerText = 'Re-log in to the WIKI (click "Log out" and log in again)';
 +
                            msg_container.classList.remove('ok');
 +
                            msg_container.classList.add('error');
 +
                        } else {
 +
                            msg_container.innerText = 'Refresh the page or try again later';
 +
                            msg_container.classList.remove('ok');
 +
                            msg_container.classList.add('error');
 +
                        }
 +
                    }
 +
                } catch (e) {
 +
                    msg_container.innerText = 'Refresh the page or try again later';
 +
                    msg_container.classList.remove('ok');
 +
                    msg_container.classList.add('error');
 +
                }
 +
            };
 +
        }
 +
    }
 +
}
 +
 
 +
function closeOgpPopup() {
 +
    document.querySelector('.ogp_popup_container').remove();
 +
    document.querySelector('.ogp_background').remove();
 +
}
 +
 
 +
function specsOpenSlider() {
 +
    var sliderList = document.querySelectorAll('.specs_slider');
 +
   
 +
    for ( var i = 0; i < sliderList.length; i++ ) {
 +
        var title_elem = sliderList[i].querySelector('.specs_slider_title');
 +
        if ( title_elem ) {
 +
            title_elem.onclick = function( e ) {
 +
                e.target.parentElement.classList.toggle('open');
 +
            }
 +
        }
 +
    }
 +
}
 +
 
 +
function specsShowMod() {
 +
    var modsList = document.querySelectorAll('.specs_mod:not(.view)');
 +
    if ( modsList.length == 0 ) {
 +
        return;
 +
    }
 +
   
 +
    var hideMods = function() {
 +
        var modsOpenList = document.querySelector('.specs_mod.view');
 +
        modsOpenList.classList.add('hide');
 +
    }
 +
   
 +
    document.addEventListener('click', function( e ) {
 +
        if (
 +
            e.target.classList.contains('specs_mod') ||
 +
            e.target.parentElement.classList.contains('specs_mod')
 +
        ) {
 +
            return;
 +
        }
 +
       
 +
        hideMods();
 +
    });
 +
   
 +
    document.querySelector('.specs_slider_container').addEventListener('scroll', hideMods);
 +
   
 +
    var openMod = function( e ) {
 +
        var view_container = document.querySelector('.specs_mod.view');
 +
        var view_pos = document.querySelector('.specs_mods').parentElement.getBoundingClientRect();
 +
        var pos = e.target.offsetParent.getBoundingClientRect();
 +
        view_container.style.left = (pos.x - view_pos.x - 26) + "px";
 +
        view_container.style.top = (pos.y - view_pos.y - 12) + "px";
 +
        view_container.innerHTML = e.target.innerHTML;
 +
        view_container.classList.remove('hide');
 +
    }
 +
   
 +
    for ( var i = 0; i < modsList.length; i++ ) {
 +
        modsList[i].onclick = openMod;
 +
    }
 
}
 
}
  
$(document).ready(function(){
+
function wikiSetup() {
 +
    treeGroup();
 
     externalLinks();
 
     externalLinks();
     charReplace();
+
     addSymbols();
 +
    skinGallery();
 +
 
 
     ttxSwichMode();
 
     ttxSwichMode();
 
     ttxCollapseBlock();
 
     ttxCollapseBlock();
 
     ttxBuyButton();
 
     ttxBuyButton();
    treeGroup();
 
 
     ttxCockpit();
 
     ttxCockpit();
});
+
    ttxMarketButton();
 +
 
 +
    specsSlider();
 +
    specsBuyButton();
 +
    specsMarketButton();
 +
    specsOpenInGame();
 +
    specsShowMod();
 +
    specsOpenSlider();
 +
 
 +
if (navigator.userAgent && navigator.userAgent.indexOf('Valve Steam GameOverlay')) {
 +
    var searchParams = new URLSearchParams(window.location.search);
 +
    if (searchParams.get('from') === 'client') {
 +
        searchParams.set("from", "steamOverlayReturn");
 +
        var newRelativePathQuery = window.location.pathname + '?' + searchParams.toString();
 +
        history.pushState(null, '', newRelativePathQuery);
 +
    }
 +
}
 +
}
 +
 
 +
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
 +
    wikiSetup();
 +
} else {
 +
    document.addEventListener('DOMContentLoaded', wikiSetup);
 +
}

Latest revision as of 11:58, 26 July 2023

/* Код открытия внешних ссылок в новой вкладке */
function externalLinks() {
    var links = document.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        var a = new RegExp('/' + window.location.host + '/');
        if( !a.test(links[i].href) && links[i].href != '' ) {
            links[i].target = '_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( '/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;");
    }
}

function specsSlider() {
    if( document.querySelector( '.specs_card_main_slider' ) ) {
        var node = document.querySelector( '.specs_card_main_slider_container' );
        
        var imgArr = document.querySelectorAll( '.specs_card_main_slider_system div' );
        
        if ( imgArr.length < 1 ) {
            return;
        }
        
        var labels_container = document.createElement('div');
        labels_container.className = 'labels_container';
        
        var labels = document.createElement('div');
        labels.className = 'labels';
        
        var functionSelect = function(e) {
            document.querySelector('.specs_card_main_slider .labels label.checked').classList.remove('checked');
            var checked_id = document.querySelector('.specs_card_main_slider_container input:checked').id;
            document.querySelector('.specs_card_main_slider label[for=' + checked_id + ']').classList.add('checked');
        };
        
        var addLinkImg = function( elem, node, labelList, index ) {
            var input = document.createElement('input');
            input.type = 'radio';
            input.name = 'slider';
            input.id = 'slider_input_' + String(index);
            input.onchange = functionSelect;
            
            var img = document.createElement('div');
            img.className = 'slide';
            img.appendChild( elem );
            
            var label = document.createElement('label');
            label.htmlFor = 'slider_input_' + String(index);
            label.id = 'label_' + String(index);
            if ( labelList.childElementCount === 0 ) {
                label.className = 'checked';
                input.checked = true;
                input.autofocus = true;
            } else if ( labelList.childElementCount === 1 ) {
                label.className = 'checked';
                input.checked = true;
                input.autofocus = true;
                labelList.querySelector('#label_0').className = '';
            }


            node.appendChild(input);
            node.appendChild(img);
            
            labelList.appendChild(label);
        };
        
        var addImg = function( lnk, node, labelList, index ) {
            var input = document.createElement('input');
            input.type = 'radio';
            input.name = 'slider';
            input.id = 'slider_input_' + String(index);
            input.onchange = functionSelect;
            
            var img = document.createElement('div');
            img.style.backgroundImage = 'url(' + String(lnk)  + ')';
            img.className = 'slide';
            
            var label = document.createElement('label');
            label.htmlFor = 'slider_input_' + String(index);
            label.id = 'label_' + String(index);
            if ( labelList.childElementCount === 0 ) {
                label.className = 'checked';
                input.checked = true;
                input.autofocus = true;
            } else if ( labelList.childElementCount === 1 ) {
                label.className = 'checked';
                input.checked = true;
                input.autofocus = true;
                labelList.querySelector('#label_0').className = '';
            }


            node.appendChild(input);
            node.appendChild(img);
            
            labelList.appendChild(label);
        };
        
        var add360 = function( lnk, node, labelList, index ) {
            function onProgress ( e ) {
                progress = e.progress.loaded / e.progress.total * 100;
                e.target.container.parentElement.querySelector('.specs_360_loading_progress_line').style.width = progress + '%';
                if ( progress == 100 ) {
                    e.target.container.parentElement.querySelector('.specs_360_loading').style.opacity = '0';
                }
            }
            
            jQuery.getScript( '/index.php?title=MediaWiki:Panorama.js&action=raw&ctype=text/javascript' ).done(function( script, textStatus ) {
                var input = document.createElement('input');
                input.type = 'radio';
                input.name = 'slider';
                input.id = 'slider_input_' + String(index);
                if ( labelList.childElementCount === 0 ) {
                    input.checked = true;
                    input.autofocus = true;
                }
                input.onchange = functionSelect;
                
                var div = document.createElement('div');
                div.className = 'slide';
                
                var container360 = document.createElement('div');
                container360.style.width = '100%';
                container360.style.height = '100%';
                container360.id = 'specs_360_container_' + String(index);
                container360.allowFullscreen = true;
                container360.frameBorder = '0';
                container360.setAttribute('mozallowfullscreen', true);
                container360.setAttribute('webkitallowfullscreen', true);
                container360.setAttribute('data-link', lnk);
                
                container360Loading = document.createElement('div');
                container360Loading.className = 'specs_360_loading';
                
                container360LoadingText = document.createElement('span');
                container360LoadingText.className = 'specs_360_loading_text ';
                container360LoadingText.innerHTML = 'LOADING...';
                
                container360LoadingProgress = document.createElement('div');
                container360LoadingProgress.className = 'specs_360_loading_progress';
                
                container360LoadingProgressLine = document.createElement('div');
                container360LoadingProgressLine.className = 'specs_360_loading_progress_line';
                
                container360LoadingProgress.appendChild(container360LoadingProgressLine);
                container360Loading.appendChild(container360LoadingText);
                container360Loading.appendChild(container360LoadingProgress);
                
                div.appendChild(container360);
                
                div.appendChild(container360Loading);
                
                var label = document.createElement('label');
                label.htmlFor = 'slider_input_' + String(index);
                label.id = 'label_' + String(index);
                label.className = 'label360';
                label.onclick = function( e ) {
                    var elem_id = e.target.id.replace('label_', '');
                    var container_360 = document.getElementById('specs_360_container_' + elem_id);
                    if ( container_360.innerHTML != '' ) {
                        return;
                    }
                    
                    if (typeof yaCounter48855122 != 'undefined') {
                        yaCounter48855122.reachGoal('COCKPIT_BUTTON',{URL:document.location.href});
                    }
                    
                    var panorama, viewer;
                    panorama = new PANOLENS.ImagePanorama( container_360.getAttribute('data-link') );
                    panorama.addEventListener( 'progress', onProgress );
                    viewer = new PANOLENS.Viewer({
                        container: container_360
                    });
                    viewer.add( panorama );
                    viewer.tweenControlCenter( new THREE.Vector3(25000.0, 1000, 0), 0 );
                };
                
                node.appendChild(input);
                node.appendChild(div);
                
                labelList.appendChild(label);
            });
        }
        
        for ( var i = 0; i < imgArr.length; i++ ) {
            var item = imgArr[i];
            
            if ( 
                item.childElementCount == 1
            ) {
                if ( item.children[0].tagName == 'IMG' ) {
                    addImg( item.children[0].src, node, labels, i );
                } else if (
                    item.children[0].tagName == 'A' &&
                    item.children[0].childElementCount == 1 &&
                    item.children[0].children[0].tagName == 'IMG'
                ) {
                    addLinkImg( item.children[0], node, labels, i );
                }
            } else {
                var match = item.innerText.match(/([a-z0-9]*)\:\/\/(.*)\n?/);
                var protocol = match[1];
                
                switch ( protocol ) {
                    case '360':
                        add360( match[2], node, labels, i );
                        break;
                }
            }
        }
        
        labels_container.appendChild( labels );
        
        node.appendChild( labels_container );
        document.querySelector( '.specs_card_main_slider_system' ).remove();
    }
}

/* Код кнопки "Купить" ТТХ карточек */
function specsBuyButton() {
    var el = document.getElementsByClassName("general_info_buy_button");
    for (var i = 0; i < el.length; i++){
        var link = 'https://store.gaijin.net/story.php?id=' + el[i].getAttribute('data-link') + '&partner=Wiki&partner_val=mufby3bs';
        el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('BUY_BUTTON',{URL:document.location.href});}window.open('" + link + "');return true;");
    }
}

/* Код кнопки "Найти на бирже" ТТХ карточек */
function specsMarketButton() {
    var el = document.getElementsByClassName("general_info_market_button");
    for (var i = 0; i < el.length; i++){
        var link = 'https://trade.gaijin.net/?n=' + el[i].getAttribute('data-link') + '&viewitem=&a=1067';
        el[i].setAttribute('onclick', "if(typeof yaCounter48855122 != 'undefined'){yaCounter48855122.reachGoal('MARKET_BUTTON',{URL:document.location.href});}window.open('" + link + "');return true;");
    }
}

function specsOpenInGame() {
    var logout = document.getElementById('pt-logout');
    if ( logout == null ) {
        var login_link = document.querySelector('#pt-login a').href;
        var popup_html = '<div class="ogp_popup_container"><div class="ogp_popup_center"><div class="ogp_popup"><div class="ogp_close" onclick="closeOgpPopup();"></div><div class="ogp_logo"><a href="https://warthunder.ru" target="_blank"><img src="https://wiki.warthunder.com/images/9/9d/Ogp_logo.png"></a></div><div class="ogp_block desc"><img src="https://wiki.warthunder.com/images/9/91/Msg-info.png"><span>How to view the vehicle in the game:</span></div><div class="ogp_divider"></div><div class="ogp_block user"><div><b>Already have a Gaijin account?</b></div><div><ol><li><a href="' + login_link + '">Log in</a> on Wiki</li><li>Log in with the same account in War Thunder</li></ol></div></div><div class="ogp_divider"></div><div class="ogp_block"><div><b>Not registered in War Thunder?</b></div><div>More than 1,800 tanks, aircraft, helicopters and ships are waiting in the game!</div><div class="ogp_button">REGISTER</div></div></div></div></div><div class="ogp_background" onclick="closeOgpPopup();"></div>';
        var el = document.querySelectorAll('.general_info_game_button');
        for (var i = 0; i < el.length; i++){
            el[i].onclick = function(e) {
                var divc = document.createElement('div');
                divc.innerHTML = popup_html;
                document.querySelector('.content-area').appendChild(divc);
                document.querySelector('.ogp_button').onclick = function() {
                    if (typeof yaCounter48855122 != 'undefined') {
                        yaCounter48855122.reachGoal('OIG_REG',{URL:document.location.href});
                    }
                    window.open('https://warthunder.com/en/play4free?r=wiki#');
                }
            };
        }
    } else {
        var el = document.querySelectorAll('.general_info_game_button');
        for (var i = 0; i < el.length; i++){
            el[i].onclick = function(e) {
                var xhr = new XMLHttpRequest();
                var unit_id = document.querySelector('.specs_card_main').getAttribute('data-code');
                if (typeof yaCounter48855122 != 'undefined') {
                    yaCounter48855122.reachGoal('OIG_SHOW',{URL:document.location.href,CODE:unit_id});
                }
                xhr.open('GET', '/Special:GameObjectView?object_id=' + unit_id, false);
                xhr.send();

                try {
                    var msg_container = document.querySelector('.general_info_message');
                    if (xhr.status != 200) {
                        msg_container.innerText = 'Refresh the page or try again later';
                        msg_container.classList.remove('ok');
                        msg_container.classList.add('error');
                    } else {
                        var response = JSON.parse(xhr.responseText);
                        if (response.status == 200) {
                            if ( response.details.status == 'failed' ) {
                                if ( response.details.error == 'SERVER_ERROR_INTERNAL' ) {
                                    msg_container.innerText = 'The game is not running or is running not under the current account';
                                    msg_container.classList.remove('ok');
                                    msg_container.classList.add('error');
                                } else {
                                    msg_container.innerText = 'Refresh the page or try again later';
                                    msg_container.classList.remove('ok');
                                    msg_container.classList.add('error');
                                }
                            } else if ( response.details.status == 'ERROR' ) {
                                xhr.open('GET', '/api.php?action=logout', false);
                                xhr.send();
                                
                                msg_container.innerText = 'Re-log in to the WIKI (click "Log out" and log in again)';
                                msg_container.classList.remove('ok');
                                msg_container.classList.add('error');
                            } else if ( response.details.status == 'ok' ) {
                                if ( response.details.reply.result == 'unit_not_found' ) {
                                    msg_container.innerText = 'The vehicle was not found. Refresh the page or try again later';
                                    msg_container.classList.remove('ok');
                                    msg_container.classList.add('error');
                                } else if ( response.details.reply.result == 'success' ) {
                                    msg_container.innerText = 'The vehicle is shown in the game window!';
                                    msg_container.classList.remove('error');
                                    msg_container.classList.add('ok');
                                } else {
                                    msg_container.innerText = 'Refresh the page or try again later';
                                    msg_container.classList.remove('ok');
                                    msg_container.classList.add('error');
                                }
                            } else {
                                msg_container.innerText = 'Refresh the page or try again later';
                                msg_container.classList.remove('ok');
                                msg_container.classList.add('error');
                            }
                        } else if (response.status == 403) {
                            msg_container.innerText = 'Re-log in to the WIKI (click "Log out" and log in again)';
                            msg_container.classList.remove('ok');
                            msg_container.classList.add('error');
                        } else {
                            msg_container.innerText = 'Refresh the page or try again later';
                            msg_container.classList.remove('ok');
                            msg_container.classList.add('error');
                        }
                    }
                } catch (e) {
                    msg_container.innerText = 'Refresh the page or try again later';
                    msg_container.classList.remove('ok');
                    msg_container.classList.add('error');
                }
            };
        }
    }
}

function closeOgpPopup() {
    document.querySelector('.ogp_popup_container').remove();
    document.querySelector('.ogp_background').remove();
}

function specsOpenSlider() {
    var sliderList = document.querySelectorAll('.specs_slider');
    
    for ( var i = 0; i < sliderList.length; i++ ) {
        var title_elem = sliderList[i].querySelector('.specs_slider_title');
        if ( title_elem ) {
            title_elem.onclick = function( e ) {
                e.target.parentElement.classList.toggle('open');
            }
        }
    }
}

function specsShowMod() {
    var modsList = document.querySelectorAll('.specs_mod:not(.view)');
    if ( modsList.length == 0 ) {
        return;
    }
    
    var hideMods = function() {
        var modsOpenList = document.querySelector('.specs_mod.view');
        modsOpenList.classList.add('hide');
    }
    
    document.addEventListener('click', function( e ) {
        if (
            e.target.classList.contains('specs_mod') ||
            e.target.parentElement.classList.contains('specs_mod')
        ) {
            return;
        }
        
        hideMods();
    });
    
    document.querySelector('.specs_slider_container').addEventListener('scroll', hideMods);
    
    var openMod = function( e ) {
        var view_container = document.querySelector('.specs_mod.view');
        var view_pos = document.querySelector('.specs_mods').parentElement.getBoundingClientRect();
        var pos = e.target.offsetParent.getBoundingClientRect();
        view_container.style.left = (pos.x - view_pos.x - 26) + "px";
        view_container.style.top = (pos.y - view_pos.y - 12) + "px";
        view_container.innerHTML = e.target.innerHTML;
        view_container.classList.remove('hide');
    }
    
    for ( var i = 0; i < modsList.length; i++ ) {
        modsList[i].onclick = openMod;
    }
}

function wikiSetup() {
    treeGroup();
    externalLinks();
    addSymbols();
    skinGallery();

    ttxSwichMode();
    ttxCollapseBlock();
    ttxBuyButton();
    ttxCockpit();
    ttxMarketButton();

    specsSlider();
    specsBuyButton();
    specsMarketButton();
    specsOpenInGame();
    specsShowMod();
    specsOpenSlider();

if (navigator.userAgent && navigator.userAgent.indexOf('Valve Steam GameOverlay')) {
    var searchParams = new URLSearchParams(window.location.search);
    if (searchParams.get('from') === 'client') {
        searchParams.set("from", "steamOverlayReturn");
        var newRelativePathQuery = window.location.pathname + '?' + searchParams.toString();
        history.pushState(null, '', newRelativePathQuery);
    }
}
}

if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
    wikiSetup();
} else {
    document.addEventListener('DOMContentLoaded', wikiSetup);
}