MediaWiki:Common.js

/* */

/* ######################################################################## */ /* ### JavaScript here is loaded for all users and all skins. ### */ /* ######################################################################## */

/* ######################################################################## */ /* ### SHARED CODE                                                     ### */ /* ### ### */ /* ### Description: Used by multiple modules                            ### */ /* ### Credit:     various                                             ### */ /* ######################################################################## */

/** * Removes lazy loading from all images contained in `lazyIcon`. * * By User:Sakaratte. */ function removeLazyLoad(lazyIcon) { var lazyIconImages = lazyIcon.getElementsByTagName("img"); for (var i = 0; i < lazyIconImages.length; i++) { var iconSrc = lazyIconImages[i].getAttribute("data-src"); if (iconSrc !== null) lazyIconImages[i].setAttribute("src", iconSrc); lazyIconImages[i].className = ""; } }

/* ######################################################################## */ /* ### TITLE ICONS (Template:Games)                                    ### */ /* ### ### */ /* ### Description: Add icons to article title                          ### */ /* ### Credit:     User:Porter21                                       ### */ /* ######################################################################## */

$(function {   if (window.wgIsMainpage)        return;    if (wgNamespaceNumber !== 0 && wgNamespaceNumber !== 4 && wgNamespaceNumber !== 110 && wgNamespaceNumber !== 502)        return;    if (skin !== "oasis" && skin !== "wikia")        return;

var iconBar = $("#va-titleicons"); var previewBar = $("#va-titleicons-preview"); if (iconBar.length === 0 || $("a", previewBar).length === 0) return;

var articleDiv = $(".WikiaArticle"); if (articleDiv.length > 0) iconBar.css("display", "block").prependTo(articleDiv);

$("#va-titleicons-more").append("");

iconBar.hover(       function { $(this).addClass("va-titleicons-hover"); },        function { $(this).removeClass("va-titleicons-hover"); }    ); removeLazyLoad(document.getElementById("va-titleicons-preview")); removeLazyLoad(document.getElementById("va-titleicons-fullsize")); });

/* ############################################################################# */ /* ### TICKER                                                               ### */ /* ###  ### */ /* ### Description: Displays a ticker, as in Template:Ticker             ### */ /* ### Credit:     unknown                                                  ### */ /* ###             User:FDekker                                             ### */ /* ############################################################################# */ $(function {   var step = 10;  // How many pixels to move text each tick

$(".ticker").each(function(_, ticker) {       ticker = $(ticker);        ticker.css("display", "block");

var wrapper = $(".tickerWrapper", ticker); wrapper.css("left", (step + ticker.width) + "px");

var text = $(".tickerText", ticker); var textWidth = text.outerWidth;

setInterval(function {           var offset =                (wrapper.position.left > -(textWidth + step))                    ? (wrapper.position.left - step) + "px"  // Move left                    : (ticker.width + step) + "px";  // Reset            wrapper.css("left", offset);        }, 200); }); });

/* ###################################################################################### */ /* ### Staff Images                                                                  ### */ /* ###           ### */ /* ### Description: Loads all of the latest staff images on the staff page. ### */ /* ### URL: https://fallout.wikia.com/wiki/Fallout_Wiki:Administrators_and_moderators ### */ /* ### Credit:     User:TwoBearsHigh-Fiving                                          ### */ /* ###             User:FDekker                                                      ### */ /* ###################################################################################### */ $(function {   var placeholderClass = "user-image-placeholder";

var placeholders = $("." + placeholderClass); if (placeholders.length === 0) return;

var users = placeholders .map(function(_, placeholder) {            return $(placeholder).attr("data-user");         }) .toArray; $.ajax({       url: "https://" + window.location.hostname + "/api/v1/User/Details",        data: { "ids": users.join(",") },        success: function(response) {            response.items.forEach(function(item) { $("." + placeholderClass + "[data-user='" + item.name + "']") .each(function(_, placeholder) {                       placeholder = $(placeholder);

var width = placeholder.attr("data-width"); var height = placeholder.attr("data-height"); if (width === undefined && height === undefined) { width = "100px"; height = "100px"; } else if (width === undefined || height === undefined) { width = width || height; height = width || height; }

placeholder.html(                           ""                        ); });           });        },        dataType: "json" }); });

/* ##################################################################################### */ /* ### Notable content                                                              ### */ /* ###          ### */ /* ### Description: Create a collapsible template where mw-collapsable is not        ### */ /* ###             suitable to use. ### */ /* ### URL: https://fallout.fandom.com/wiki/Fallout_Wiki:Notable_content/draft      ### */ /* ### Credit:     User:Sakaratte                                                   ### */ /* ##################################################################################### */

$(function {   var collapseCaption = "Less";    var expandCaption = "More";

document.querySelectorAll(".np-collapsible").forEach(function(collapsible) {       removeLazyLoad(collapsible);

var collapsed = collapsible.querySelector("#np-collapsed"); var helip = collapsible.querySelector("#np-helip"); helip.innerHTML = expandCaption; helip.addEventListener("click", function(e) {           var navState = helip.innerHTML;            var navClassList = collapsed.classList;

if (navState == expandCaption) { navClassList.add("np-visible"); navClassList.remove("np-hidden"); helip.innerHTML = collapseCaption; } else { navClassList.remove("np-visible"); navClassList.add("np-hidden"); helip.innerHTML = expandCaption; }       });    }); });