MediaWiki:Common.js: Difference between revisions

From Wiki The-West EN
Jump to navigation
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
//Popup item
//Popup item
$(document).mousemove(function(e){
$(document).mousemove(function(e) {
if ($('.popup_window:visible').length!==0){
    if ($('.popup_window:visible').length !== 0) {
var width;
        var width;
var height;
        var height;
var parent_left = $('.item_container:hover').offset().left;
        var parent_left = $('.item_container:hover').offset().left;
var parent_top = $('.item_container:hover').offset().top;
        var parent_top = $('.item_container:hover').offset().top;
var w = e.pageX;
        var w = e.pageX;
if (e.clientX < ($(window).width())/2){
        if (e.clientX < ($(window).width()) / 2) {
width = w + 20 - parent_left;
            width = w + 20 - parent_left;
} else {
        } else {
width = w - 20 - $('.popup_window:visible').outerWidth() - parent_left;
            width = w - 20 - $('.popup_window:visible').outerWidth() - parent_left;
}
        }
var h = e.pageY;
        var h = e.pageY;
var h2 = $('.popup_window:visible').outerHeight();
        var h2 = $('.popup_window:visible').outerHeight();
var h3 =$(window).height();
        var h3 = $(window).height();
if (e.clientY < (h3/2)){
        if (e.clientY < (h3 / 2)) {
height = h + 20 - parent_top;
            height = h + 20 - parent_top;
if (e.clientY + h2 +10 > h3) height = h - e.clientY - parent_top + h3 - h2 + 10;
            if (e.clientY + h2 + 10 > h3) height = h - e.clientY - parent_top + h3 - h2 + 10;
} else {
        } else {
height = h - h2 - parent_top;
            height = h - h2 - parent_top;
if (e.clientY - h2 < 10) height = h - e.clientY - parent_top + 10;
            if (e.clientY - h2 < 10) height = h - e.clientY - parent_top + 10;
}
        }
$('.popup_window:visible').css({top: height, left: width});
        $('.popup_window:visible').css({
}
            top: height,
            left: width
        });
    }
});
});


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


//Search
//Search
if ($("#input_search").length==1){
if ($("#input_search").length == 1) {
     //Add :containsCI selector (contains case insensitive)
     //Add :containsCI selector (contains case insensitive)
     $.extend($.expr[":"], {
     $.extend($.expr[":"], {
Line 50: Line 58:
         }
         }
     });
     });
     var input_search=$('<input type="search" class="west" placeholder="Search">').bind("propertychange keyup input paste", function (){
     var input_search = $('<input type="search" class="west" placeholder="Search">').bind("propertychange keyup input paste", function() {
         if(this.value==''){
         if (this.value == '') {
             $('.item_container').show();
             $('.item_container').show();
         } else {
         } else {
             $('.item_container').hide();
             $('.item_container').hide();
             $('.item_container:containsCI("'+this.value+'")').show();
             $('.item_container:containsCI("' + this.value + '")').show();
         }
         }
     }).appendTo($("#input_search"));
     }).appendTo($("#input_search"));
}
}
//Switch weapons
//Switch weapons
if ($("#switch").length==1){
if ($("#switch").length == 1) {
     $("#fire").hide();
     $("#fire").hide();
     $("#switch").on("click",function(){$('#melee, #fire').toggle()});
     $("#switch").on("click", function() {
        $('#melee, #fire').toggle()
    });
}
}

Revision as of 18:01, 11 March 2017

/* Any JavaScript here will be loaded for all users on every page load. */
//Popup item
$(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) {
    var input_level = $('<input type="number" class="west" placeholder="Level" 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"));
}

//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="Search">').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"));
}
//Switch weapons
if ($("#switch").length == 1) {
    $("#fire").hide();
    $("#switch").on("click", function() {
        $('#melee, #fire').toggle()
    });
}