MediaWiki:Common.js

/* */

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

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

function addTitleIcons { var iconBar = $('#va-titleicons'); var previewBar = $('#va-titleicons-preview');

if (skin != 'monobook' && skin != 'oasis' && skin != 'wikia') { return; }

if (iconBar.length > 0 && $('a', previewBar).length > 0) { if (skin == 'oasis' || skin == 'wikia') { var articleDiv = $('.WikiaArticle');

if (articleDiv.length > 0) { iconBar.css('display', 'block').prependTo(articleDiv); }     } else if (skin == 'monobook') { var firstHeading = $('#firstHeading').css('position', 'relative');

if (firstHeading.length > 0) { iconBar.css('display', 'block').appendTo(firstHeading.css('padding-right', previewBar.width + 25)); }     }

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

iconBar.hover(        function  {            $(this).addClass('va-titleicons-hover');         }, function  {            $(this).removeClass('va-titleicons-hover');         }); } }

/* Games template fix to remove Lazy load by User:Sakaratte                */ function rmvLzyLoad(lazyIcon) { var lazyIconCleanse = lazyIcon.getElementsByTagName("img"); for (i = 0; i < lazyIconCleanse.length; i++) {           var iconSrc = lazyIconCleanse[i].getAttribute("data-src"); if (iconSrc !== null) /*Does nothing if there is no data-src */ { lazyIconCleanse[i].setAttribute("src", iconSrc); }           lazyIconCleanse[i].className=""; } }

var gamesCheck = document.getElementById("va-titleicons");

if (gamesCheck !== null) {   var lazyIconSmall = document.getElementById("va-titleicons-preview"); var lazyIconLarge = document.getElementById("va-titleicons-fullsize"); rmvLzyLoad(lazyIconSmall); rmvLzyLoad(lazyIconLarge); }

var lzyHelip = document.getElementById("np-collapsed"); if (lzyHelip !== null) { rmvLzyLoad(lzyHelip); }

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

function disableArchiveEdit { // 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 'monaco': $('#control_addsection').remove; $('#fe_newsection').remove; editlink = $('#ca-edit'); break; case 'monobook': $('#ca-addsection').remove; editlink = $('#ca-edit > a'); break; 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 ajaxPatrolLinks { 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]');      }); }); }

/* ######################################################################## */ /* ### SCRIPT LOADER                                                   ### */ /* ### ### */ /* ### Description: Loads all the other scripts                         ### */ /* ### Credit:     User:Porter21                                       ### */ /* ######################################################################## */

function vaultScriptLoader { // Always loaded addCountdowns; rewriteChatLink; ajaxPatrolLinks;

// Only loaded for specific namespaces if ((wgNamespaceNumber === 0 || wgNamespaceNumber === 4 || wgNamespaceNumber === 110 || wgNamespaceNumber === 502) &&     !window.wgIsMainpage) { addTitleIcons; }

if (wgNamespaceNumber%2 !== 0 && wgNamespaceNumber !== 501) { archiveTool; disableArchiveEdit; } }

jQuery(function($) {  vaultScriptLoader; });

/* ############################################################################# */ /* ### 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                                                  ### */ /* ############################################################################# */ var $ticker = $('#ticker'), $ticker_div = $('#tickerdiv'), $ticker_text = $('#tickertxt'), ticker_text_outer_width, ticker_interval;

function createTicker { if ($ticker.length && $ticker_div.length && $ticker_text.length) { $ticker.css('display', 'block'); ticker_text_outer_width = $ticker_text.outerWidth; $ticker_div.css('left', parseInt($ticker.width) + 10 + 'px'); ticker_interval = setInterval("processTicker", 200); } }

function processTicker { var left_width = (parseInt($ticker_div.position.left) > (-10 - ticker_text_outer_width)) ? parseInt($ticker_div.position.left) - 10 + 'px' : parseInt($ticker.width) + 10 + 'px'; $ticker_div.css('left', left_width); }

createTicker;

/* ###################################################################################### */ /* ### 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                                          ### */ /* ###################################################################################### */ function loadStaffImages { // Container surrounding the user boxes var $staffBox = $('#staff-container'); // Return if the container doesn't exist if (!$staffBox.length) { return; } // Grab all the placeholders var $placeholders = $('.img-placeholder'); // Build an array of user names var users = []; $placeholders.each(function {       users.push($(this).attr('data-user'));    }); // Create a query string from user names var queryString = users.join(','); // Call to API to fetch images $.ajax({       url: "https://fallout.fandom.com/api/v1/User/Details",        data: { "ids": queryString },        success: function(response) {            var userItems = response.items;            for (var i = 0; i < userItems.length; i++) {                var $placeholder = $(".img-placeholder[data-user='" + userItems[i].name + "']");                $placeholder.html("");            }        },         dataType: "json"    }); } addOnloadHook(loadStaffImages);

/* ##################################################################################### */ /* ### 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                                                   ### */ /* ##################################################################################### */ /*Initialise variables */ var helipInitialise = document.getElementsByClassName('np-helip'); /* Remove duplicate id's from article */ for (i=0; i < helipInitialise.length; ++i) {       var newHelip = "np-helip" + i;        var newCollapse = "np-Collapsed" + i;    document.getElementById("np-helip").setAttribute("onclick", 'npCollapsible("' + newHelip + '", "' + newCollapse + '")'); document.getElementById("np-helip").innerHTML = "More"; document.getElementById("np-collapsed").id = newCollapse; document.getElementById("np-helip").id = newHelip; } /* Switches collapsible content between hidden and visible */ function npCollapsible (helipName, collapseName) { var collapseCaption = "Less"; var expandCaption = "More"; navState = document.getElementById(helipName).innerHTML; navClass = document.getElementById(collapseName).classList; if (navState == expandCaption) { navClass.add("np-visible"); navClass.remove("np-hidden"); document.getElementById(helipName).innerHTML = collapseCaption; } else { navClass.remove("np-visible"); navClass.add("np-hidden"); document.getElementById(helipName).innerHTML = expandCaption; } }