User:Slate/common.js

/* Load the jQuery with the current document. */ jQuery( document ).ready( function( $ ) { } );

/* Directly from http://wow.gamepedia.com/MediaWiki:Common.js */ function setStoredValue(key, value, expiredays) { if (typeof(localStorage) == "undefined") { var exdate = new Date; exdate.setDate(exdate.getDate + (expiredays ? expiredays : 30)); document.cookie = key + "=" + escape(value) + ";expires=" + exdate.toGMTString; } else { try { localStorage[key] = value; } catch (e) { // Usually QUOTA_EXCEEDED_ERR } } }

function getStoredValue(key, defaultValue) { if (typeof(localStorage) == "undefined") { if (document.cookie && document.cookie.length) { var varr = document.cookie.match("(?:^|;)\\s*" + key + "=([^;]*)"); if (varr.length == 2) return varr[1]; }   return defaultValue; } return localStorage[key] == null ? defaultValue : localStorage[key]; }

// AJAX RC var ajaxPages = {"Special:RecentChanges" : 1}; var ajaxRCOverride = false; var rcRefresh = 120000;

function ajaxRC { appTo = $(".firstHeading"); appTo.append(' Auto-refresh:   '); $("#autoRefreshToggle").click(function {   setStoredValue("ajaxRC", $("#autoRefreshToggle").is(":checked") ? "on" : "off")   loadRCData  }); $("#autoRefreshProgress").hide; if (getStoredValue("ajaxRC") == "on" || ajaxRCOverride) { $("#autoRefreshToggle").attr("checked", "checked"); setTimeout("loadRCData;", rcRefresh); } } function handleAutocollapse(root) { var $ct = root.find(".mw-collapsible"); var $es = $ct.filter(".mw-autocollapse").not($ct.first).not(".mw-collapsed, .mw-uncollapsed, .mw-expanded"); $es.filter(function {   var link = $(this).find(".mw-collapsible-toggle a");    if (link.length)       link.first.click;    return !link.length;  }).toggleClass("mw-collapsed mw-autocollapse"); } function loadRCData { if (!$("#autoRefreshToggle").is(":checked")) return; $('#autoRefreshProgress').show $(article).load(location.href + " "+article+" > *", function (data) {   handleAutocollapse($(article));    $(article + " .mw-collapsible").makeCollapsible;    $('#autoRefreshProgress').hide    if ($("#autoRefreshToggle").is(":checked"))       setTimeout("loadRCData;", rcRefresh);  }); }

$(function { article = "#bodyContent";  var pagename = mw.config.get('wgPageName');  if (pagename && ajaxPages.hasOwnProperty(pagename) && !$("#autoRefreshToggle").length)     ajaxRC; });

// ================================================================================ // Username replace function for Template:USERNAME // ================================================================================ // Inserts user name into. // Disable by setting disableUsernameReplace = true. jQuery(function($) { if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace)    return;  var username = mw.config.get('wgUserName');  if (username == null)    return;

$('.insertusername').text(username); });

// ================================================================================ // Editcount replace function for Template:EDITCOUNT // ================================================================================ // Inserts edit count into jQuery(function($) { var userEditCount = mw.config.get('wgUserEditCount');  if (userEditCount == null)    return;

$('.inserteditcount').text(userEditCount); });

// ================================================================================ // Registration date replace function for Template:REGISTRATIONDATE // ================================================================================ // Inserts registration date into jQuery(function($) { var userRegistrationDate = mw.config.get('wgUserRegistration');  if (userRegistrationDate == null)    return;

$('.insertregistrationdate').text(new Date(userRegistrationDate).toLocaleString); });