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

/* ######################################################################## */ /* ### DISABLE ARCHIVE EDIT                                            ### */ /* ### ### */ /* ### Description: Remove section edit links and gray out main edit    ### */ /* ###             button on archived talk pages                       ### */ /* ### Credit:     User:Porter21                                       ### */ /* ######################################################################## */

$(function {   if (wgNamespaceNumber % 2 === 0 || wgNamespaceNumber === 501) return;

// Configuration var userconfig = (window.DisableArchiveEditConfig) ? window.DisableArchiveEditConfig : {}; var config = $.extend(true, {     archiveSubpage: 'Archive',      disableCompletely: false,      textColor: '#D9D9D9',      userLang: false,      // English      en: {         archived: "Archived",         archivedTooltip: "This page is an archive and should not be edited."      }   }, userconfig); // Function for multi-language support (by Daniel Friesen aka User:Dantman) function msg(name) { if ( config.userLang && wgUserLanguage in config && name in config[wgUserLanguage] ) return config[wgUserLanguage][name]; if ( wgContentLanguage in config && name in config[wgContentLanguage] ) return config[wgContentLanguage][name]; return config.en[name]; }  // Check whether page is an archive if ((new RegExp('\\/\[' + config.archiveSubpage.substr(0,1).toUpperCase     + config.archiveSubpage.substr(0,1).toLowerCase + '\]' + config.archiveSubpage.substr(1)      + '\\s\*\\d\*')).test(wgTitle)) { // Remove "add new section" links and prepare altering "edit" page control switch (skin) { case 'oasis': case 'wikia': var oasisButton = $(($('#WikiaUserPagesHeader').length ? '.UserProfileActionButton' : '#WikiaPageHeader') + ' > .wikia-menu-button'); oasisButton.children("a:first").prependTo($('ul:first', oasisButton)).wrap(' ').children('img').remove; oasisButton.prepend(''); $('a[data-id="addtopic"]', oasisButton).parent.remove; editlink = $('a:first', oasisButton); break; }     // Remove "edit section" links $('span.editsection').remove; // Alter "edit" page control if (config.disableCompletely) { editlink.remove; } else { editlink.attr('title', msg('archivedTooltip')).css('color', config.textColor).text(msg('archived')); }  } });

/* ######################################################################## */ /* ### JQUERY AJAX PATROL LINKS (REMOVE AFTER UCP MIGRATION!)          ### */ /* ### ### */ /* ### Description: Mark pages as patrolled via AJAX                    ### */ /* ### Credit:     User:Grunny (https://dev.wikia.com)                 ### */ /* ######################################################################## */

$(function {   var ajaxIndicator = stylepath + '/common/progress-wheel.gif';   var patrolLinks = $('.patrollink');

if(!patrolLinks.length) { return; }

patrolLinks.click(function (e) {     var curLink = $(this);      var curURL = curLink.children('a').attr('href');

e.preventDefault; curLink.html(''); $.get(curURL, function (data) {        curLink.css('color', 'grey').text('[Marked as patrolled]');      }); }); });

/* ############################################################################# */ /* ### EDITHELP                                                             ### */ /* ###  ### */ /* ### Description: Displays documentation about templates within the        ### */ /* ###             classic editor                                           ### */ /* ### Credit:     User:Mazn                                                ### */ /* ### Disclaimer: See https://fallout.wikia.com/wiki/MediaWiki:EditHelp.js ### */ /* ############################################################################# */ if ( /[?&]action=edit/.test( window.location.search ) ) { $.getScript('/load.php?mode=articles&only=scripts&articles=MediaWiki:EditHelp.js'); }

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