Gamepedia Help Wiki

Para conteúdo atualizado sobre o novo tema Fandomdesktop, consulte a Central da Comunidade

LEIA MAIS

Gamepedia Help Wiki
Sem resumo de edição
Sem resumo de edição
Linha 73: Linha 73:
 
// show the root element in case it was hidden while waiting for JS.
 
// show the root element in case it was hidden while waiting for JS.
 
$(this).show();
 
$(this).show();
  +
});
  +
  +
window.AddRailModule = [{prepend: true}];
  +
  +
mw.hook('AddRailModule.module').add(function() {
  +
mw.hook('dev.wds').add(function(wds) {
  +
$('.railModule.rail-module h2.has-icon').prepend(
  +
wds.icon('discord', {'class': 'wds-icon-small'})
  +
);
  +
wds.render('h2.has-icon');
  +
});
 
});
 
});

Revisão das 19h17min de 27 de junho de 2021

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

/* Replaces {{USERNAME}} with the name of the user browsing the page.
   Requires copying Template:USERNAME. */
$(function () {
    if (window.disableUserReplace || mw.config.get('wgUserName') === null) return;
    $('span.insertusername').html(mw.config.get('wgUserName'));
});
/* End of the {{USERNAME}} replacement */

$(function () {
    if (window.disableUserReplace || mw.config.get('wgUserName') === null) return;
    $('span.insertusersandboxlink').html('<a href="/User:' + mw.config.get('wgUserName') + '/sandbox">sandbox</a>');
});

/*************************
 * JQuery Random  Plugin *
 *************************/

/**
 * Adds a 'random' filter to jQuery, which selects 1 or more elements at random for the current jQuery set.
 * Defaults to 1 element if a amount isn't given.
 */

jQuery.fn.random = function(count) {
    var count = (typeof count !== 'undefined') ?  count : 1;
    // Return the current set if an invalid count is asked for.
    if ( count < 1 || count >= this.length || ! Number.isInteger(Number(count)) ) {
        return jQuery(this);
    }

    var indexes = [];
    var resultset = [];
    while ( indexes.length < count ) {
        // Generate a random index
        var index = Math.floor(Math.random() * this.length);
        
        // reroll the random index if it's already present
        var reroll = false;
        for (var i = 0; i < indexes.length; i++) {
            if ( indexes[i] == index ) {
                reroll = true;
            }
        }
        if (reroll) {
            continue;
        }

        // Add the index/element to the result set
        indexes.push(index);
        resultset.push(this[index]);
    }
    return jQuery(resultset);
}

/*****************
 * Random subset *
 *****************/

/**
 * A random subset of list elements within elements with the 'random-subset' class are show, while the rest are hidden.
 * The 'data-random-subset-count' attribute can be used to specify the number of elements to be displayed.
 */

$('.random-subset').each(function() {
    var count = 1;
    // If the data-random-subset-count attribute is present use that count
    if ($(this).attr('data-random-subset-count')) {
        count = $(this).attr('data-random-subset-count');
    }
    var entries = $(this).find('li');
    $(entries).random(entries.length - count).remove();
    // show the root element in case it was hidden while waiting for JS.
    $(this).show();
});

window.AddRailModule = [{prepend: true}];

mw.hook('AddRailModule.module').add(function() {
  mw.hook('dev.wds').add(function(wds) {
    $('.railModule.rail-module h2.has-icon').prepend(
      wds.icon('discord', {'class': 'wds-icon-small'})
    );
    wds.render('h2.has-icon');
  });
});