User:Slate/common.js: Difference between revisions

From Inkipedia, the Splatoon wiki
(test header anchor)
Tag: Reverted
(splashtag)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* For splashtag testing */
function openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";
}
/* Directly from http://wow.gamepedia.com/MediaWiki:Common.js (changed load url) */
/* Directly from http://wow.gamepedia.com/MediaWiki:Common.js (changed load url) */
function setStoredValue(key, value, expiredays) {
function setStoredValue(key, value, expiredays) {
Line 75: Line 90:
     ajaxRC();
     ajaxRC();
});
});
/**
* Vector HeadAnchors
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-vector-headanchor.js
* @revision 2015-03-07
*
* @license http://krinkle.mit-license.org/
* @author Timo Tijhof, 2013–2015
*/
( function ( $ ) {
$( '.mw-headline' ).each( function ( i, el ) {
var id = el.id,
$headline = $( el ),
$header = $headline.parent();
if ( !id || $header.find( '.mw-headline-anchor,.mw-headline-headanchor').length ) {
return;
}
$headline.removeAttr('id');
$header.addClass( 'mw-header' ).prepend(
$( '<a>' ).prop({
id: id,
href: '#' + id,
title: 'Lien vers cette section',
className: 'mw-headline-headanchor'
})
);
} );
}( jQuery ) );

Latest revision as of 18:32, 23 April 2023

/* For splashtag testing */
function openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";
}

/* Directly from http://wow.gamepedia.com/MediaWiki:Common.js (changed load url) */
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('&nbsp;<span style="font-size: xx-small; border-bottom: 1px dotted; cursor:help;" title="Automatically refresh the current page every ' + Math.floor(rcRefresh/1000) + ' seconds">Auto-refresh:</span><input type="checkbox" id="autoRefreshToggle"><span style="position:relative; top:5px; left:5px;" id="autoRefreshProgress"><img src="https://cdn.wikimg.net/en/splatoonwiki/images/1/15/Blue_vs_orange_bounce.gif" border="0" alt="AJAX operation in progress" /></span>');
  $("#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();
});