MediaWiki:Common.js: Difference between revisions
Content deleted Content added
Create |
Update foundation url |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 11: | Line 11: | ||
* is supported in MediaWiki core. |
* is supported in MediaWiki core. |
||
*/ |
*/ |
||
⚫ | |||
var autoCollapse = 2; |
var autoCollapse = 2; |
||
var collapseCaption = 'hide'; |
var collapseCaption = 'hide'; |
||
var expandCaption = 'show'; |
var expandCaption = 'show'; |
||
function collapseTable( tableIndex ) { |
function collapseTable( tableIndex ) { |
||
var Button = document.getElementById( 'collapseButton' + tableIndex ); |
var Button = document.getElementById( 'collapseButton' + tableIndex ); |
||
var Table = document.getElementById( 'collapsibleTable' + tableIndex ); |
var Table = document.getElementById( 'collapsibleTable' + tableIndex ); |
||
if ( !Table || !Button ) { |
if ( !Table || !Button ) { |
||
return false; |
return false; |
||
} |
} |
||
var Rows = Table.rows; |
var Rows = Table.rows; |
||
var i; |
var i; |
||
if ( Button.firstChild.data === collapseCaption ) { |
if ( Button.firstChild.data === collapseCaption ) { |
||
for ( i = 1; i < Rows.length; i++ ) { |
for ( i = 1; i < Rows.length; i++ ) { |
||
Line 39: | Line 39: | ||
} |
} |
||
} |
} |
||
function createClickHandler( tableIndex ) { |
function createClickHandler( tableIndex ) { |
||
return function ( e ) { |
return function ( e ) { |
||
Line 46: | Line 46: | ||
}; |
}; |
||
} |
} |
||
/** |
|||
function createCollapseButtons() { |
|||
* Code for fundraising Thank You pages |
|||
var tableIndex = 0; |
|||
* e.g. https://foundation.wikimedia.org/wiki/Thank_You/en |
|||
var NavigationBoxes = {}; |
|||
⚫ | |||
var Tables = document.getElementsByTagName( 'table' ); |
|||
* @author: [[User:Pcoombe (WMF)]] |
|||
⚫ | |||
*/ |
|||
for ( i = 0; i < Tables.length; i++ ) { |
|||
if ( mw.config.get('wgPageName').substring(0,9) === 'Thank_You' ) { |
|||
mw.loader.using( 'mediawiki.util', function() { |
|||
/* only add button and increment count if there is a header row to work with */ |
|||
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0]; |
|||
var paymentMethod = mw.util.getParamValue('payment_method'), |
|||
if ( !HeaderRow ) { |
|||
country = mw.util.getParamValue('country'); |
|||
⚫ | |||
if ( paymentMethod === 'bt' ) { |
|||
document.getElementById('ty-banktransfer').style.display = 'block'; |
|||
if ( !Header ) { |
|||
continue; |
|||
⚫ | |||
NavigationBoxes[ tableIndex ] = Tables[i]; |
|||
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex ); |
|||
var Button = document.createElement( 'span' ); |
|||
var ButtonLink = document.createElement( 'a' ); |
|||
var ButtonText = document.createTextNode( collapseCaption ); |
|||
// Styles are declared in [[MediaWiki:Common.css]] |
|||
Button.className = 'collapseButton'; |
|||
ButtonLink.style.color = Header.style.color; |
|||
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); |
|||
ButtonLink.setAttribute( 'href', '#' ); |
|||
$( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ); |
|||
ButtonLink.appendChild( ButtonText ); |
|||
Button.appendChild( document.createTextNode( '[' ) ); |
|||
Button.appendChild( ButtonLink ); |
|||
Button.appendChild( document.createTextNode( ']' ) ); |
|||
Header.insertBefore( Button, Header.firstChild ); |
|||
tableIndex++; |
|||
} |
} |
||
if ( paymentMethod === 'bitcoin' ) { |
|||
} |
|||
document.getElementById('ty-bitcoin').style.display = 'block'; |
|||
for ( i = 0; i < tableIndex; i++ ) { |
|||
if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || |
|||
( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) |
|||
) { |
|||
collapseTable( i ); |
|||
} |
|||
else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { |
|||
var element = NavigationBoxes[i]; |
|||
while ((element = element.parentNode)) { |
|||
if ( $( element ).hasClass( 'outercollapse' ) ) { |
|||
collapseTable ( i ); |
|||
break; |
|||
} |
|||
} |
|||
} |
} |
||
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 ); |
mw.hook( 'wikipage.content' ).add( createCollapseButtons ); |
||
*/ |
Latest revision as of 00:45, 31 July 2018
/**
* 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 );
*/