(Old tooltip code not loading -- testing Pcj's tooltip code from a Wikia site)
(more recent code)
 
(13 intermediate revisions by the same user not shown)
Line 2: Line 2:


// Duplicate image list
// Duplicate image list
importScript('User:Arkalor/dupimages.js');
importScriptPage('DupImageList/code.js', 'dev');  
 
/* --- Standard Functions --- */
 
/** name - cookie name, value - 'on' or 'off' or whatever, exdays - expiry of cookie in days */
function setCookie(name, value, exdays) {  // Sets a cookie
  value = name + "=" + escape(value);
  if (exdays !== null) { var d = new Date(); value += ";expires=" + d.setDate(d.getDate() + exdays).toGMTString(); }
  document.cookie = value;
}
 
/** name - cookie name, @return - cookie or empty string */
function getCookie(name) {    // Gets a cookie
  var c = document.cookie;
  if (c.length > 0) {
    var s = c.indexOf(name + "=");
    if (s !== -1) {
      var e = c.indexOf(";", s = s + name.length + 1);
      return unescape(c.substring(s, (e !== -1) ? e : e = c.length));
    }
  }
  return "";
}


/* --- Tooltips --- */
/* --- Tooltips --- */
Line 30: Line 8:
var tooltipsOn = true;
var tooltipsOn = true;


var $tfb;
var $tfb, $ttfb, $htt;
var $ttfb;
activeHoverLink = null;
var $htt;
tipCache = {};


// hides the tooltip
// hides the tooltip
function hideTip() {
function hideTip() {
  $tfb.html("").removeClass("tooltip-ready").addClass("hidden").css("visibility", "hidden");
$tfb.removeClass("tooltip-ready").addClass("hidden").css("visibility","hidden");
$tfb.children().remove();
if ($(this).data('ahl-id') == activeHoverLink) activeHoverLink = null;
}
}


// displays the tooltip
// displays the tooltip
function displayTip(e) {
function displayTip(e) {
  $htt.not(":empty").removeClass("hidden").addClass("tooltip-ready");
$htt.not(":empty").removeClass("hidden").addClass("tooltip-ready");
  moveTip(e);
moveTip(e);
  $htt.not(":empty").css("visibility", "visible");
$htt.not(":empty").css("visibility","visible");
moveTip(e);
}
}


// moves the tooltip
// moves the tooltip
function moveTip(e) {
function moveTip(e) {
  var newTop = e.clientY + ((e.clientY > ($(window).height() / 2)) ? -($htt.not(".hidden").innerHeight() + 20) : 20);
$ct = $htt.not(":empty");
  var newLeft = e.clientX + ((e.clientX > ($(window).width() / 2)) ? -($htt.not(".hidden").innerWidth() + 20) : 20);
var eh = $ct.innerHeight() + 20, wh = $(window).height();
  $htt.not(".hidden").css({
var newTop = e.clientY + ((e.clientY > (wh/2)) ? -eh : 20);
    "position": "fixed",
var newLeft = e.clientX + ((e.clientX > ($(window).width()/2)) ? -($ct.innerWidth()+20):20);
    "top": newTop + "px",
newTop = Math.max(0, Math.min(wh - eh, newTop));
    "left": newLeft + "px"
 
  });
$ct.css({"position":"fixed","top":newTop + "px","left":newLeft + "px"});
}
}


// AJAX tooltips
// AJAX tooltips
function showTipFromCacheEntry(e, url, tag) {
var h = tipCache[url + " " + tag];
if (!h) {
h = tipCache[url].find(tag);
if (h.length) tipCache[url + " " + tag] = h;
}
if (!h.length) {
$tfb.html('<div class="tooltip-content"><b>Error</b><br />This target either has no tooltip<br />or was not intended to have one.</div>');
} else {
h.css("display", "").addClass("tooltip-content");
$tfb.html(h);
}
displayTip(e);
}
function showTip(e) {
function showTip(e) {
  $t = $(this);
var $t = $(this);
  $p = $t.parent();
$p = $t.parent();
  if ($p.hasClass("selflink") == false) {
if ($p.hasClass("selflink") == false) {
    $t.removeAttr("title");
                $t.removeAttr("title");
    $p.removeAttr("title");
                $p.removeAttr("title");
    $tfb.load("/" + $t.data("tt").replace(/ /g, "_").replace(/\?/g, "%3F") + "?action=render div.tooltip-content", function () {
var tooltipIdentifier = "div.tooltip-content", tooltipTag = $t.attr("class").match(/taggedttlink(-[^\s]+)/)
      if ($tfb.html() == "") $tfb.html('<div class="tooltip-content"><b>Error</b><br />This target either has no tooltip<br />or was not intended to have one.</div>');
if ($t.hasClass("versionsttlink")) tooltipIdentifier += activeVersionTag;
      $tfb.find(".tooltip-content").css("display", "");
else if (tooltipTag) tooltipIdentifier += tooltipTag[1];
      displayTip(e);
var url = "/index.php?title=" + encodeURIComponent(decodeURIComponent($t.data("tt"))) + "&action=render " + 'div[class*="tooltip-content"]';
    });
var tipId = url + " " + tooltipIdentifier;
  }
activeHoverLink = tipId;
$t.data('ahl-id', tipId);
if (tipCache[url] != null) return showTipFromCacheEntry(e, url, tooltipIdentifier);
$('<div style="display: none"/>').load(url, function(text) {
if (text == "") return; // Occurs when navigating away from the page cancels the XHR
tipCache[url] = $(this);
if (tipId != activeHoverLink) return;
showTipFromCacheEntry(e, url, tooltipIdentifier);
});
}
}
}


// quick tooltips
// quick tooltips
function hideTemplateTip() {
function hideTemplateTip() {
  $ttfb.html("").removeClass("tooltip-ready").addClass("hidden");
$ttfb.html("").removeClass("tooltip-ready").addClass("hidden");  
}
}


function showTemplateTip(e) {
function showTemplateTip(e) {
  $ttfb.html('<div class="tooltip-content">' + $(this).next().html() + '</div>');
$ttfb.html('<div class="tooltip-content">' + $(this).next().html() + '</div>');
  displayTip(e);
displayTip(e);
}
}


function ttBind() {
// add the tooltip calls to the page
  $t = $(this);
function bindTT() {
  $p = $t.parent();
$t=$(this);
  if ($p.hasClass("selflink") == false) {
$p=$t.parent();
    $t.data("tt", $p.attr("title").replace(" (page does not exist)", "").replace("?", "%3F")).mouseover(showTip).mouseout(hideTip).mousemove(moveTip);
if ($p.hasClass("selflink") == false) {
    if ($p.hasClass("new")) {
$t.data("tt", $p.attr("title").replace(" (page does not exist)","").replace("?","%3F")).hover(showTip,hideTip).mousemove(moveTip);
      els = '<sup><span class="plainlinks fromWikia">';
}
      y = ($t.hasClass("itemlink")) ? 0 : 1;
      z = ($t.hasClass("achievementlink")) ? 2 : 3;
      for (x = y; x < z; x++) els += eLink(x, $t.data("tt").replace("Quest:", ""));
      $p.after(els + '</span></sup>');
    }
    if (extDB != "http://www.asheron.wikia.com/") {
      fullextURL = extDB + $t.data("tt");
      $p.attr("href", fullextURL);
    }
  }
}
}


// check to see if it is active then do it
function tooltipsInit(root) {
function ttMouseOver(foo) {
if (!tooltipsOn) return;
  if (tooltipsOn && getCookie("wiki-tiploader") != "no") {
if ($tfb == null) {
    $("#WikiaArticle").mouseover(hideTip);
$(article).append('<div id="tfb" class="htt"></div><div id="templatetfb" class="htt"></div>');
    $("#WikiaArticle").append('<div id="tfb" class="htt"></div><div id="templatetfb" class="htt"><div>');
$tfb = $("#tfb");
    $tfb = $("#tfb");
$ttfb = $("#templatetfb");
    $ttfb = $("#templatetfb");
$htt = $("#tfb,#templatetfb");
    $htt = $("#tfb,#templatetfb");
}
    if (foo == 1) {
root.find(".ajaxoutertt > a").wrapInner('<span class="ajaxttlink" />');
      $("#WikiaArticle span.ajaxttlink").each(ttBind);
root.find(".ajaxoutertt, .ajaxoutertt-soft").each(function() {
    }
var cn = this.className.replace(/(?:^|\s)ajaxoutertt[^\s]*/, "").replace(/^\s+|\s+$/g, "");
    $("#WikiaArticle span.tttemplatelink").mouseover(showTemplateTip).mouseout(hideTemplateTip).mousemove(moveTip);
if (cn) $(this).find("span.ajaxttlink").addClass(cn);
  }
});
root.find("span.ajaxttlink").each(bindTT);
root.find("span.tttemplatelink").hover(showTemplateTip,hideTemplateTip).mousemove(moveTip);
}
}
$(function() {
  if(skin=='oasis') { article = '#WikiaMainContent'; }
  else { article = '#bodyContent'; }
tooltipsInit($(article));
});


/* --- Calculate PXP --- */
/* --- Calculate PXP --- */
Line 228: Line 230:
addOnloadHook(createPXPCalculationForms);
addOnloadHook(createPXPCalculationForms);


/* --- Collapsible Tables --- */
/** Collapsible tables *********************************************************
*
*  Description: Allows tables to be collapsed, showing only the header. See
*                        http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
*  Maintainers: [[en:User:R. Koot]]
*/
   
   
var autoCollapse = 2;
var autoCollapse = 2;
var collapseCaption = 'hide';
var collapseCaption = 'hide';
var expandCaption = 'show';
var expandCaption = 'show';
function hasClass( element, className ) {
var Classes = element.className.split( " " );
for ( var i = 0; i < Classes.length; i++ ) {
if ( Classes[i] == className ) {
return true;
}
}
return false;
}
   
   
function collapseTable( tableIndex ) {
function collapseTable( tableIndex ) {
var i;
        var Button = document.getElementById( 'collapseButton' + tableIndex );
var Button = document.getElementById( 'collapseButton' + tableIndex );
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
   
   
if ( !Table || !Button ) {
        if ( !Table || !Button ) {
return false;
                return false;
}
        }
   
   
var Rows = Table.getElementsByTagName( 'tr' );
        var Rows = Table.rows;
   
   
if ( Button.firstChild.data == collapseCaption ) {
        if ( Button.firstChild.data == collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
                for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
                        Rows[i].style.display = 'none';
}
                }
Button.firstChild.data = expandCaption;
                Button.firstChild.data = expandCaption;
} else {
        } else {
for ( i = 1; i < Rows.length; i++ ) {
                for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
                        Rows[i].style.display = Rows[0].style.display;
}
                }
Button.firstChild.data = collapseCaption;
                Button.firstChild.data = collapseCaption;
}
        }
}
}
   
   
function createCollapseButtons() {
function createCollapseButtons() {
var i;
        var tableIndex = 0;
var tableIndex = 0;
        var NavigationBoxes = new Object();
var NavigationBoxes = {};
        var Tables = document.getElementsByTagName( 'table' );
var Tables = document.getElementsByTagName( 'table' );
   
   
for ( i = 0; i < Tables.length; i++ ) {
        for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], 'collapsible' ) ) {
                if ( hasClass( Tables[i], 'collapsible' ) ) {
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
   
   
var Button = document.createElement( 'span' );
                        /* only add button and increment count if there is a header row to work with */
var ButtonLink = document.createElement( 'a' );
                        var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
var ButtonText = document.createTextNode( collapseCaption );
                        if ( !HeaderRow ) {
                                continue;
                        }
                        var Header = HeaderRow.getElementsByTagName( 'th' )[0];
                        if ( !Header ) {
                                continue;
                        }
   
   
Button.style.styleFloat = 'right';
                        NavigationBoxes[tableIndex] = Tables[i];
Button.style.cssFloat = 'right';
                        Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
Button.style.fontWeight = 'normal';
Button.style.textAlign = 'right';
Button.style.width = '6em';
   
   
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
                        var Button = document.createElement( 'span' );
ButtonLink.setAttribute( 'href', 'javascript:collapseTable(' + tableIndex + ');' );
                        var ButtonLink = document.createElement( 'a' );
ButtonLink.appendChild( ButtonText );
                        var ButtonText = document.createTextNode( collapseCaption );
   
   
Button.appendChild( document.createTextNode( '[' ) );
                        Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
   
   
var Header = Tables[i].getElementsByTagName( 'tr' )[0].getElementsByTagName( 'th' )[0];
                        ButtonLink.style.color = Header.style.color;
/* only add button and increment count if there is a header row to work with */
                        ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
if (Header) {
                        ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
Header.insertBefore( Button, Header.childNodes[0] );
                        ButtonLink.appendChild( ButtonText );
tableIndex++;
}
                        Button.appendChild( document.createTextNode( '[' ) );
}
                        Button.appendChild( ButtonLink );
}
                        Button.appendChild( document.createTextNode( ']' ) );
                        Header.insertBefore( Button, Header.childNodes[0] );
                        tableIndex++;
                }
        }
        for ( var i = 0;  i < tableIndex; i++ ) {
                if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
                        collapseTable( i );
                } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
                        var element = NavigationBoxes[i];
                        while ( element = element.parentNode ) {
                                if ( hasClass( element, 'outercollapse' ) ) {
                                        collapseTable( i );
                                        break;
                                }
                        }
                }
        }
}
/** Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*
* @deprecated:  Use $(element).hasClass() instead.
*/
var hasClass = ( function() {
        var reCache = {};
        return function( element, className ) {
                return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
        };
})();
/** Alternating table rows
*
*/
   
   
for ( i = 0; i < tableIndex; i++ ) {
/* alternating colors for table rows. */
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
function setAlternateRows(tbl, parseClass) {
collapseTable( i );
    rows = tbl.getElementsByTagName("tr");
}
    for (k = 1; k < rows.length; k++) {
}
        rows[k].className = (k % 2 == 0 ? "even" : "odd");
    }
    return;
}
/* To add a "pallet" for a table, simply modify the CASE argument and add the name
  of the CSS class that you want colors for. */
function alternateRows() {
    tbls = document.getElementsByTagName("table");
    for (i = 0; i < tbls.length; i++) {
        tbl = tbls[i];
        parseClasses = tbl.className.split(" ");
        for (j = 0; j < parseClasses.length; j++) {
            parseClass = parseClasses[j];
            switch( parseClass ) {
                case "altRows":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMed":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMed2":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsSmall":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMP":
                    setAlternateRows( tbl, parseClass );
                    break;
                default:
                    break;
            }
        }
    }
}
}
   
   
addOnloadHook( createCollapseButtons );
/* This code is executed on a pages after loading has finished */
$(function() {
createCollapseButtons();
alternateRows();
});

Latest revision as of 11:23, 5 July 2015

/* Any JavaScript here will be loaded for all users on every page load. */

// Duplicate image list
importScriptPage('DupImageList/code.js', 'dev'); 

/* --- Tooltips --- */
// default setting to turn tooltips on
var tooltipsOn = true;

var $tfb, $ttfb, $htt;
activeHoverLink = null;
tipCache = {};

// hides the tooltip
function hideTip() {
	$tfb.removeClass("tooltip-ready").addClass("hidden").css("visibility","hidden"); 
	$tfb.children().remove();
	if ($(this).data('ahl-id') == activeHoverLink) activeHoverLink = null;
}

// displays the tooltip
function displayTip(e) {
	$htt.not(":empty").removeClass("hidden").addClass("tooltip-ready");
	moveTip(e);
	$htt.not(":empty").css("visibility","visible");
	moveTip(e);
}

// moves the tooltip
function moveTip(e) {
	$ct = $htt.not(":empty");
	var eh = $ct.innerHeight() + 20, wh = $(window).height();
	var newTop = e.clientY + ((e.clientY > (wh/2)) ? -eh : 20);
	var newLeft = e.clientX + ((e.clientX > ($(window).width()/2)) ? -($ct.innerWidth()+20):20);
	newTop = Math.max(0, Math.min(wh - eh, newTop));

	$ct.css({"position":"fixed","top":newTop + "px","left":newLeft + "px"});
}

// AJAX tooltips
function showTipFromCacheEntry(e, url, tag) {
	var h = tipCache[url + " " + tag];
	if (!h) {
		h = tipCache[url].find(tag);
		if (h.length) tipCache[url + " " + tag] = h;
	}
	if (!h.length) {
		$tfb.html('<div class="tooltip-content"><b>Error</b><br />This target either has no tooltip<br />or was not intended to have one.</div>');
	} else {
		h.css("display", "").addClass("tooltip-content");
		$tfb.html(h);
	}
	displayTip(e);
}
function showTip(e) {
	var $t = $(this);
	$p = $t.parent();
	if ($p.hasClass("selflink") == false) {
                $t.removeAttr("title");
                $p.removeAttr("title");
		var tooltipIdentifier = "div.tooltip-content", tooltipTag = $t.attr("class").match(/taggedttlink(-[^\s]+)/)
		if ($t.hasClass("versionsttlink")) tooltipIdentifier += activeVersionTag;
		else if (tooltipTag) tooltipIdentifier += tooltipTag[1];
		var url = "/index.php?title=" + encodeURIComponent(decodeURIComponent($t.data("tt"))) + "&action=render " + 'div[class*="tooltip-content"]';
		var tipId = url + " " + tooltipIdentifier;
		activeHoverLink = tipId;
		$t.data('ahl-id', tipId);
		if (tipCache[url] != null) return showTipFromCacheEntry(e, url, tooltipIdentifier);
		$('<div style="display: none"/>').load(url, function(text) {
			if (text == "") return; // Occurs when navigating away from the page cancels the XHR
			tipCache[url] = $(this);
			if (tipId != activeHoverLink) return;
			showTipFromCacheEntry(e, url, tooltipIdentifier);
		});
	}
}

// quick tooltips
function hideTemplateTip() {
	$ttfb.html("").removeClass("tooltip-ready").addClass("hidden"); 
}

function showTemplateTip(e) {
	$ttfb.html('<div class="tooltip-content">' + $(this).next().html() + '</div>');
	displayTip(e);
}

// add the tooltip calls to the page
function bindTT() {
	$t=$(this);
	$p=$t.parent();
	if ($p.hasClass("selflink") == false) {
		$t.data("tt", $p.attr("title").replace(" (page does not exist)","").replace("?","%3F")).hover(showTip,hideTip).mousemove(moveTip);
	}
}

function tooltipsInit(root) {
	if (!tooltipsOn) return;
	if ($tfb == null) {
		$(article).append('<div id="tfb" class="htt"></div><div id="templatetfb" class="htt"></div>');
		$tfb = $("#tfb");
		$ttfb = $("#templatetfb");
		$htt = $("#tfb,#templatetfb");
	}
	root.find(".ajaxoutertt > a").wrapInner('<span class="ajaxttlink" />');
	root.find(".ajaxoutertt, .ajaxoutertt-soft").each(function() {
		var cn = this.className.replace(/(?:^|\s)ajaxoutertt[^\s]*/, "").replace(/^\s+|\s+$/g, "");
		if (cn) $(this).find("span.ajaxttlink").addClass(cn);
	});
	root.find("span.ajaxttlink").each(bindTT);
	root.find("span.tttemplatelink").hover(showTemplateTip,hideTemplateTip).mousemove(moveTip);
}

$(function() {
  if(skin=='oasis') { article = '#WikiaMainContent'; }
  else { article = '#bodyContent'; }
tooltipsInit($(article));
});

/* --- Calculate PXP --- */

function xp_at_level(level)
{
    if (level < 2)
        return 0;

    if (level == 2)
        return 1000;

    if (level <= 126)
        return Math.ceil((Math.pow((level + 5), 5) - Math.pow(6, 5)) / 9.0);

    return Math.round((Math.pow((level + 5), 5) - Math.pow(6, 5)) / 9.0);
}

function xp_to_next_level(level)
{
    if (level < 0 || level > 274)
        return 0;

    return xp_at_level(level + 1) - xp_at_level(level);
}

function percent_xp_to_next_level(level, percent)
{
    return Math.floor(xp_to_next_level(level) * percent / 100.0);
}

function format_xp(mystring)
{
    var result;
    var pos;

    mystring += '';
    if (mystring.length <= 3) {
        result = mystring;
    } else {
        var count = 0;
        result = "";
        for (pos = mystring.length - 3; pos >= 0 && count < 20; pos -= 3, count++) {
            if (result.length == 0)
                result = mystring.substr(pos, 3);
            else
                result = mystring.substr(pos, 3) + "," + result;
        }
        if (pos > -3)
            result = mystring.substr(0, 3+pos) + "," + result;
    }

    return result;
}

function calc_and_display_pxp(index)
{
    var level = parseInt(document.getElementById("pxp_level_input_" + index).value);
    var percent = parseFloat(document.getElementById("pxp_percent_input_" + index).value);

    document.getElementById("pxp_result_" + index).innerHTML = " = " + format_xp(percent_xp_to_next_level(level, percent));

    return false;
}

function hasClass(element, className)
{
    return element.className.indexOf(className) != -1;
}

function createPXPCalculationForms()
{
    var paras = document.getElementsByTagName("p");
    var offset = 0;

    for (var index = 0; index < paras.length; index++) {
        if (hasClass(paras[index], "calc-pxp")) {
            var form = document.createElement("form");
            var input1 = document.createElement("input");
            var input2 = document.createElement("input");
            var input3 = document.createElement("input");
            var span = document.createElement("span");

            form.setAttribute("onSubmit", "return calc_and_display_pxp(" + offset + ");");
            input1.setAttribute("size", "6");
            input1.setAttribute("value", "200");
            input1.setAttribute("id", "pxp_level_input_" + offset);

            input2.setAttribute("size", "6");
            input2.setAttribute("value", "10");
            input2.setAttribute("id", "pxp_percent_input_" + offset);

            input3.setAttribute("type", "button");
            input3.setAttribute("value", "Calculate PXP");
            input3.setAttribute("onclick", "javascript:calc_and_display_pxp(" + offset + ");");

            span.setAttribute("id", "pxp_result_" + offset);
            span.innerHTML = "??? xp";

            form.appendChild(document.createTextNode("Level: "));
            form.appendChild(input1);
            form.appendChild(document.createTextNode(" Percent: "));
            form.appendChild(input2);
            form.appendChild(input3);
            form.appendChild(span);

            paras[index].appendChild(form);
            offset++;
        }
    }
}

addOnloadHook(createPXPCalculationForms);

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *                         http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 *  Maintainers: [[en:User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
 
function collapseTable( tableIndex ) {
        var Button = document.getElementById( 'collapseButton' + tableIndex );
        var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
        if ( !Table || !Button ) {
                return false;
        }
 
        var Rows = Table.rows;
 
        if ( Button.firstChild.data == collapseCaption ) {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = 'none';
                }
                Button.firstChild.data = expandCaption;
        } else {
                for ( var i = 1; i < Rows.length; i++ ) {
                        Rows[i].style.display = Rows[0].style.display;
                }
                Button.firstChild.data = collapseCaption;
        }
}
 
function createCollapseButtons() {
        var tableIndex = 0;
        var NavigationBoxes = new Object();
        var Tables = document.getElementsByTagName( 'table' );
 
        for ( var i = 0; i < Tables.length; i++ ) {
                if ( hasClass( Tables[i], 'collapsible' ) ) {
 
                        /* only add button and increment count if there is a header row to work with */
                        var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
                        if ( !HeaderRow ) {
                                continue;
                        }
                        var Header = HeaderRow.getElementsByTagName( 'th' )[0];
                        if ( !Header ) {
                                continue;
                        }
 
                        NavigationBoxes[tableIndex] = Tables[i];
                        Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
 
                        var Button = document.createElement( 'span' );
                        var ButtonLink = document.createElement( 'a' );
                        var ButtonText = document.createTextNode( collapseCaption );
 
                        Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]
 
                        ButtonLink.style.color = Header.style.color;
                        ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
                        ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
                        ButtonLink.appendChild( ButtonText );
 
                        Button.appendChild( document.createTextNode( '[' ) );
                        Button.appendChild( ButtonLink );
                        Button.appendChild( document.createTextNode( ']' ) );
 
                        Header.insertBefore( Button, Header.childNodes[0] );
                        tableIndex++;
                }
        }
 
        for ( var i = 0;  i < tableIndex; i++ ) {
                if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
                        collapseTable( i );
                } else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {
                        var element = NavigationBoxes[i];
                        while ( element = element.parentNode ) {
                                if ( hasClass( element, 'outercollapse' ) ) {
                                        collapseTable( i );
                                        break;
                                }
                        }
                }
        }
}
 
/** Test if an element has a certain class **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 *
 * @deprecated:  Use $(element).hasClass() instead.
 */
 
var hasClass = ( function() {
        var reCache = {};
        return function( element, className ) {
                return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
        };
})();
 
 
/** Alternating table rows 
 *
 */
 
/* alternating colors for table rows. */
function setAlternateRows(tbl, parseClass) {
    rows = tbl.getElementsByTagName("tr");
    for (k = 1; k < rows.length; k++) {
        rows[k].className = (k % 2 == 0 ? "even" : "odd");
    }
    return;
}
/* To add a "pallet" for a table, simply modify the CASE argument and add the name
   of the CSS class that you want colors for. */
function alternateRows() {
    tbls = document.getElementsByTagName("table");
    for (i = 0; i < tbls.length; i++) {
        tbl = tbls[i];
        parseClasses = tbl.className.split(" ");
        for (j = 0; j < parseClasses.length; j++) {
            parseClass = parseClasses[j];
            switch( parseClass ) {
                case "altRows":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMed":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMed2":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsSmall":
                    setAlternateRows( tbl, parseClass );
                    break;
                case "altRowsMP":
                    setAlternateRows( tbl, parseClass );
                    break;
                default:
                    break;
            }
        }
    }
}
 
 
/* This code is executed on a pages after loading has finished */
$(function() {
	createCollapseButtons();
	alternateRows();
});