Difference between revisions of "MediaWiki:Common.js"

From LIMSWiki
Jump to navigationJump to search
(Removed secondary script call.)
 
(24 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. */
/*
SortTable
  version 2.1
  7th April 2007
  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/


  19 Feb 2008
/* Return whether a particular class is used**************************************
  Fixed some jslint errors to support DokuWiki (http://www.splitbrain.org) js compression
* 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);
    };
})();


  function reinitsort()
/**
  sorttable.reinit
* Collapsible tables; reimplemented with mw-collapsible
  added by Otto Vainio to allow sort tables updated with javascript.
* Styling is also in place to avoid FOUC
  Otto Vainio (otto@valjakko.net)
*
* 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' );


  27.11.2008
$.each( $tables, function( index, table ) {
  Changed line 77 document.getElementsByTagName('table') to div.getElementsByTagName('table')
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
  To allow multiple sortable tables in same page
if( $( table ).hasClass( 'collapsed') ) {
  (Thanks to Hans Sampiemon)
$( 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 );


  14.1.2009
/**
  Added option for default sorting.
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
  Use dokuwiki event registration.
*
* 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' );
}
}
} );
}


  27.1.2009
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
  Cleaned some jlint errors to make this workable, when css+js compress is set in dokuwiki


  10.5.2011
/**
  * version 2.5 Fixed problems with secionediting, footnotes and edittable
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
  * Maintainers: UNMAINTAINED
*/
var collapseCaption = 'hide';
var expandCaption = 'show';


  Instructions:
// Set up the words in your language
  Used from dokuwiki
var navigationBarHide = '[' + collapseCaption + ']';
  Click on the headers to sort
var navigationBarShow = '[' + expandCaption + ']';
 
  Thanks to many, many people for contributions and suggestions.
  Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
  This basically means: do what you want with it.
*/
var stIsIE = /*@cc_on!@*/false;
var tableid = 0;


sorttable = {
/**
  reinit: function() {
* Shows and hides content and picture (if available) of navigation bars.
    arguments.callee.done = true;
*
    // kill the timer
* @param {number} indexNavigationBar The index of navigation bar to be toggled
    if (_timer) {clearInterval(_timer);}
* @param {jQuery.Event} event Event object
   
*/
    if (!document.createElement || !document.getElementsByTagName) {return;}
function toggleNavigationBar( indexNavigationBar, event ) {
   
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
//    sorttable.DATE_RE = /^(\d\d?)[\/\.\-](\d\d?)[\/\.\-]((\d\d)?\d\d)$/;
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    sorttable.DATE_RE = /^(\d\d?)[\/\.\-](\d\d?)[\/\.\-]((\d\d)?\d\d)( (\d\d?)[:\.]?(\d\d?))?$/;
var navChild;


   
if ( !navFrame || !navToggle ) {
    forEach(document.getElementsByTagName('table'), function(table) {
return false;
      if (table.className.search(/\bsortable\b/) != -1) {
}
        sorttable.makeSortable(table);
      }
    });
    forEach(document.getElementsByTagName('div'), function(div) {
      if (div.className.search(/\bsortable\b/) != -1) {
        sorttable.makeSortablediv(div);
      }
    });
  },


  init: function() {
// If shown now
    // quit if this function has already been called
if ( navToggle.firstChild.data === navigationBarHide ) {
    if (arguments.callee.done) {return;}
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
    // flag this function so we don't do the same thing twice
if ( $( navChild ).hasClass( 'NavContent' ) ) {
    arguments.callee.done = true;
navChild.style.display = 'none';
    // kill the timer
}
    if (_timer) {clearInterval(_timer);}
}
   
navToggle.firstChild.data = navigationBarShow;
    if (!document.createElement || !document.getElementsByTagName) {return;}
   
// If hidden now
//    sorttable.DATE_RE = /^(\d\d?)[\/\.\-](\d\d?)[\/\.\-]((\d\d)?\d\d)$/;
} else if ( navToggle.firstChild.data === navigationBarShow ) {
    sorttable.DATE_RE = /^(\d\d?)[\/\.\-](\d\d?)[\/\.\-]((\d\d)?\d\d)( (\d\d?):?(\d\d?))?$/;
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
   
if ( $( navChild ).hasClass( 'NavContent' ) ) {
    forEach(document.getElementsByTagName('table'), function(table) {
navChild.style.display = 'block';
      if (table.className.search(/\bsortable\b/) != -1) {
}
        sorttable.makeSortable(table);
}
      }
navToggle.firstChild.data = navigationBarHide;
    });
}
    forEach(document.getElementsByTagName('div'), function(div) {
      if (div.className.search(/\bsortable\b/) != -1) {
        sorttable.makeSortablediv(div);
      }
    });
   
  },
  makeSortablediv: function(div) {
        if (div.getElementsByTagName('table').length === 0) {
        } else {
          forEach(div.getElementsByTagName('table'), function(table) {
            colid=div.className;
            overs = new Array();
            var patt1=/\bcol_\d_[a-z]+/gi;
            var overs = new Array();
            if (colid.search(patt1) != -1) {
              var overrides = new Array();
              overrides = colid.match(patt1);
              var xo="";
              for (xo in overrides)
              {
                if (xo == "")
                {
                } else {
                  try
                  {
                    var tmp = overrides[xo].split("_");
                    var ind = tmp[1];
                    var val = tmp[2];
                    overs[ind]=val;
                 
                  }
                  catch (e)
                  {
                  }
                }
              }
              colid = colid.replace(patt1,'');
            }
            sorttable.makeSortable(table,overs);
            if (colid.search(/\bsort/) != -1) {
              colid = colid.replace('sortable','');
              colid = colid.replace(' sort','');
              if (!colid != '')
              {
                colid = colid.trim();
              }
              revs=false;
              if (colid.search(/\br/) != -1) {
                revs=true;
                colid = colid.replace('r','');
              }
              sorttable.defaultSort(table,colid,revs);
            }
          });
        }
  },
  defaultSort: function(table, colid, revs) {
//    theadrow = table.tHead.rows[0].cells;
    theadrow = table.rows[0].cells;
    colid--;
    colname ="col"+colid;
    // remove sorttable_sorted classes
    var thiscell=false;
    forEach(theadrow, function(cell) {
      colclass=cell.className;             
      classname = colclass.split(" ");     
      if (classname[0]==colname)           
//      if (cell.className==colname)
      {
        thiscell=cell;
      }
//      if (cell.nodeType == 1) { // an element
//        cell.className = cell.className.replace('sorttable_sorted_reverse','');
//        cell.className = cell.className.replace('sorttable_sorted','');
//      }
    });
    if (thiscell===false) {return;}
    sortfwdind = document.getElementById('sorttable_sortfwdind');
    if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
    sortrevind = document.getElementById('sorttable_sortrevind');
    if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
   
    thiscell.className += ' sorttable_sorted';
    sortfwdind = document.createElement('span');
    sortfwdind.id = "sorttable_sortfwdind";
    sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
    thiscell.appendChild(sortfwdind);
    // build an array to sort. This is a Schwartzian transform thing,
    // i.e., we "decorate" each row with the actual sort key,
    // sort based on the sort keys, and then put the rows back in order
    // which is a lot faster because you only do getInnerText once per row
    row_array = [];
    col = thiscell.sorttable_columnindex;
    rows = thiscell.sorttable_tbody.rows;
    for (var j=1; j<rows.length; j++) {
      row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
    }
    /* If you want a stable sort, uncomment the following line */
    //sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
    /* and comment out this one */
    row_array.sort(thiscell.sorttable_sortfunction);
   
    tb = thiscell.sorttable_tbody;
    for (var jj=0; jj<row_array.length; jj++) {
      tb.appendChild(row_array[jj][1]);
    }
   
    delete row_array;
    // If reverse sort wanted, then doit
    if (revs) {
      // reverse the table, which is quicker
      sorttable.reverse(thiscell.sorttable_tbody);
      thiscell.className = thiscell.className.replace('sorttable_sorted',
                                                      'sorttable_sorted_reverse');
      thiscell.removeChild(document.getElementById('sorttable_sortfwdind'));
      sortrevind = document.createElement('span');
      sortrevind.id = "sorttable_sortrevind";
      sortrevind.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
      thiscell.appendChild(sortrevind);
    }


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 );


  makeSortable: function(table,overrides) {
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
//    tableid++;
for ( j = 0; j < navFrame.childNodes.length; j++ ) {
/*
if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
    if (table.getElementsByTagName('thead').length === 0) {
navToggle.style.color = navFrame.childNodes[j].style.color;
      // table doesn't have a tHead. Since it should have, create one and
navFrame.childNodes[j].appendChild( navToggle );
      // put the first table row in it.
}
      the = document.createElement('thead');
}
      the.appendChild(table.rows[0]);
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
      table.insertBefore(the,table.firstChild);
} );
    }
}
*/
    // Safari doesn't support table.tHead, sigh
/*
    if (table.tHead === null) {table.tHead = table.getElementsByTagName('thead')[0];}
   
    if (table.tHead.rows.length != 1) {return;} // can't cope with two header rows
  */ 
//    table.tHead.className += ' tableid'+tableid;


    // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
    // "total" rows, for example). This is B&R, since what you're supposed
    // to do is put them in a tfoot. So, if there are sortbottom rows,
    // for backwards compatibility, move them to tfoot (creating it if needed).
    /*
    sortbottomrows = [];
    for (var i=0; i<table.rows.length; i++) {
      if (table.rows[i].className.search(/\bsortbottom\b/) != -1) {
        sortbottomrows[sortbottomrows.length] = table.rows[i];
      }
    }
    if (sortbottomrows) {
      if (table.tFoot === null) {
        // table doesn't have a tfoot. Create one.
        tfo = document.createElement('tfoot');
        table.appendChild(tfo);
      }
      for (var ii=0; ii<sortbottomrows.length; ii++) {
        tfo.appendChild(sortbottomrows[ii]);
      }
      delete sortbottomrows;
    }
    */
    // work through each column and calculate its type
//    headrow = table.tHead.rows[0].cells;
    headrow = table.rows[0].cells;
//    for (var i=0; i<headrow.length; i++) {
    for (i=0; i<headrow.length; i++) {
      // manually override the type with a sorttable_type attribute
      var colOptions="";
      if (overrides[i+1])
      {
        colOptions=overrides[i+1];
      }
      if (!colOptions.match(/\bnosort\b/)) { // skip this col
        mtch = colOptions.match(/\b[a-z0-9]+\b/);
        if (mtch) { override = mtch[0]; }
        if (mtch && typeof sorttable["sort_"+override] == 'function') {
          headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
        } else {
          headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
        }
/*     
      if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { // skip this col
        mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/);
        if (mtch) { override = mtch[1]; }
        if (mtch && typeof sorttable["sort_"+override] == 'function') {
          headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
        } else {
          headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
        }
*/
        // make it clickable to sort
        headrow[i].sorttable_columnindex = i;
        headrow[i].sorttable_tbody = table.tBodies[0];
//        dean_addEvent(headrow[i],"click", function(e) {
        addEvent(headrow[i],"click", function(e) {


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


          if (this.className.search(/\bsorttable_sorted\b/) != -1) {
function NiftyCheck(){
            // if we're already sorted by this column, just
if(!document.getElementById || !document.createElement)
            // reverse the table, which is quicker
    return(false);
            sorttable.reverse(this.sorttable_tbody);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
            this.className = this.className.replace('sorttable_sorted',
if(Array.prototype.push==null){Array.prototype.push=function(){
                                                    'sorttable_sorted_reverse');
      this[this.length]=arguments[0]; return(this.length);}}
            sortfwdind = document.getElementById('sorttable_sortfwdind');
return(true);
            if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
}
//            this.removeChild(document.getElementById('sorttable_sortfwdind'));
            sortrevind = document.getElementById('sorttable_sortrevind');
            if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
            sortrevind = document.createElement('span');
            sortrevind.id = "sorttable_sortrevind";
            sortrevind.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
            this.appendChild(sortrevind);
            return;
          }
          if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) {
            // if we're already sorted by this column in reverse, just
            // re-reverse the table, which is quicker
            sorttable.reverse(this.sorttable_tbody);
            this.className = this.className.replace('sorttable_sorted_reverse',
                                                    'sorttable_sorted');
            sortrevind = document.getElementById('sorttable_sortrevind');
            if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
//           this.removeChild(document.getElementById('sorttable_sortrevind'));
            sortfwdind = document.getElementById('sorttable_sortfwdind');
            if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
            sortfwdind = document.createElement('span');
            sortfwdind.id = "sorttable_sortfwdind";
            sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
            this.appendChild(sortfwdind);
            return;
          }
         
          // remove sorttable_sorted classes
//          theadrow = this.parentNode;
          forEach(theadrow.childNodes, function(cell) {
            if (cell.nodeType == 1) { // an element
              cell.className = cell.className.replace('sorttable_sorted_reverse','');
              cell.className = cell.className.replace('sorttable_sorted','');
            }
          });
          sortfwdind = document.getElementById('sorttable_sortfwdind');
          if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
          sortrevind = document.getElementById('sorttable_sortrevind');
          if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
         
          this.className += ' sorttable_sorted';
          sortfwdind = document.createElement('span');
          sortfwdind.id = "sorttable_sortfwdind";
          sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
          this.appendChild(sortfwdind);


          // build an array to sort. This is a Schwartzian transform thing,
function Rounded(selector, wich, bk, color, opt) {
          // i.e., we "decorate" each row with the actual sort key,
    var i, prefixt, prefixb, cn = "r", ecolor = "", edges = !1, eclass = "", b = !1, t = !1;
          // sort based on the sort keys, and then put the rows back in order
    if (color == "transparent") {
          // which is a lot faster because you only do getInnerText once per row
        cn = cn + "x";
          row_array = [];
        ecolor = bk;
          col = this.sorttable_columnindex;
        bk = "transparent";
          rows = this.sorttable_tbody.rows;
    } else if (opt && opt.indexOf("border") >= 0) {
          for (var j=1; j<rows.length; j++) {
        var optar = opt.split(" ");
             row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
        for (i = 0; i < optar.length; i++)
          }
             if (optar[i].indexOf("#") >= 0)
          /* If you want a stable sort, uncomment the following line */
                ecolor = optar[i];
          //sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
        if (ecolor == "")
          /* and comment out this one */
            ecolor = "#666";
          row_array.sort(this.sorttable_sortfunction);
        cn += "e";
         
        edges = !0;
          tb = this.sorttable_tbody;
    } else if (opt && opt.indexOf("smooth") >= 0) {
          for (var j3=0; j3<row_array.length; j3++) {
        cn += "a";
            tb.appendChild(row_array[j3][1]);
         ecolor = Mix(bk, color);
          }
         
          delete row_array;
         });
      }
     }
     }
  },
    if (opt && opt.indexOf("small") >= 0)
 
        cn += "s";
  guessType: function(table, column) {
    prefixt = cn;
     // guess the type of a column based on its first non-blank row
    prefixb = cn;
     sortfn = sorttable.sort_alpha;
    if (wich.indexOf("all") >= 0) {
     for (var i=0; i<table.tBodies[0].rows.length; i++) {
        t = !0;
      text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
        b = !0;
      if (text !== '') {
    } else if (wich.indexOf("top") >= 0)
         if (text.match(/^-?[£$¤]?[\d,.]+[%€]?$/)) {
        t = "true";
          return sorttable.sort_numeric;
    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);
         }
         }
         // check for a date: dd/mm/yyyy or dd/mm/yy
         for (i = 0; i < el.childNodes.length; i++) {
        // can have / or . or - as separator
            if (el.childNodes[i].nodeType == 1) {
        // can be mm/dd as well
                el.childNodes[i].style.borderLeft = "1px solid " + bc;
        possdate = text.match(sorttable.DATE_RE);
                el.childNodes[i].style.borderRight = "1px solid " + bc;
        if (possdate) {
             }
          // looks like a date
          first = parseInt(possdate[1]);
          second = parseInt(possdate[2]);
          if (first > 12) {
            // definitely dd/mm
            return sorttable.sort_ddmm;
          } else if (second > 12) {
            return sorttable.sort_mmdd;
          } else {
            // looks like a date, but we can't tell which, so assume
             // that it's dd/mm (English imperialism!) and keep looking
            sortfn = sorttable.sort_ddmm;
          }
         }
         }
      }
     }
     }
     return sortfn;
     el.passed = !0;
  },
}
 
function AddTop(el, bk, color, bc, cn) {
  getInnerText: function(node) {
     var i, lim = 4, d = CreateEl("b");
     // gets the text we want to use for sorting for a cell.
     if (cn.indexOf("s") >= 0)
     // strips leading and trailing whitespace.
        lim = 2;
     // this is *not* a generic getInnerText function; it's special to sorttable.
     if (bc)
     // for example, you can override the cell text with a customkey attribute.
        d.className = "artop";
     // it also gets .value for <input> fields.
     else
      
        d.className = "rtop";
    hasInputs = (typeof node.getElementsByTagName == 'function') &&
     d.style.backgroundColor = bk;
                node.getElementsByTagName('input').length;
     for (i = 1; i <= lim; i++) {
   
        var x = CreateEl("b");
    if (node.getAttribute("sorttable_customkey") !== null) {
        x.className = cn + i;
      return node.getAttribute("sorttable_customkey");
        x.style.backgroundColor = color;
        if (bc)
            x.style.borderColor = bc;
        d.appendChild(x);
     }
     }
     else if (typeof node.textContent != 'undefined' && !hasInputs) {
     el.style.paddingTop = 0;
      return node.textContent.replace(/^\s+|\s+$/g, '');
    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);
     }
     }
     else if (typeof node.innerText != 'undefined' && !hasInputs) {
     el.style.paddingBottom = 0;
      return node.innerText.replace(/^\s+|\s+$/g, '');
    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];
     }
     }
     else if (typeof node.text != 'undefined' && !hasInputs) {
     if (selid != "") {
      return node.text.replace(/^\s+|\s+$/g, '');
        f = document.getElementById(selid);
        if (f)
            objlist.push(f);
        return (objlist);
     }
     }
     else {
     if (selector.indexOf(".") > 0) {
      switch (node.nodeType) {
        s = selector.split(".");
        case 3:
         tag = s[0];
          if (node.nodeName.toLowerCase() == 'input') {
        selclass = s[1];
            return node.value.replace(/^\s+|\s+$/g, '');
          }
        case 4:
          return node.nodeValue.replace(/^\s+|\s+$/g, '');
          break;
        case 1:
         case 11:
          var innerText = '';
          for (var i = 0; i < node.childNodes.length; i++) {
            innerText += sorttable.getInnerText(node.childNodes[i]);
          }
          return innerText.replace(/^\s+|\s+$/g, '');
          break;
        default:
          return '';
      }
     }
     }
  },
    var v = document.getElementsByTagName(tag);
 
     if (selclass == "")
  reverse: function(tbody) {
        return (v);
     // reverse the rows in a tbody
     for (i = 0; i < v.length; i++) {
    newrows = [];
        if (v[i].className.indexOf(selclass) >= 0) {
     for (var i=0; i<tbody.rows.length; i++) {
            objlist.push(v[i]);
      newrows[newrows.length] = tbody.rows[i];
        }
     }
     }
     for (var i=newrows.length-1; i>=1; i--) {
     return (objlist);
      tbody.appendChild(newrows[i]);
}
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);
     }
     }
     delete newrows;
     return ("#" + r[0].toString(16) + r[1].toString(16) + r[2].toString(16));
  },
}
 
function doRoundEdges() {
  /* sort functions
     if (!NiftyCheck())
    each sort function takes two parameters, a and b
        return;
    you are comparing a[0] and b[0] */
    Rounded("div#nifty", "all", "#FFF", "#D4DDFF", "smooth");
  sort_numeric: function(a,b) {
}
    aa = parseFloat(a[0].replace(/[^0-9.\-]/g,''));
jQuery(doRoundEdges);
    if (isNaN(aa)) {aa = 0;}
function setStyleById(i, p, v) {
    bb = parseFloat(b[0].replace(/[^0-9.\-]/g,''));
     var n = document.getElementById(i);
     if (isNaN(bb)) {bb = 0;}
     n.style[p] = v;
    return aa-bb;
}
  },
jQuery(performIE);
  sort_alpha: function(a,b) {
function performIE() {
    if (a[0]==b[0]) {return 0;}
     if (-1 != navigator.userAgent.indexOf("MSIE")) {
    if (a[0]<b[0]) {return -1;}
        var Divs = document.getElementsByTagName("div");
    return 1;
        var divCnt = 0;
  },
        var divID = "";
  sort_ddmm: function(a,b) {
        if (Divs.length > 0) {
     mtch = a[0].match(sorttable.DATE_RE);
            var CurrDiv = Divs[0];
     y = mtch[3]; m = mtch[2]; d = mtch[1];
            var s = "";
    t = mtch[5]+'';
            while (Divs.length > divCnt) {
    if (t.length < 1 ) {t = '';}
                s = eval("CurrDiv.style.ietop");
    if (m.length == 1) {m = '0'+m;}
                if ((s != "") && (s != null)) {
    if (d.length == 1) {d = '0'+d;}
                    divID = "mapDiv" + divCnt;
    dt1 = y+m+d+t;
                    CurrDiv.setAttribute("id", divID);
    mtch = b[0].match(sorttable.DATE_RE);
                    setStyleById(divID, "top", CurrDiv.style.ietop);
    y = mtch[3]; m = mtch[2]; d = mtch[1];
                }
    t = mtch[5]+'';
                 divCnt++;
     if (t.length < 1 ) {t = '';}
                 CurrDiv = Divs[divCnt];
    if (m.length == 1) {m = '0'+m;}
    if (d.length == 1) {d = '0'+d;}
    dt2 = y+m+d+t;
    if (dt1==dt2) {return 0;}
    if (dt1<dt2) {return -1;}
    return 1;
  },
  sort_mmdd: function(a,b) {
    mtch = a[0].match(sorttable.DATE_RE);
    y = mtch[3]; d = mtch[2]; m = mtch[1];
    t = mtch[5]+'';
    if (m.length == 1) {m = '0'+m;}
    if (d.length == 1) {d = '0'+d;}
    dt1 = y+m+d+t;
    mtch = b[0].match(sorttable.DATE_RE);
    y = mtch[3]; d = mtch[2]; m = mtch[1];
    t = mtch[5]+'';
    if (t.length < 1 ) {t = '';}
    if (m.length == 1) {m = '0'+m;}
    if (d.length == 1) {d = '0'+d;}
    dt2 = y+m+d+t;
    if (dt1==dt2) {return 0;}
    if (dt1<dt2) {return -1;}
    return 1;
  },
 
  shaker_sort: function(list, comp_func) {
    // A stable sort function to allow multi-level sorting of data
    // see: http://en.wikipedia.org/wiki/Cocktail_sort
    // thanks to Joseph Nahmias
    var b = 0;
    var t = list.length - 1;
    var swap = true;
 
    while(swap) {
        swap = false;
        for(var i = b; i < t; ++i) {
            if ( comp_func(list[i], list[i+1]) > 0 ) {
                 var q = list[i]; list[i] = list[i+1]; list[i+1] = q;
                 swap = true;
             }
             }
         } // for
         }
        t--;
    }
}
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/


        if (!swap) {break;}
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var indexNavigationBar = 0;


        for(var i = t; i > b; --i) {
/**
            if ( comp_func(list[i], list[i-1]) < 0 ) {
* Shows and hides content and picture (if available) of navigation bars
                var q = list[i]; list[i] = list[i-1]; list[i-1] = q;
* Parameters:
                swap = true;
*    indexNavigationBar: the index of navigation bar to be toggled
            }
**/
        } // for
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
        b++;
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;


     } // while(swap)
     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 ) {
  Supporting functions: bundled here to avoid depending on a library
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
  ****************************************************************** */
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
 
                NavChild.style.display = 'block';
 
            }
 
        }
// Dean Edwards/Matthias Miller/John Resig
        NavToggle.firstChild.data = NavigationBarHide;
 
 
// Dean's forEach: http://dean.edwards.name/base/forEach.js
/*
  forEach, version 1.0
  Copyright 2006, Dean Edwards
  License: http://www.opensource.org/licenses/mit-license.php
*/
 
// array-like enumeration
if (!Array.forEach) { // mozilla already supports this
  Array.forEach = function(array, block, context) {
    for (var i = 0; i < array.length; i++) {
      block.call(context, array[i], i, array);
     }
     }
  };
}


// generic enumeration
     event.preventDefault();
Function.prototype.forEach = function(object, block, context) {
  for (var key in object) {
     if (typeof this.prototype[key] == "undefined") {
      block.call(context, object[key], key, object);
    }
  }
};
};


// character enumeration
/* adds show/hide-button to navigation bars */
String.forEach = function(string, block, context) {
function createNavigationBarToggleButton( $content ) {
  Array.forEach(string.split(""), function(chr, index) {
    var NavChild;
    block.call(context, chr, index, string);
    /* iterate over all < div >-elements */
  });
    var $divs = $content.find( 'div' );
};
    $divs.each( function ( i, NavFrame ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {


// globally resolve forEach enumeration
            indexNavigationBar++;
var forEach = function(object, block, context) {
            var NavToggle = document.createElement( 'a' );
  if (object) {
            NavToggle.className = 'NavToggle';
    var resolve = Object; // default
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
    if (object instanceof Function) {
            NavToggle.setAttribute( 'href', '#' );
      // functions have a "length" property
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
      resolve = Function;
    } else if (object.forEach instanceof Function) {
      // the object implements a custom forEach method so use that
      object.forEach(block, context);
      return;
    } else if (typeof object == "string") {
      // the object is a string
      resolve = String;
    } else if (typeof object.length == "number") {
      // the object is array-like
      resolve = Array;
    }
    resolve.forEach(object, block, context);
  }
};


            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 );


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


//sorttable.init;
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );


function reinitsort() {
/* Tweak to get CategoryTree extension to have trees expanded by default */
  sorttable.reinit();
$( 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(); });