MediaWiki:Common.js

De Wiki The-West FR
Aller à la navigation

Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

  • Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
  • Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
  • Internet Explorer / Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
  • Opera : appuyez sur Ctrl + F5.
// New version based on version 2 mai 2021 à 09:32‎ Hudra modified with inputs 
// from https://wiki.the-west.net/wiki/MediaWiki:Common.js version 11:25, 13 August 2023‎ Criminus 

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

$(document).ready(function() {
    // $.getScript("/wiki/QuestsCalendar.js?action=raw", function() {
    //     // Script loaded
    // });

    // $.getScript("/wiki/Quests.js?action=raw", function() {
    //     // Script loaded
    // });

	$('body').append($('<div></div>').load('https://wiki.the-west.fr/wiki/Dock.html?action=raw'));
	
	if ($('.item_container').length!==0) {
		$.getScript("https://wiki.the-west.fr/wiki/Popup.js?action=raw");
		$('.item_container').each(function() {
			$(this).append('<img src="https://westzz.innogamescdn.com/images/items/' + $(this).attr('data-url') + ($(this).attr('data-cache')?"?"+$(this).attr('data-cache'):"")+'">');
		});
	} 
});
	
$('#navbar a, .set_icon a').removeAttr("title");
$(window).scroll(function() {
    if ($(this).scrollTop() > $("#right_menu").offset().top + $('#right_menu').height() - $( window ).height() + 120) {
        $('#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>'
		);
    });
}

//Configuration du tri des diacritique dans les tables de class "sortable"
mw.config.set( 'tableSorterCollation', {'à':'a', 'â':'a', 'æ':'ae', 'é':'e', 'è':'e', 'ê':'e', 'î':'i', 'ï':'i', 'ô':'o', 'œ':'oe', 'û':'u', 'ç':'c',  } );
if ($('#calcLvlLoss').length !== 0) {
  var context = $('#calcLvlLoss');
  var input_character_level = $('<input type="number" style="width:150px;" class="west" placeholder="Niveau" 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;
    }
    calcLvlLoss();
  }).appendTo(context.find(".character_level"));
  var input_duel_level = $('<input type="number" style="width:150px;" class="west" placeholder="Niveau de duel" min="0" max="450">').bind("propertychange keyup input paste", function() {
    if (this.value > 450) {
      this.value = 450;
    } else if (this.value < 0) {
      this.value = 0;
    }
    calcLvlLoss();
  }).appendTo(context.find(".duel_level"));
  function calcLvlLoss() {
    var duel_lvl = parseInt(input_duel_level.val()),
      char_lvl = parseInt(input_character_level.val());
    if (isNaN(duel_lvl) || isNaN(char_lvl) || duel_lvl < char_lvl) {
      context.find('.result').html('');
    } else {
      var getXp = function(lvl) {
          return Math.ceil(Math.pow((lvl) / 0.1, 1 / 0.6));
        },
        getLvl = function(xp, perc) {
          return char_lvl + Math.floor(Math.pow(xp * (perc || 1), 0.6) * 0.1);
        };
      var minXp = getXp(duel_lvl - char_lvl),
        maxXp = duel_lvl === 450 ? '∞' : getXp(duel_lvl + 1 - char_lvl),
        minLvl = getLvl(minXp, 0.9),
        maxLvl = duel_lvl === 450 ? 450 : getLvl(maxXp, 0.9);
      context.find('.result').html('Expérience de duel actuelle : ' + minXp + ' - ' + maxXp + '<br/>Niveau de duel après avoir pris la potion : ' + minLvl + (maxLvl > minLvl ? ' - ' + maxLvl : ''));
    }
  }
}

// from .net version - probably unused here ... for now
//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');
        });
    });
}
//floating header - 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);
});
(function($) {
    $(document).ready(function() {
        $('.radioButtonsHere').replaceWith('<center><input id="normal" type="radio" value="0" class="selectRadio" name="selectRadio"/> Normal Job <input id="silver" type="radio" value="50" class="selectRadio" name="selectRadio"/> Silver <input id="aura" type="radio" value="100" class="selectRadio" name="selectRadio"/> Gold</center>');
        var multiplierValue = 1;
        var currentXPArray = [];
        var currentCashArray = [];
        $('.xp').each(function(index) {
            currentXPArray[index] = parseInt($(this).text());
        });
        $('.money').each(function(index) {
            var getNumber = $(this).text().replace(/[^0-9]/gi, '');
            currentCashArray[index] = parseFloat(getNumber, 10);
        });
        $("input[name='selectRadio']").change(function() {
            multiplierValue = $(this).val();
            $('.xp').each(function(index) {
                var finalXP = currentXPArray[index] + (currentXPArray[index] * (multiplierValue / 100));
                $(this).text(Math.round(finalXP));
                $(this).css({
                    'font-weight': 'bold'
                });
            });
            $('.money').each(function(index) {
                var finalCash = currentCashArray[index] + (currentCashArray[index] * (multiplierValue / 100));
                var cashSymbol = "$ ";
                $(this).text(cashSymbol + Math.round(finalCash));
                $(this).css({
                    'font-weight': 'bold'
                });
            });
        });
        $('.appImage').replaceWith('<img src="https://wiki.the-west.net/images/8/8c/Transparent.png" class="job_Type" style="position:absolute;margin-top:-6px;margin-left:-6px;" />');
        $("input[name='selectRadio']").change(
            function() {
                var $src = "";
                if ($(this).val() == '50') {
                    //$src = "https://wiki.the-west.net/images/a/ac/Silverjob_small.png";
					$src = "https://wiki.the-west.fr/wiki/Fichier:Travail_doré.png";
                } else if ($(this).val() == '100') {
                    //$src = "https://wiki.the-west.net/images/a/a6/Goldjob_small.png";
					$src = "https://wiki.the-west.fr/wiki/Fichier:Travail_doré.png";
                } else {
                    $src = "https://wiki.the-west.net/images/8/8c/Transparent.png"
                    $('.money').css({
                        'font-weight': 'normal'
                    });
                    $('.xp').css({
                        'font-weight': 'normal'
                    });
                }
                $('.job_Type').attr('src', $src);
            });
    });
})(jQuery);

//Page translator - Criminus 2023 - skipped ! only one language on FR

//Navigation stuff
(function($) {
    $(document).ready(function() {
        var $navigationDummy = $("<div>", {
            id: "navigationDummy",
            html: ""
        });
        $navigationDummy.insertBefore("#mw-navigation");
        var elementToMove = $("#module-site-navigation").detach();
        elementToMove.appendTo($navigationDummy);
    });
})(jQuery);

function($) {
    $(document).ready(function() {
        $('.contact_team-btn').click(function() {
            var url = $(this).data('url');
            if (url) {
                window.open(url, '_blank');
            }
        });
        // $('.normal_quest').click(function() {
            // var url = $(this).data('url');
            // if (url) {
                // window.open(url, '_blank');
            // }
        // });
        // $('.repeatable_quest').click(function() {
            // var url = $(this).data('url');
            // if (url) {
                // window.open(url, '_blank');
            // }
        // });
    });
})(jQuery);

(function($) {
    $(document).on('click', '.dock-toggler', function() {
        const dockItems = $('.dock-items-container');
        const toggler = $('.dock-toggler');
        const toggleDockIcon = $('.toggle-dock');

        dockItems.toggleClass('toggled');
        toggler.toggleClass('toggled');
        toggleDockIcon.toggleClass('toggled');
    });
})(jQuery);

(function($) {
    $(document).ready(function() {
        function adjustColspan() {
            var screenWidth = $(window).width();

            var threshold = 768;

            $('quest.table td, quest.table th').each(function() {
                if (!$(this).data('original-colspan') && $(this).attr('colspan')) {
                    $(this).data('original-colspan', $(this).attr('colspan'));
                }

                if (screenWidth <= threshold) {
                    if ($(this).attr('colspan') && parseInt($(this).attr('colspan'), 10) === 3) {
                        $(this).attr('colspan', '1');
                    }
                } else {
                    if ($(this).data('original-colspan')) {
                        $(this).attr('colspan', $(this).data('original-colspan'));
                    }
                }
            });
        }

        adjustColspan();

        $(window).resize(adjustColspan);
    });
})(jQuery);

(function($) {
    $(document).ready(function() {
        var currentUrl = window.location.pathname.split('/').pop();

        if (currentUrl !== 'MediaWiki:Common.css' || currentUrl !== 'MediaWiki:Common.js') {
            $('#firstHeading').hide();
        }
        if (currentUrl == 'Category:Item_sets' || currentUrl == 'Category:Questlines') {
            $('.mw-category-generated').hide();
        }
    });
})(jQuery);

(function($) {
	$(document).ready(function() {
		$('.quickSearchQuest').append('<span class="textfield_wrapper textfield_flex"><span class="textfield_label"></span><span class="textfield"><span><input type="text" id="QsearchBox" placeholder="Quick Search Quest"></span></span></span>');
	});
})(jQuery);