MediaWiki:Common.js: differenze tra le versioni

Da Wiki The-West IT.
Vai alla navigazione
Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 140: Riga 140:


$(window).scroll(function() {
$(window).scroll(function() {
     if ($(this).scrollTop() > 300) {
     if ($(this).scrollTop() > 50) {
         $('#back-top').fadeIn();
         $('#back-top').fadeIn();
     } else {
     } else {

Versione delle 19:39, 22 ott 2018

//logo cliccabile
$('.tbbox-logo').wrap('<a href="/wiki/Pagina principale"></a>');

$(document).mousemove(function(e){
	if ($('.popup_window:visible').length!==0){
		var width;
		var height;
		var parent_left = $('.item_container:hover').offset().left;
		var parent_top = $('.item_container:hover').offset().top;
		var w = e.pageX;
		if (e.clientX < ($(window).width())/2){
			width = w + 20 - parent_left;
		} else {
			width = w - 20 - $('.popup_window:visible').outerWidth() - parent_left;
		}
		var h = e.pageY;
		var h2 = $('.popup_window:visible').outerHeight();
		var h3 =$(window).height();
		if (e.clientY < (h3/2)){
			height = h + 20 - parent_top;
			if (e.clientY + h2 +10 > h3) height = h - e.clientY - parent_top + h3 - h2 + 10;
		} else {
			height = h - h2 - parent_top;
			if (e.clientY - h2 < 10) height = h - e.clientY - parent_top + 10;
		}
		$('.popup_window:visible').css({top: height, left: width});
	}
});

//Input level
if ($("#input_level").length == 1) {
    $("#input_level").append('Livello pg: ');
    var input_level = $('<input type="number" class="west" placeholder="Livello" min="0" max="150">').bind("propertychange keyup input paste", function() {
        if (this.value > 150) {
            this.value = 150;
        } else if (this.value < 0) {
            this.value = 0;
        }
        $(".calc").each(function() {
            if (input_level.val() == 0) {
                $(this).html(this.id);
                $('.per_level_off').addClass('per_level').removeClass('per_level_off');
            } else {
                $(this).html(Math.ceil(Number(this.id) * input_level.val()));
                $('.per_level').addClass('per_level_off').removeClass('per_level');
            }
        });
    }).appendTo($("#input_level"));
}

//Switch weapons
if ($("#switch").length == 1) {
    $("#fuoco").hide();
    $("#switch").on("click", function() {
        $('#contusione, #fuoco').toggle()
    });
}
//Switch prodotti
if ($("#scambio").length == 1) {
    $("#sella").hide();
    $("#scambio").on("click", function() {
        $('#prodotto, #sella').toggle()
    });
}

//Switch maps
if ($("#switch1" || "#switch2").length == 1) {
    $("#mandante1, #mandante2").hide();
    $("#switch1").on("click", function() {
        $("#mandante1").show();
        $("#mandante2").hide();
        $("#vuota").hide();
    });
    $("#switch2").on("click", function() {
        $("#mandante2").show();
        $("#mandante1").hide();
        $("#vuota").hide();
    });
}

//Search
if ($("#input_search").length == 1) {
    //Add :containsCI selector (contains case insensitive)
    $.extend($.expr[":"], {
        "containsCI": function(elem, i, match, array) {
            return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
        }
    });
    var input_search = $('<input type="search" class="west" placeholder="Cerca">').bind("propertychange keyup input paste", function() {
        if (this.value == '') {
            $('.item_container').show();
        } else {
            $('.item_container').hide();
            $('.item_container:containsCI("' + this.value + '")').show();
        }
    }).appendTo($("#input_search"));
}

$(document).ready(function()
{
    // Nascondo l'icona al caricamento della pagina
    $("#back_to_top").hide();

    // Intercetto lo scroll di pagina
    $(window).scroll(function()
    {
        // Se l'evento scroll si verifica, mostro l'icona (invisibile) con effetto dissolvenza
        if ($("#back_to_top").is(":hidden")) {
            $("#back_to_top").fadeIn(500);
        }
        // Se si verifica il ritorno ad inizio pagina, nascondo l'icona con effetto dissolvenza
        if ((window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0) == 0 && !$("#back_to_top").is(":hidden")) {
             $("#back_to_top").fadeOut(500);
        }
    });

    // Al click sull'icona, torno ad inizio pagina con movenza fluida
    $("#back_to_top").click(function()
    {
        $("html,body").animate({scrollTop: 0}, 500, function(){});
    });
});


//slide
var slideIndex = 0;
showSlides();

function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    for (i = 0; i < slides.length; i++) {
        slides[i].style.display = "none"; 
    }
    slideIndex++;
    if (slideIndex > slides.length) {slideIndex = 1} 
    slides[slideIndex-1].style.display = "block"; 
    setTimeout(showSlides, 3000); // Change image every 3 seconds
}

$(window).scroll(function() {
    if ($(this).scrollTop() > 50) {
        $('#back-top').fadeIn();
    } else {
        $('#back-top').fadeOut();
    }
});
// Scroll body to top on click
$('#back-top a').click(function() {
    $('body,html').animate({
        scrollTop: 0
    }, 800);
    return false;
});