Difference between revisions of "MediaWiki:Common.js"

From LIMSWiki
Jump to navigationJump to search
(Removed secondary script call.)
 
(22 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/*
Table sorting script  by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
Based on a script from http://www.kryogenix.org/code/browser/sorttable/.
Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html .


Copyright (c) 1997-2007 Stuart Langridge, Joost de Valk.
/* Return whether a particular class is used**************************************
* Description: Uses regular expressions and caching for better performance.
*/
var usesClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();


Version 1.5.7
/**
*/
* Collapsible tables; reimplemented with mw-collapsible
* Styling is also in place to avoid FOUC
*
* Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
* @version 3.0.0 (2018-05-20)
* @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
* @author [[User:R. Koot]]
* @author [[User:Krinkle]]
* @author [[User:TheDJ]]
* @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
* is supported in MediaWiki core. Shimmable since MediaWiki 1.32
*/
function makeCollapsibleMwCollapsible( $content ) {
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );


/* You can change these values */
$.each( $tables, function( index, table ) {
var image_path = "http://www.joostdevalk.nl/code/sortable-table/";
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
var image_up = "arrow-up.gif";
if( $( table ).hasClass( 'collapsed') ) {
var image_down = "arrow-down.gif";
$( table ).addClass( 'mw-collapsed' );
var image_none = "arrow-none.gif";
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
var europeandate = false;
var alternate_row_colors = true;
 
/* Don't change anything below this unless you know what you're doing */
addEvent(window, "load", sortables_init);
 
var SORT_COLUMN_INDEX;
var thead = false;
 
function sortables_init() {
// Find all tables with class sortable and make them sortable
if (!document.getElementsByTagName) return;
tbls = document.getElementsByTagName("table");
for (ti=0;ti<tbls.length;ti++) {
thisTbl = tbls[ti];
if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
ts_makeSortable(thisTbl);
}
}
} );
if( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function() {
$tables.makeCollapsible();
} );
}
}
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );


function ts_makeSortable(t) {
/**
if (t.rows && t.rows.length > 0) {
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
if (t.tHead && t.tHead.rows.length > 0) {
*
var firstRow = t.tHead.rows[t.tHead.rows.length-1];
* Maintainers: TheDJ
thead = true;
*/
} else {
function mwCollapsibleSetup( $collapsibleContent ) {
var firstRow = t.rows[0];
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function (index, element) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find('tr:first > th:first').prepend( $element.find('tr:first > * > .mw-collapsible-toggle'));
}
}
}
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
if (!firstRow) return;
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
// We have a first row: assume it's the header, and make its contents clickable links
if ( $element.parents( '.outercollapse' ).length > 0 ) {
for (var i=0;i<firstRow.cells.length;i++) {
$element.data( 'mw-collapsible' ).collapse();
var cell = firstRow.cells[i];
}
var txt = ts_getInnerText(cell);
}
if (cell.className != "unsortable" && cell.className.indexOf("unsortable") == -1) {
// because of colored backgrounds, style the link in the text color
cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this, '+i+');return false;"><span class="sortarrow">&nbsp;&nbsp;<img src="'+ image_path + image_none + '" alt="&darr;"/></span></a>';
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if( $toggle.parent()[0].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
}
} );
}
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
var collapseCaption = 'hide';
var expandCaption = 'show';
// Set up the words in your language
var navigationBarHide = '[' + collapseCaption + ']';
var navigationBarShow = '[' + expandCaption + ']';
/**
* Shows and hides content and picture (if available) of navigation bars.
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled
* @param {jQuery.Event} event Event object
*/
function toggleNavigationBar( indexNavigationBar, event ) {
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var navChild;
if ( !navFrame || !navToggle ) {
return false;
}
}
if (alternate_row_colors) {
alternate(t);
}
}


function ts_getInnerText(el) {
// If shown now
if (typeof el == "string") return el;
if ( navToggle.firstChild.data === navigationBarHide ) {
if (typeof el == "undefined") { return el };
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if (el.innerText) return el.innerText; //Not needed but it is faster
if ( $( navChild ).hasClass( 'NavContent' ) ) {
var str = "";
navChild.style.display = 'none';
}
}
navToggle.firstChild.data = navigationBarShow;
var cs = el.childNodes;
// If hidden now
var l = cs.length;
} else if ( navToggle.firstChild.data === navigationBarShow ) {
for (var i = 0; i < l; i++) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
switch (cs[i].nodeType) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
case 1: //ELEMENT_NODE
navChild.style.display = 'block';
str += ts_getInnerText(cs[i]);
}
break;
case 3: //TEXT_NODE
str += cs[i].nodeValue;
break;
}
}
navToggle.firstChild.data = navigationBarHide;
}
}
return str;
 
event.preventDefault();
}
}


function ts_resortTable(lnk, clid) {
/**
var span;
* Adds show/hide-button to navigation bars.
for (var ci=0;ci<lnk.childNodes.length;ci++) {
*
if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
* @param {jQuery} $content
}
*/
var spantext = ts_getInnerText(span);
function createNavigationBarToggleButton( $content ) {
var td = lnk.parentNode;
var i, j, navChild, navToggle, navToggleText, isCollapsed,
var column = clid || td.cellIndex;
indexNavigationBar = 0;
var t = getParent(td,'TABLE');
// Iterate over all < div >-elements
// Work out a type for the column
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
if (t.rows.length <= 1) return;
$divs.each( function ( i, navFrame ) {
var itm = "";
indexNavigationBar++;
var i = 0;
navToggle = document.createElement( 'a' );
while (itm == "" && i < t.tBodies[0].rows.length) {
navToggle.className = 'NavToggle';
var itm = ts_getInnerText(t.tBodies[0].rows[i].cells[column]);
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
itm = trim(itm);
navToggle.setAttribute( 'href', '#' );
if (itm.substr(0,4) == "<!--" || itm.length == 0) {
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
itm = "";
 
isCollapsed = $( navFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden.  This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
if ( navChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
}
i++;
if ( isCollapsed ) {
}
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if (itm == "") return;
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
sortfn = ts_sort_caseinsensitive;
navChild.style.display = 'none';
if (itm.match(/^\d\d[\/\.-][a-zA-z][a-zA-Z][a-zA-Z][\/\.-]\d\d\d\d$/)) sortfn = ts_sort_date;
}
if (itm.match(/^\d\d[\/\.-]\d\d[\/\.-]\d\d\d{2}?$/)) sortfn = ts_sort_date;
if (itm.match(/^-?[£$€Û¢´]\d/)) sortfn = ts_sort_numeric;
if (itm.match(/^-?(\d+[,\.]?)+(E[-+][\d]+)?%?$/)) sortfn = ts_sort_numeric;
SORT_COLUMN_INDEX = column;
var firstRow = new Array();
var newRows = new Array();
for (k=0;k<t.tBodies.length;k++) {
for (i=0;i<t.tBodies[k].rows[0].length;i++) {
firstRow[i] = t.tBodies[k].rows[0][i];
}
}
for (k=0;k<t.tBodies.length;k++) {
if (!thead) {
// Skip the first row
for (j=1;j<t.tBodies[k].rows.length;j++) {  
newRows[j-1] = t.tBodies[k].rows[j];
}
} else {
// Do NOT skip the first row
for (j=0;j<t.tBodies[k].rows.length;j++) {
newRows[j] = t.tBodies[k].rows[j];
}
}
}
}
}
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
newRows.sort(sortfn);
navToggle.appendChild( navToggleText );
if (span.getAttribute("sortdir") == 'down') {
 
ARROW = '&nbsp;&nbsp;<img src="'+ image_path + image_down + '" alt="&darr;"/>';
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
newRows.reverse();
for ( j = 0; j < navFrame.childNodes.length; j++ ) {
span.setAttribute('sortdir','up');
if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
} else {
navToggle.style.color = navFrame.childNodes[j].style.color;
ARROW = '&nbsp;&nbsp;<img src="'+ image_path + image_up + '" alt="&uarr;"/>';
navFrame.childNodes[j].appendChild( navToggle );
span.setAttribute('sortdir','down');
}
    // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
    // don't do sortbottom rows
    for (i=0; i<newRows.length; i++) {  
if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) {
t.tBodies[0].appendChild(newRows[i]);
}
}
    // do sortbottom rows only
    for (i=0; i<newRows.length; i++) {
if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1))
t.tBodies[0].appendChild(newRows[i]);
}
// Delete any other arrows there may be showing
var allspans = document.getElementsByTagName("span");
for (var ci=0;ci<allspans.length;ci++) {
if (allspans[ci].className == 'sortarrow') {
if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
allspans[ci].innerHTML = '&nbsp;&nbsp;<img src="'+ image_path + image_none + '" alt="&darr;"/>';
}
}
}
}
}
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
span.innerHTML = ARROW;
} );
alternate(t);
}
}


function getParent(el, pTagName) {
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
if (el == null) {
 
return null;
/* JavaScript for rounding borders
} else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {
  Source: http://webdesign.html.it/articoli/leggi/528/more-nifty-corners */
return el;
 
} else {
function NiftyCheck(){
return getParent(el.parentNode, pTagName);
if(!document.getElementById || !document.createElement)
}
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}
}


function sort_date(date) {
function Rounded(selector, wich, bk, color, opt) {
// y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
    var i, prefixt, prefixb, cn = "r", ecolor = "", edges = !1, eclass = "", b = !1, t = !1;
dt = "00000000";
    if (color == "transparent") {
if (date.length == 11) {
        cn = cn + "x";
mtstr = date.substr(3,3);
        ecolor = bk;
mtstr = mtstr.toLowerCase();
        bk = "transparent";
switch(mtstr) {
    } else if (opt && opt.indexOf("border") >= 0) {
case "jan": var mt = "01"; break;
        var optar = opt.split(" ");
case "feb": var mt = "02"; break;
        for (i = 0; i < optar.length; i++)
case "mar": var mt = "03"; break;
            if (optar[i].indexOf("#") >= 0)
case "apr": var mt = "04"; break;
                ecolor = optar[i];
case "may": var mt = "05"; break;
        if (ecolor == "")
case "jun": var mt = "06"; break;
            ecolor = "#666";
case "jul": var mt = "07"; break;
        cn += "e";
case "aug": var mt = "08"; break;
        edges = !0;
case "sep": var mt = "09"; break;
    } else if (opt && opt.indexOf("smooth") >= 0) {
case "oct": var mt = "10"; break;
        cn += "a";
case "nov": var mt = "11"; break;
        ecolor = Mix(bk, color);
case "dec": var mt = "12"; break;
    }
// default: var mt = "00";
    if (opt && opt.indexOf("small") >= 0)
}
        cn += "s";
dt = date.substr(7,4)+mt+date.substr(0,2);
    prefixt = cn;
return dt;
    prefixb = cn;
} else if (date.length == 10) {
    if (wich.indexOf("all") >= 0) {
if (europeandate == false) {
        t = !0;
dt = date.substr(6,4)+date.substr(0,2)+date.substr(3,2);
        b = !0;
return dt;
    } else if (wich.indexOf("top") >= 0)
} else {
        t = "true";
dt = date.substr(6,4)+date.substr(3,2)+date.substr(0,2);
    else if (wich.indexOf("tl") >= 0) {
return dt;
        t = "true";
}
        if (wich.indexOf("tr") < 0)
} else if (date.length == 8) {
            prefixt += "l";
yr = date.substr(6,2);
    } else if (wich.indexOf("tr") >= 0) {
if (parseInt(yr) < 50) {
        t = "true";
yr = '20'+yr;  
        prefixt += "r";
} else {  
    }
yr = '19'+yr;  
    if (wich.indexOf("bottom") >= 0)
}
        b = !0;
if (europeandate == true) {
    else if (wich.indexOf("bl") >= 0) {
dt = yr+date.substr(3,2)+date.substr(0,2);
        b = "true";
return dt;
        if (wich.indexOf("br") < 0)
} else {
            prefixb += "l";
dt = yr+date.substr(0,2)+date.substr(3,2);
    } else if (wich.indexOf("br") >= 0) {
return dt;
        b = "true";
}
        prefixb += "r";
}
    }
return dt;
    var v = getElementsBySelector(selector);
    var l = v.length;
    for (i = 0; i < l; i++) {
        if (edges)
            AddBorder(v[i], ecolor);
        if (t)
            AddTop(v[i], bk, color, ecolor, prefixt);
        if (b)
            AddBottom(v[i], bk, color, ecolor, prefixb);
    }
}
function AddBorder(el, bc) {
    var i;
    if (!el.passed) {
        if (el.childNodes.length == 1 && el.childNodes[0].nodeType == 3) {
            var t = el.firstChild.nodeValue;
            el.removeChild(el.lastChild);
            var d = CreateEl("span");
            d.style.display = "block";
            d.appendChild(document.createTextNode(t));
            el.appendChild(d);
        }
        for (i = 0; i < el.childNodes.length; i++) {
            if (el.childNodes[i].nodeType == 1) {
                el.childNodes[i].style.borderLeft = "1px solid " + bc;
                el.childNodes[i].style.borderRight = "1px solid " + bc;
            }
        }
    }
    el.passed = !0;
}
}
 
function AddTop(el, bk, color, bc, cn) {
function ts_sort_date(a,b) {
    var i, lim = 4, d = CreateEl("b");
dt1 = sort_date(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
    if (cn.indexOf("s") >= 0)
dt2 = sort_date(ts_getInnerText(b.cells[SORT_COLUMN_INDEX]));
        lim = 2;
    if (bc)
if (dt1==dt2) {
        d.className = "artop";
return 0;
    else
}
        d.className = "rtop";
if (dt1<dt2) {
    d.style.backgroundColor = bk;
return -1;
    for (i = 1; i <= lim; i++) {
}
        var x = CreateEl("b");
return 1;
        x.className = cn + i;
        x.style.backgroundColor = color;
        if (bc)
            x.style.borderColor = bc;
        d.appendChild(x);
    }
    el.style.paddingTop = 0;
    el.insertBefore(d, el.firstChild);
}
}
function ts_sort_numeric(a,b) {
function AddBottom(el, bk, color, bc, cn) {
var aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    var i, lim = 4, d = CreateEl("b");
aa = clean_num(aa);
    if (cn.indexOf("s") >= 0)
var bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
        lim = 2;
bb = clean_num(bb);
    if (bc)
return compare_numeric(aa,bb);
        d.className = "artop";
    else
        d.className = "rtop";
    d.style.backgroundColor = bk;
    for (i = lim; i > 0; i--) {
        var x = CreateEl("b");
        x.className = cn + i;
        x.style.backgroundColor = color;
        if (bc)
            x.style.borderColor = bc;
        d.appendChild(x);
    }
    el.style.paddingBottom = 0;
    el.appendChild(d);
}
}
function compare_numeric(a,b) {
function CreateEl(x) {
var a = parseFloat(a);
    if (isXHTML)
a = (isNaN(a) ? 0 : a);
        return (document.createElementNS('http://www.w3.org/1999/xhtml', x));
var b = parseFloat(b);
    else
b = (isNaN(b) ? 0 : b);
        return (document.createElement(x));
return a - b;
}
}
function ts_sort_caseinsensitive(a,b) {
function getElementsBySelector(selector) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
    var i, selid = "", selclass = "", tag = selector, f, s = [], objlist = [];
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
    if (selector.indexOf(" ") > 0) {
if (aa==bb) {
        s = selector.split(" ");
return 0;
        var fs = s[0].split("#");
}
        if (fs.length == 1)
if (aa<bb) {
            return (objlist);
return -1;
        f = document.getElementById(fs[1]);
}
        if (f)
return 1;
            return (f.getElementsByTagName(s[1]));
        return (objlist);
    }
    if (selector.indexOf("#") > 0) {
        s = selector.split("#");
        tag = s[0];
        selid = s[1];
    }
    if (selid != "") {
        f = document.getElementById(selid);
        if (f)
            objlist.push(f);
        return (objlist);
    }
    if (selector.indexOf(".") > 0) {
        s = selector.split(".");
        tag = s[0];
        selclass = s[1];
    }
    var v = document.getElementsByTagName(tag);
    if (selclass == "")
        return (v);
    for (i = 0; i < v.length; i++) {
        if (v[i].className.indexOf(selclass) >= 0) {
            objlist.push(v[i]);
        }
    }
    return (objlist);
}
}
function ts_sort_default(a,b) {
function Mix(c1, c2) {
aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
    var i, step1, step2, x, y, r = new Array(3);
bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
    if (c1.length == 4)
if (aa==bb) {
        step1 = 1;
return 0;
    else
}
        step1 = 2;
if (aa<bb) {
    if (c2.length == 4)
return -1;
        step2 = 1;
}
    else
return 1;
        step2 = 2;
    for (i = 0; i < 3; i++) {
        x = parseInt(c1.substr(1 + step1 * i, step1), 16);
        if (step1 == 1)
            x = 16 * x + x;
        y = parseInt(c2.substr(1 + step2 * i, step2), 16);
        if (step2 == 1)
            y = 16 * y + y;
        r[i] = Math.floor((x * 50 + y * 50) / 100);
    }
    return ("#" + r[0].toString(16) + r[1].toString(16) + r[2].toString(16));
}
}
function addEvent(elm, evType, fn, useCapture)
function doRoundEdges() {
// addEvent and removeEvent
    if (!NiftyCheck())
// cross-browser event handling for IE5+, NS6 and Mozilla
        return;
// By Scott Andrew
    Rounded("div#nifty", "all", "#FFF", "#D4DDFF", "smooth");
{
if (elm.addEventListener){
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent){
var r = elm.attachEvent("on"+evType, fn);
return r;
} else {
alert("Handler could not be removed");
}
}
}
function clean_num(str) {
jQuery(doRoundEdges);
str = str.replace(new RegExp(/[^-?0-9.]/g),"");
function setStyleById(i, p, v) {
return str;
    var n = document.getElementById(i);
    n.style[p] = v;
}
}
function trim(s) {
jQuery(performIE);
return s.replace(/^\s+|\s+$/g, "");
function performIE() {
    if (-1 != navigator.userAgent.indexOf("MSIE")) {
        var Divs = document.getElementsByTagName("div");
        var divCnt = 0;
        var divID = "";
        if (Divs.length > 0) {
            var CurrDiv = Divs[0];
            var s = "";
            while (Divs.length > divCnt) {
                s = eval("CurrDiv.style.ietop");
                if ((s != "") && (s != null)) {
                    divID = "mapDiv" + divCnt;
                    CurrDiv.setAttribute("id", divID);
                    setStyleById(divID, "top", CurrDiv.style.ietop);
                }
                divCnt++;
                CurrDiv = Divs[divCnt];
            }
        }
    }
}
}
function alternate(table) {
// Take object table and get all it's tbodies.
/**
var tableBodies = table.getElementsByTagName("tbody");
* Dynamic Navigation Bars (experimental)
// Loop through these tbodies
*
for (var i = 0; i < tableBodies.length; i++) {
* Description: See [[Wikipedia:NavFrame]].
// Take the tbody, and get all it's rows
* Maintainers: UNMAINTAINED
var tableRows = tableBodies[i].getElementsByTagName("tr");
*/
// Loop through these rows
 
// Start at 1 because we want to leave the heading row untouched
/* set up the words in your language */
for (var j = 0; j < tableRows.length; j++) {
var NavigationBarHide = '[' + collapseCaption + ']';
// Check if j is even, and apply classes for both possible results
var NavigationBarShow = '[' + expandCaption + ']';
if ( (j % 2) == ) {
var indexNavigationBar = 0;
if ( !(tableRows[j].className.indexOf('odd') == -1) ) {
 
tableRows[j].className = tableRows[j].className.replace('odd', 'even');
/**
} else {
* Shows and hides content and picture (if available) of navigation bars
if ( tableRows[j].className.indexOf('even') == -1 ) {
* Parameters:
tableRows[j].className += " even";
*    indexNavigationBar: the index of navigation bar to be toggled
}
**/
}
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
} else {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
if ( !(tableRows[j].className.indexOf('even') == -1) ) {
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
tableRows[j].className = tableRows[j].className.replace('even', 'odd');
    var NavChild;
} else {
 
if ( tableRows[j].className.indexOf('odd') == -1 ) {
    if ( !NavFrame || !NavToggle ) {
tableRows[j].className += " odd";
        return false;
}
    }
}
 
}
    /* if shown now */
}
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
}
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
 
    event.preventDefault();
};
 
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
    var NavChild;
    /* iterate over all < div >-elements */
    var $divs = $content.find( 'div' );
    $divs.each( function ( i, NavFrame ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
 
            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
            /**
            * Check if any children are already hidden. This loop is here for backwards compatibility:
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
            * the content visible without JavaScript support), the new recommended way is to add the class
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
            */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );
 
            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    } );
}
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
/* Tweak to get CategoryTree extension to have trees expanded by default */
$( document ).ready(function() { $('.CategoryTreeToggle[data-ct-state="collapsed"]').click(); });

Latest revision as of 18:12, 3 August 2021

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

/* Return whether a particular class is used**************************************
 * Description: Uses regular expressions and caching for better performance.
 */
 
 var usesClass = (function () {
     var reCache = {};
     return function (element, className) {
         return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
     };
 })();

/**
 * Collapsible tables; reimplemented with mw-collapsible
 * Styling is also in place to avoid FOUC
 * 
 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
 * @version 3.0.0 (2018-05-20)
 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 * @author [[User:R. Koot]]
 * @author [[User:Krinkle]]
 * @author [[User:TheDJ]]
 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
 */
function makeCollapsibleMwCollapsible( $content ) {
	var $tables = $content
		.find( 'table.collapsible:not(.mw-collapsible)' )
		.addClass( 'mw-collapsible' );

	$.each( $tables, function( index, table ) {
		// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
		if( $( table ).hasClass( 'collapsed') ) {
			$( table ).addClass( 'mw-collapsed' );
			// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
		}
	} );
	if( $tables.length > 0 ) {
		mw.loader.using( 'jquery.makeCollapsible' ).then( function() {
			$tables.makeCollapsible();
		} );
	}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );

/**
 * Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
 *
 * Maintainers: TheDJ
 */
function mwCollapsibleSetup( $collapsibleContent ) {
	var $element,
		$toggle,
		autoCollapseThreshold = 2;
	$.each( $collapsibleContent, function (index, element) {
		$element = $( element );
		if ( $element.hasClass( 'collapsible' ) ) {
			$element.find('tr:first > th:first').prepend( $element.find('tr:first > * > .mw-collapsible-toggle'));
		}
		if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
			$element.data( 'mw-collapsible' ).collapse();
		} else if ( $element.hasClass( 'innercollapse' ) ) {
			if ( $element.parents( '.outercollapse' ).length > 0 ) {
				$element.data( 'mw-collapsible' ).collapse();
			}
		}
		// because of colored backgrounds, style the link in the text color
		// to ensure accessible contrast
		$toggle = $element.find( '.mw-collapsible-toggle' );
		if ( $toggle.length ) {
			// Make the toggle inherit text color
			if( $toggle.parent()[0].style.color ) {
				$toggle.find( 'a' ).css( 'color', 'inherit' );
			}
		}
	} );
}

mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */
 
var collapseCaption = 'hide';
var expandCaption = 'show';

// Set up the words in your language
var navigationBarHide = '[' + collapseCaption + ']';
var navigationBarShow = '[' + expandCaption + ']';

/**
 * Shows and hides content and picture (if available) of navigation bars.
 *
 * @param {number} indexNavigationBar The index of navigation bar to be toggled
 * @param {jQuery.Event} event Event object
 */
function toggleNavigationBar( indexNavigationBar, event ) {
	var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
	var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
	var navChild;

	if ( !navFrame || !navToggle ) {
		return false;
	}

	// If shown now
	if ( navToggle.firstChild.data === navigationBarHide ) {
		for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavContent' ) ) {
				navChild.style.display = 'none';
			}
		}
		navToggle.firstChild.data = navigationBarShow;
	
	// If hidden now
	} else if ( navToggle.firstChild.data === navigationBarShow ) {
		for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavContent' ) ) {
				navChild.style.display = 'block';
			}
		}
		navToggle.firstChild.data = navigationBarHide;
	}

	event.preventDefault();
}

/**
 * Adds show/hide-button to navigation bars.
 *
 * @param {jQuery} $content
 */
function createNavigationBarToggleButton( $content ) {
	var i, j, navChild, navToggle, navToggleText, isCollapsed,
		indexNavigationBar = 0;
	// Iterate over all < div >-elements
	var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
	$divs.each( function ( i, navFrame ) {
		indexNavigationBar++;
		navToggle = document.createElement( 'a' );
		navToggle.className = 'NavToggle';
		navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
		navToggle.setAttribute( 'href', '#' );
		$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );

		isCollapsed = $( navFrame ).hasClass( 'collapsed' );
		/**
		 * Check if any children are already hidden.  This loop is here for backwards compatibility:
		 * the old way of making NavFrames start out collapsed was to manually add style="display:none"
		 * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
		 * the content visible without JavaScript support), the new recommended way is to add the class
		 * "collapsed" to the NavFrame itself, just like with collapsible tables.
		 */
		for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
				if ( navChild.style.display === 'none' ) {
					isCollapsed = true;
				}
			}
		}
		if ( isCollapsed ) {
			for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
					navChild.style.display = 'none';
				}
			}
		}
		navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
		navToggle.appendChild( navToggleText );

		// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
		for ( j = 0; j < navFrame.childNodes.length; j++ ) {
			if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
				navToggle.style.color = navFrame.childNodes[j].style.color;
				navFrame.childNodes[j].appendChild( navToggle );
			}
		}
		navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
	} );
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/* JavaScript for rounding borders
   Source: http://webdesign.html.it/articoli/leggi/528/more-nifty-corners */

function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector, wich, bk, color, opt) {
    var i, prefixt, prefixb, cn = "r", ecolor = "", edges = !1, eclass = "", b = !1, t = !1;
    if (color == "transparent") {
        cn = cn + "x";
        ecolor = bk;
        bk = "transparent";
    } else if (opt && opt.indexOf("border") >= 0) {
        var optar = opt.split(" ");
        for (i = 0; i < optar.length; i++)
            if (optar[i].indexOf("#") >= 0)
                ecolor = optar[i];
        if (ecolor == "")
            ecolor = "#666";
        cn += "e";
        edges = !0;
    } else if (opt && opt.indexOf("smooth") >= 0) {
        cn += "a";
        ecolor = Mix(bk, color);
    }
    if (opt && opt.indexOf("small") >= 0)
        cn += "s";
    prefixt = cn;
    prefixb = cn;
    if (wich.indexOf("all") >= 0) {
        t = !0;
        b = !0;
    } else if (wich.indexOf("top") >= 0)
        t = "true";
    else if (wich.indexOf("tl") >= 0) {
        t = "true";
        if (wich.indexOf("tr") < 0)
            prefixt += "l";
    } else if (wich.indexOf("tr") >= 0) {
        t = "true";
        prefixt += "r";
    }
    if (wich.indexOf("bottom") >= 0)
        b = !0;
    else if (wich.indexOf("bl") >= 0) {
        b = "true";
        if (wich.indexOf("br") < 0)
            prefixb += "l";
    } else if (wich.indexOf("br") >= 0) {
        b = "true";
        prefixb += "r";
    }
    var v = getElementsBySelector(selector);
    var l = v.length;
    for (i = 0; i < l; i++) {
        if (edges)
            AddBorder(v[i], ecolor);
        if (t)
            AddTop(v[i], bk, color, ecolor, prefixt);
        if (b)
            AddBottom(v[i], bk, color, ecolor, prefixb);
    }
}
function AddBorder(el, bc) {
    var i;
    if (!el.passed) {
        if (el.childNodes.length == 1 && el.childNodes[0].nodeType == 3) {
            var t = el.firstChild.nodeValue;
            el.removeChild(el.lastChild);
            var d = CreateEl("span");
            d.style.display = "block";
            d.appendChild(document.createTextNode(t));
            el.appendChild(d);
        }
        for (i = 0; i < el.childNodes.length; i++) {
            if (el.childNodes[i].nodeType == 1) {
                el.childNodes[i].style.borderLeft = "1px solid " + bc;
                el.childNodes[i].style.borderRight = "1px solid " + bc;
            }
        }
    }
    el.passed = !0;
}
function AddTop(el, bk, color, bc, cn) {
    var i, lim = 4, d = CreateEl("b");
    if (cn.indexOf("s") >= 0)
        lim = 2;
    if (bc)
        d.className = "artop";
    else
        d.className = "rtop";
    d.style.backgroundColor = bk;
    for (i = 1; i <= lim; i++) {
        var x = CreateEl("b");
        x.className = cn + i;
        x.style.backgroundColor = color;
        if (bc)
            x.style.borderColor = bc;
        d.appendChild(x);
    }
    el.style.paddingTop = 0;
    el.insertBefore(d, el.firstChild);
}
function AddBottom(el, bk, color, bc, cn) {
    var i, lim = 4, d = CreateEl("b");
    if (cn.indexOf("s") >= 0)
        lim = 2;
    if (bc)
        d.className = "artop";
    else
        d.className = "rtop";
    d.style.backgroundColor = bk;
    for (i = lim; i > 0; i--) {
        var x = CreateEl("b");
        x.className = cn + i;
        x.style.backgroundColor = color;
        if (bc)
            x.style.borderColor = bc;
        d.appendChild(x);
    }
    el.style.paddingBottom = 0;
    el.appendChild(d);
}
function CreateEl(x) {
    if (isXHTML)
        return (document.createElementNS('http://www.w3.org/1999/xhtml', x));
    else
        return (document.createElement(x));
}
function getElementsBySelector(selector) {
    var i, selid = "", selclass = "", tag = selector, f, s = [], objlist = [];
    if (selector.indexOf(" ") > 0) {
        s = selector.split(" ");
        var fs = s[0].split("#");
        if (fs.length == 1)
            return (objlist);
        f = document.getElementById(fs[1]);
        if (f)
            return (f.getElementsByTagName(s[1]));
        return (objlist);
    }
    if (selector.indexOf("#") > 0) {
        s = selector.split("#");
        tag = s[0];
        selid = s[1];
    }
    if (selid != "") {
        f = document.getElementById(selid);
        if (f)
            objlist.push(f);
        return (objlist);
    }
    if (selector.indexOf(".") > 0) {
        s = selector.split(".");
        tag = s[0];
        selclass = s[1];
    }
    var v = document.getElementsByTagName(tag);
    if (selclass == "")
        return (v);
    for (i = 0; i < v.length; i++) {
        if (v[i].className.indexOf(selclass) >= 0) {
            objlist.push(v[i]);
        }
    }
    return (objlist);
}
function Mix(c1, c2) {
    var i, step1, step2, x, y, r = new Array(3);
    if (c1.length == 4)
        step1 = 1;
    else
        step1 = 2;
    if (c2.length == 4)
        step2 = 1;
    else
        step2 = 2;
    for (i = 0; i < 3; i++) {
        x = parseInt(c1.substr(1 + step1 * i, step1), 16);
        if (step1 == 1)
            x = 16 * x + x;
        y = parseInt(c2.substr(1 + step2 * i, step2), 16);
        if (step2 == 1)
            y = 16 * y + y;
        r[i] = Math.floor((x * 50 + y * 50) / 100);
    }
    return ("#" + r[0].toString(16) + r[1].toString(16) + r[2].toString(16));
}
function doRoundEdges() {
    if (!NiftyCheck())
        return;
    Rounded("div#nifty", "all", "#FFF", "#D4DDFF", "smooth");
}
jQuery(doRoundEdges);
function setStyleById(i, p, v) {
    var n = document.getElementById(i);
    n.style[p] = v;
}
jQuery(performIE);
function performIE() {
    if (-1 != navigator.userAgent.indexOf("MSIE")) {
        var Divs = document.getElementsByTagName("div");
        var divCnt = 0;
        var divID = "";
        if (Divs.length > 0) {
            var CurrDiv = Divs[0];
            var s = "";
            while (Divs.length > divCnt) {
                s = eval("CurrDiv.style.ietop");
                if ((s != "") && (s != null)) {
                    divID = "mapDiv" + divCnt;
                    CurrDiv.setAttribute("id", divID);
                    setStyleById(divID, "top", CurrDiv.style.ietop);
                }
                divCnt++;
                CurrDiv = Divs[divCnt];
            }
        }
    }
}
 
/**
 * Dynamic Navigation Bars (experimental)
 *
 * Description: See [[Wikipedia:NavFrame]].
 * Maintainers: UNMAINTAINED
 */

/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var indexNavigationBar = 0;

/**
 * Shows and hides content and picture (if available) of navigation bars
 * Parameters:
 *     indexNavigationBar: the index of navigation bar to be toggled
 **/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;

    if ( !NavFrame || !NavToggle ) {
        return false;
    }

    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;

    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }

    event.preventDefault();
};

/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
    var NavChild;
    /* iterate over all < div >-elements */
    var $divs = $content.find( 'div' );
    $divs.each( function ( i, NavFrame ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {

            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );

            var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
            /**
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
            NavToggle.appendChild( NavToggleText );

            /* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
            for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    } );
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

/* Tweak to get CategoryTree extension to have trees expanded by default */
$( document ).ready(function() { $('.CategoryTreeToggle[data-ct-state="collapsed"]').click(); });