MediaWiki:Common.js

/* */

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

/* ######################################################################## */ /* ### ImportJS OVERRIDES                                              ### */ /* ### ### */ /* ### Description: Overrides configurations of ImportJS modules. ### */ /* ### Credit:     User:FWDekker                                       ### */ /* ######################################################################## */

// ArchiveTool changed their default values at some point. // These lines revert it to the old values. window.ArchiveToolConfig = { archiveListTemplate: "Archives", archivePageTemplate: "Archivepage", };

/* ######################################################################## */ /* ### 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 = ""; } }

/* ############################################################################# */ /* ### TICKER                                                               ### */ /* ###  ### */ /* ### Description: Displays a ticker, as in Template:Ticker             ### */ /* ### Credit:     unknown                                                  ### */ /* ###             User:FDekker                                             ### */ /* ############################################################################# */ $(function {   $(".ticker").each(function(_, ticker) { var step = 10; // How many pixels to move text each tick var tickerSpeed = 200; ticker = $(ticker); if (ticker.attr('data-speed') !== undefined) tickerSpeed = parseInt(ticker.attr('data-speed')); if (ticker.attr('data-step') !== undefined) step = parseInt(ticker.attr('data-step')); 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);        }, tickerSpeed); }); });

/* ####################################################################################### */ /* ### Admin Images                                                                   ### */ /* ###            ### */ /* ### Description: Loads all admin images on the leadership page. ### */ /* ### 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");        }) .map(function(_, user) {       	return user.replace(/@/g, "\"");        })        .toArray;    $.ajax({        url: "https://" + window.location.hostname + "/api/v1/User/Details",        data: { "ids": users.join(",") },        success: function(response) {            response.items.forEach(function(item) {            	var escapedName = item.name.replace(/"/g, "@");

$("." + placeholderClass + "[data-user]") // Separate filter to support quotes in usernames .filter(function {           			return $(this).data("user") === escapedName;            		}) .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: DEPRECIATED DO NOT USE                                           ### */ /* ### Credit:     Please use Template:Leveled list                             ### */ /* ##################################################################################### */

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

/* ##################################################################################### */ /* ### Global File Usage                                                            ### */ /* ###              ### */ /* ### Description: DEPRECIATED DO NOT USE                                           ### */ /* ### Credit:     No interlanguage links utilized on site                          ### */ /* ##################################################################################### */ window.globalFileUsageConfig = { 'lang': ['bg','cs','de','en','es','fa','fi','fr','hu','it','ja','ko','lt','nl','no','pl','ru','pt-br','sv','tr','uk','zh'], 'auto_show': false, 'on_delete': true };