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

Материал из War Thunder Wiki
Перейти к: навигация, поиск
Строка 8: Строка 8:
 
}
 
}
 
selectedArrow();
 
selectedArrow();
 
+
bodyContent
 
/* Код замены игровых символов */
 
/* Код замены игровых символов */
 
function specialSymbols(){
 
function specialSymbols(){
 
var txt = document.getElementById("bodyContent").innerHTML;
 
var txt = document.getElementById("bodyContent").innerHTML;
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">▀</span></span>');
+
txt = txt.replace(/▀/g, '<span style="font-family: wtfSymbols;">▀</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">▂</span></span>');
+
txt = txt.replace(/▂/g, '<span style="font-family: wtfSymbols;">▂</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">▅</span></span>');
+
txt = txt.replace(/▅/g, '<span style="font-family: wtfSymbols;">▅</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">▃</span></span>');
+
txt = txt.replace(/▃/g, '<span style="font-family: wtfSymbols;">▃</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">▄</span></span>');
+
txt = txt.replace(/▄/g, '<span style="font-family: wtfSymbols;">▄</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;">␠</span></span>');
+
txt = txt.replace(/␠/g, '<span style="font-family: wtfSymbols;">␠</span>');
txt = txt.replace(/<span style="font-family: wtfSymbols;"></span>/g, '<span style="font-family: wtfSymbols;"><span style="font-family: wtfSymbols;"></span></span>');
+
txt = txt.replace(//g, '<span style="font-family: wtfSymbols;"></span>');
 
document.getElementById("bodyContent").innerHTML = txt;
 
document.getElementById("bodyContent").innerHTML = txt;
 
}
 
}

Версия 17:50, 24 мая 2018

/* Код стрелочки под активным разделом */
function selectedArrow() {
	var el = document.getElementsByClassName("selected");
	var i;
	for (i = 0; i < el.length; i++){
		el[i].innerHTML = el[i].innerHTML + '<span style="display:block;margin-top:-5px;background:url(http://test-wiki.warthunder.ru/skins/Vector/images/arrow_selected.png) no-repeat center top;"></span>';
	}
}
selectedArrow();
bodyContent
/* Код замены игровых символов */
function specialSymbols(){
	var txt = document.getElementById("bodyContent").innerHTML;
	txt = txt.replace(/▀/g, '<span style="font-family: wtfSymbols;">▀</span>');
	txt = txt.replace(/▂/g, '<span style="font-family: wtfSymbols;">▂</span>');
	txt = txt.replace(/▅/g, '<span style="font-family: wtfSymbols;">▅</span>');
	txt = txt.replace(/▃/g, '<span style="font-family: wtfSymbols;">▃</span>');
	txt = txt.replace(/▄/g, '<span style="font-family: wtfSymbols;">▄</span>');
	txt = txt.replace(/␠/g, '<span style="font-family: wtfSymbols;">␠</span>');
	txt = txt.replace(//g, '<span style="font-family: wtfSymbols;"></span>');
	document.getElementById("bodyContent").innerHTML = txt;
}
specialSymbols();

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

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

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

/* Код кнопки "Купить" ТТХ карточек */
function ttxBuyButton() {
	var logout = document.getElementById('pt-logout');
	var el = document.getElementsByClassName("ttx-buy-button");
	var i;
	if (logout == null) {
		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', "window.open ('" + link + "');");
		}
	}
}
ttxBuyButton();

/* Код веток техники */
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() {
			$(".tree-group-collapse").slideUp();
		});
	});
}
treeGroup();