MediaWiki:Common.js: Difference between revisions

From Wiki The-West EN
Jump to navigation
No edit summary
No edit summary
Line 102: Line 102:


$(document).ready(function () {
$(document).ready(function () {
    var table = $('table');
                $('th #sort').each(function (col) {
   
                    $(this).hover(
    $('#money_header, #luck_header')
                            function () {
        .wrapInner('<span title="Show data asc"/>')
                                $(this).addClass('focus');
        .each(function(){
                            },
           
                            function () {
            var th = $(this),
                                $(this).removeClass('focus');
                thIndex = th.index(),
                            }
                inverse = false;
                    );
           
                    $(this).click(function () {
            th.click(function(){
                        if ($(this).is('.asc')) {
               
                            $(this).removeClass('asc');
                table.find('td').find(function(){
                            $(this).addClass('desc selected');
                   
                            sortOrder = -1;
                    return $(this).index() === thIndex;
                        } else {
                   
                            $(this).addClass('asc selected');
                }).sortElements(function(a, b){
                            $(this).removeClass('desc');
                   
                            sortOrder = 1;
                    return $.text([a]) > $.text([b]) ?
                        }
                        inverse ? -1 : 1
                        $(this).siblings().removeClass('asc selected');
                        : inverse ? 1 : -1;
                        $(this).siblings().removeClass('desc selected');
                   
                        var arrData = $('table').find('tbody >tr:has(td)').get();
                }, function(){
                        arrData.sort(function (a, b) {
                   
                            var val1 = $(a).children('td').eq(col).text().toUpperCase();
                    // parentNode is the element we want to move
                            var val2 = $(b).children('td').eq(col).text().toUpperCase();
                     return this.parentNode;  
                            if ($.isNumeric(val1) && $.isNumeric(val2))
                   
                                return sortOrder == 1 ? val1 - val2 : val2 - val1;
                            else
                                return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0;
                        });
                        $.each(arrData, function (index, row) {
                            $('tbody').append(row);
                        });
                     });
                 });
                 });
               
                inverse = !inverse;
                   
             });
             });
               
        });
});

Revision as of 09:12, 15 October 2022

/* Any JavaScript here will be loaded for all users on every page load. */
$('.tbbox-logo').wrap('<a href="/wiki/Main_Page"></a>');
if ($('.item_container').length !== 0) {
  $('.item_container').each(function () {
    $(this).append(
      '<img src="https://westzz.innogamescdn.com/images/items/' +
        $(this).attr('data-url') +
        '?1">'
    );
  });
  $.getScript('/wiki/Popup.js?action=raw');
}

$(window).scroll(function () {
  if ($(this).scrollTop() > 300) {
    $('#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;
});
// Embed youtube videos
if ($('.youtube_video').length !== 0) {
  $('.youtube_video').each(function () {
    $(this).html(
      '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/' +
        $(this).attr('data-id') +
        '?cc_load_policy=1&cc_lang_pref=' +
        $(this).attr('data-subtitles') +
        '" frameborder="0" allowfullscreen></iframe>'
    );
  });
}
//calculate box - n3mesis
if ($('.calculate_box').length) {
  $.getScript('/wiki/Calculate.js?action=raw');
};
//crafting
if($('.target_input').length){$('.target_input p').each(function(){var id=$(this).attr('id');var phrase=$(this).text();var newInput="<input type='number' name='input_new' value='"+
phrase+"' class='target' max='50000' min='' />";$(this).replaceWith(newInput);});var multiplierValue=1;var currentAmountsArray=[];$('.amount').each(function(index){currentAmountsArray[index]=parseInt($(this).text());});$("input[name='input_new']").on('input paste keyup',function(){this.value>50000?(this.value=50000):this.value<0&&(this.value=0);multiplierValue=this.value;$('.amount').each(function(index){$(this).text(currentAmountsArray[index]*multiplierValue);});$('.craft_extra').show();$('.craft_extra .item_container').each(function(){$(this).children().addClass('OverlayItem');});});}

// As seen on https://bitbucket.org/cmcqueen1975/htmlfloatingtableheader/overview
function UpdateTableHeaders() {
	$("div.divTableWithFloatingHeader").each(function() {
		var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
		var floatingHeaderRow = $(".tableFloatingHeader", this);
		var offset = $(this).offset();
		var scrollTop = $(window).scrollTop();
		if ((scrollTop > originalHeaderRow.offset().top) && (scrollTop < offset.top + $(this).height() - originalHeaderRow.height())) {
			floatingHeaderRow.css("visibility", "visible");
			floatingHeaderRow.css("top", "0px");

			// Copy cell widths from original header
			$("th", floatingHeaderRow).each(function(index) {
				var cellWidth = $("th", originalHeaderRow).eq(index).css('width');
				$(this).css('width', cellWidth);
			});

			// Copy row width from whole table
			floatingHeaderRow.css("width", $(this).css("width"));
		}
		else {
			floatingHeaderRow.css("visibility", "hidden");
			floatingHeaderRow.css("top", "0px");
		}
	});
};

$(function() {
	$("table.tableWithFloatingHeader").each(function() {
		$(this).wrap("<div class=\"divTableWithFloatingHeader\" style=\"position:relative\"></div>");

		var cls = "tr.floatingHeader";
		if($(cls, this).length == 0) {
			cls = "tr";
		}
		var originalHeaderRow = $(cls, this).first();
		var clonedHeaderRow = originalHeaderRow.clone().insertBefore(originalHeaderRow);

		clonedHeaderRow.addClass("tableFloatingHeader");
		clonedHeaderRow.css("position", "fixed");
		clonedHeaderRow.css("top", "0px");
		clonedHeaderRow.css("left", $(this).offset().left);
		clonedHeaderRow.css("visibility", "hidden");
		clonedHeaderRow.css("z-index", 1);

		originalHeaderRow.addClass("tableFloatingHeaderOriginal");
	});
	UpdateTableHeaders();
	$(window).on('scroll', UpdateTableHeaders);
	$(window).on('resize', UpdateTableHeaders);
});

$(document).ready(function () {
                $('th #sort').each(function (col) {
                    $(this).hover(
                            function () {
                                $(this).addClass('focus');
                            },
                            function () {
                                $(this).removeClass('focus');
                            }
                    );
                    $(this).click(function () {
                        if ($(this).is('.asc')) {
                            $(this).removeClass('asc');
                            $(this).addClass('desc selected');
                            sortOrder = -1;
                        } else {
                            $(this).addClass('asc selected');
                            $(this).removeClass('desc');
                            sortOrder = 1;
                        }
                        $(this).siblings().removeClass('asc selected');
                        $(this).siblings().removeClass('desc selected');
                        var arrData = $('table').find('tbody >tr:has(td)').get();
                        arrData.sort(function (a, b) {
                            var val1 = $(a).children('td').eq(col).text().toUpperCase();
                            var val2 = $(b).children('td').eq(col).text().toUpperCase();
                            if ($.isNumeric(val1) && $.isNumeric(val2))
                                return sortOrder == 1 ? val1 - val2 : val2 - val1;
                            else
                                return (val1 < val2) ? -sortOrder : (val1 > val2) ? sortOrder : 0;
                        });
                        $.each(arrData, function (index, row) {
                            $('tbody').append(row);
                        });
                    });
                });
            });