MediaWiki:Common.js

From Wikimedia Foundation Governance Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 * Collapsible tables
 *
 * Allows tables to be collapsed, showing only the header. See  [[Wikipedia:NavFrame]].
 *
 * @version 2.0.3 (2014-03-14)
 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
 * @author [[User:R. Koot]]
 * @author [[User:Krinkle]]
 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
 * is supported in MediaWiki core.
 */

var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';

function collapseTable( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );

    if ( !Table || !Button ) {
        return false;
    }

    var Rows = Table.rows;
    var i;

    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}

function createClickHandler( tableIndex ) {
    return function ( e ) {
        e.preventDefault();
        collapseTable( tableIndex );
    };
}

/**
 * Code for fundraising Thank You pages
 * e.g. https://foundation.wikimedia.org/wiki/Thank_You/en
 *
 * @author: [[User:Pcoombe (WMF)]]
 */

if ( mw.config.get('wgPageName').substring(0,9) === 'Thank_You' ) {

    mw.loader.using( 'mediawiki.util', function() {

        var paymentMethod = mw.util.getParamValue('payment_method'),
            country = mw.util.getParamValue('country');

        if ( paymentMethod === 'bt' ) {
            document.getElementById('ty-banktransfer').style.display = 'block';
        }
        if ( paymentMethod === 'bitcoin' ) {
            document.getElementById('ty-bitcoin').style.display = 'block';
        }
        if ( paymentMethod === 'bpay' ) {
            document.getElementById('ty-bpay').style.display = 'block';
        }

        if ( country === 'US' || country === 'CA' ) {
            document.getElementById('ty-store').style.display = 'block';
        }

    });

}

/**
 * This throws a "ReferenceError: createCollapseButtons is not defined" in every browser now that the createCollapseButtons function is gone.
 * On the other hand, why is this code even here? It's clearly marked as deprecated
 * since about four versions ago...
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
 */