MediaWiki:Common.js: Difference between revisions

From Wiki The-West EN
Jump to navigation
No edit summary
No edit summary
Line 53: Line 53:
// As seen on https://bitbucket.org/cmcqueen1975/htmlfloatingtableheader/overview
// As seen on https://bitbucket.org/cmcqueen1975/htmlfloatingtableheader/overview
function UpdateTableHeaders() {
function UpdateTableHeaders() {
$("div.divTableWithFloatingHeader").each(function() {
    $("div.divTableWithFloatingHeader").each(function() {
var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
        var originalHeaderRow = $(".tableFloatingHeaderOriginal", this);
var floatingHeaderRow = $(".tableFloatingHeader", this);
        var floatingHeaderRow = $(".tableFloatingHeader", this);
var offset = $(this).offset();
        var offset = $(this).offset();
var scrollTop = $(window).scrollTop();
        var scrollTop = $(window).scrollTop();
if ((scrollTop > originalHeaderRow.offset().top) && (scrollTop < offset.top + $(this).height() - originalHeaderRow.height())) {
        if ((scrollTop > originalHeaderRow.offset().top) && (scrollTop < offset.top + $(this).height() - originalHeaderRow.height())) {
floatingHeaderRow.css("visibility", "visible");
            floatingHeaderRow.css("visibility", "visible");
floatingHeaderRow.css("top", "0px");
            floatingHeaderRow.css("top", "0px");


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


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


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


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


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


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


(function($) {
(function($) {
     $(document).ready(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>');
        $('.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 multiplierValue = 1;
         var currentXPArray = [];
         var currentXPArray = [];
var currentCashArray = [];
        var currentCashArray = [];
         $('.xp').each(function(index) {
         $('.xp').each(function(index) {
             currentXPArray[index] = parseInt($(this).text());
             currentXPArray[index] = parseInt($(this).text());
Line 119: Line 119:
             multiplierValue = $(this).val();
             multiplierValue = $(this).val();
             $('.xp').each(function(index) {
             $('.xp').each(function(index) {
var finalXP = currentXPArray[index] + (currentXPArray[index] * (multiplierValue / 100));
                var finalXP = currentXPArray[index] + (currentXPArray[index] * (multiplierValue / 100));
                 $(this).text(Math.round(finalXP));
                 $(this).text(Math.round(finalXP));
$(this).css({ 'font-weight': 'bold' });
                $(this).css({ 'font-weight': 'bold' });
             });
             });
             $('.money').each(function(index) {
             $('.money').each(function(index) {
var finalCash = currentCashArray[index] + (currentCashArray[index] * (multiplierValue / 100));
                var finalCash = currentCashArray[index] + (currentCashArray[index] * (multiplierValue / 100));
var cashSymbol = "$ ";
                var cashSymbol = "$ ";
                 $(this).text(cashSymbol + Math.round(finalCash));
                 $(this).text(cashSymbol + Math.round(finalCash));
$(this).css({ 'font-weight': 'bold' });
                $(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;" />');
        $('.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(
        $("input[name='selectRadio']").change(
function(){
            function(){
var $src = "";
                var $src = "";
if ($(this).val() == '50') {
                if ($(this).val() == '50') {
$src = "https://wiki.the-west.net/images/a/ac/Silverjob_small.png";
                    $src = "https://wiki.the-west.net/images/a/ac/Silverjob_small.png";
}
                }
else if ($(this).val() == '100') {
                else if ($(this).val() == '100') {
$src = "https://wiki.the-west.net/images/a/a6/Goldjob_small.png";
                    $src = "https://wiki.the-west.net/images/a/a6/Goldjob_small.png";
}
                }
else{
                else{
$src = "https://wiki.the-west.net/images/8/8c/Transparent.png"
                    $src = "https://wiki.the-west.net/images/8/8c/Transparent.png"
$('.money').css({ 'font-weight': 'normal' });
                    $('.money').css({ 'font-weight': 'normal' });
$('.xp').css({ 'font-weight': 'normal' });
                    $('.xp').css({ 'font-weight': 'normal' });
}
                }
$('.job_Type').attr('src',$src);
                $('.job_Type').attr('src',$src);
});
        });
     });
     });
})(jQuery);
})(jQuery);
Line 153: Line 153:
(function($) {
(function($) {
     $(document).ready(function() {
     $(document).ready(function() {
         $('#p-Language > div.border-1 > div > div').append(
         //$('#p-Language > div.border-1 > div > div').append(
        $('#module-page-navigation').append(
             $('<div>')
             $('<div>')
             .addClass('inner-body')
             .addClass('inner-body')
         );
         );
         $('#p-Language > div.border-1 > div > div > div').append(
         //$('#p-Language > div.border-1 > div > div > div').append(
        $('#module-page-navigation').append(
             $('<div>')
             $('<div>')
             .addClass('langPicker')
             .addClass('langPicker')
Line 167: Line 169:
                 title: 'English',
                 title: 'English',
                 src: 'https://wiki.the-west.net/images/c/ce/Gb.png',
                 src: 'https://wiki.the-west.net/images/c/ce/Gb.png',
                 link: 'https://wiki.the-west.net/wiki/Main_Page'
                 //link: 'https://wiki.the-west.net/wiki/Main_Page'
                link: 'https://west39.wikitest.fail/wiki/Main_Page'
             },
             },
             {
             {
Line 173: Line 176:
                 title: 'Danish',
                 title: 'Danish',
                 src: 'https://wiki.the-west.net/images/0/06/Dk.png',
                 src: 'https://wiki.the-west.net/images/0/06/Dk.png',
                 link: 'https://wiki.the-west.net/wiki/Forside'
                 //link: 'https://wiki.the-west.net/wiki/Forside'
                link: 'https://west39.wikitest.fail/wiki/Forside'
             },
             },
             {
             {
Line 179: Line 183:
                 title: 'Swedish',
                 title: 'Swedish',
                 src: 'https://wiki.the-west.net/images/d/d0/Se.png',
                 src: 'https://wiki.the-west.net/images/d/d0/Se.png',
                 link: 'https://wiki.the-west.net/wiki/Huvudsida'
                 //link: 'https://wiki.the-west.net/wiki/Huvudsida'
                link: 'https://west39.wikitest.fail/wiki/Huvudsida'
             }
             }
         ];
         ];

Revision as of 15:42, 10 August 2023

/* Any JavaScript here will be loaded for all users on every page load. */

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

    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);
});

(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";
                }
                else if ($(this).val() == '100') {
                    $src = "https://wiki.the-west.net/images/a/a6/Goldjob_small.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
(function($) {
    $(document).ready(function() {
        //$('#p-Language > div.border-1 > div > div').append(
        $('#module-page-navigation').append(
            $('<div>')
            .addClass('inner-body')
        );
        //$('#p-Language > div.border-1 > div > div > div').append(
        $('#module-page-navigation').append(
            $('<div>')
            .addClass('langPicker')
        );

        var languages = [
            {
                lang: 'en',
                title: 'English',
                src: 'https://wiki.the-west.net/images/c/ce/Gb.png',
                //link: 'https://wiki.the-west.net/wiki/Main_Page'
                link: 'https://west39.wikitest.fail/wiki/Main_Page'
            },
            {
                lang: 'dk',
                title: 'Danish',
                src: 'https://wiki.the-west.net/images/0/06/Dk.png',
                //link: 'https://wiki.the-west.net/wiki/Forside'
                link: 'https://west39.wikitest.fail/wiki/Forside'
            },
            {
                lang: 'se',
                title: 'Swedish',
                src: 'https://wiki.the-west.net/images/d/d0/Se.png',
                //link: 'https://wiki.the-west.net/wiki/Huvudsida'
                link: 'https://west39.wikitest.fail/wiki/Huvudsida'
            }
        ];

        var translations = {
            en: {
                //Search Box Translation
                searchNav: 'Search',
                searchNavAdv: 'Advanced search',
                searchNavFText: 'Search Wiki The-West EN',
                searchNavFTitle: 'Search Wiki The-West EN [alt-shift-f]',
                //Main Page Translation
                mainPage: 'Main Page',
                mainPageLink: '/wiki/Main_Page',
                //Navigation Categories Translation
                navigationText: 'Navigation',
                gettingStartedText: 'Getting Started',
                gameFeaturesText: 'Game Features',
                newToWikiText: 'New to the Wiki',
                toolsText: 'Tools',
                quickAccessText: 'Quick access',
                moreGamesText: 'More games',
                followUSText: 'Follow us',
                // Navigation links
                rulesText: 'Game rules',
                rulesLink: 'https://wiki.the-west.net/wiki/Game_Rules',
            },
            dk: {
                //Search Box Translation
                searchNav: 'Søg',
                searchNavAdv: 'Avanceret søgning',
                searchNavFText: 'Søg på Wiki The-West DK',
                searchNavFTitle: 'Søg på Wiki The-West DK [alt-shift-f]',
                //Main Page Translation
                mainPage: 'Forside',
                mainPageLink: '/wiki/Forside',
                //Navigation Categories Translation
                navigationText: 'Naviger',
                gettingStartedText: 'Kom godt i gang',
                gameFeaturesText: 'Spilfunktioner',
                newToWikiText: 'Nyt på wikien',
                toolsText: 'Værktøjer',
                quickAccessText: 'Genveje',
                moreGamesText: 'Flere spil',
                followUSText: 'Følg os',
                // Navigation links
                rulesText: 'Regler',
                rulesLink: 'https://wiki.the-west.net/wiki/Regler_pr._September_2020',
            },
            se: {
                //Search Box Translation
                searchNav: 'Sök',
                searchNavAdv: 'Avancerad sökning',
                searchNavFText: 'Sök på Wiki The-West SE',
                searchNavFTitle: 'Sök på Wiki The-West SE [alt-shift-f]',
                //Main Page Translation
                mainPage: 'Huvudsida',
                mainPageLink: '/wiki/Huvudsida',
                //Navigation Categories Translation
                navigationText: 'Navigering',
                gettingStartedText: 'Börja',
                gameFeaturesText: 'Spelfunktioner',
                newToWikiText: 'Nytt på wikin',
                toolsText: 'Verktyg',
                quickAccessText: 'Genvägar',
                moreGamesText: 'Fler spel',
                followUSText: 'Följ oss',
                // Navigation links
                rulesText: 'Spelregler',
                rulesLink: 'https://wiki.the-west.net/wiki/Game_Rules',
            }
        };

        function updateLinks(language) {
            if (translations[language]) {
                //Logo redirects
                $('.tbbox-logo')
                    .wrap('<a href='+ translations[language].mainPageLink +'></a>');
                // Search Box
                $('h3#p-search-label')
                    .text(translations[language].searchNav);
                $('#searchform > a')
                    .text(translations[language].searchNavAdv);
                $('input#searchInput')
                    .attr('placeholder', translations[language].searchNavFText)
                    .attr('title', translations[language].searchNavFTitle);
                // Navigation Categories and Links
                $('#n-Main-Page > a')
                    .text(translations[language].mainPage)
                    .attr('href', translations[language].mainPageLink);
                $('h3#p-Navigation-label')
                    .text(translations[language].navigationText);
                $('h3#p-Getting_Started-label')
                    .text(translations[language].gettingStartedText);
                $('h3#p-Game_Features-label')
                    .text(translations[language].gameFeaturesText);
                $('h3#p-New_to_the_Wiki-label')
                    .text(translations[language].newToWikiText);
                $('h3#p-tb-label')
                    .text(translations[language].toolsText);
                $('span#Quick_access')
                    .text(translations[language].quickAccessText);
                $('span#More_games')
                    .text(translations[language].moreGamesText);
                $('span#Follow_us')
                    .text(translations[language].followUSText);
                //Navigation links
                $('#n-Game-rules > a')
                    .text(translations[language].rulesText)
                    .attr('href', translations[language].rulesLink);
            }
        }

        var storedLanguage = localStorage.getItem('selectedLanguage');

        if (storedLanguage) {
            updateLinks(storedLanguage);
        }

        for (var i = 0; i < languages.length; i++) {
            var imageElement = $('<img>').attr('src', languages[i].src).attr('title', languages[i].title);
            var linkElement = $('<a>')
                .attr('href', languages[i].link)
                .append(imageElement)
                .on('click', { lang: languages[i].lang }, function(event) {
                    localStorage.setItem('selectedLanguage', event.data.lang);
                    updateLinks(event.data.lang);
                });
            $('.langPicker').append(linkElement);
        }
    });
})(jQuery);