https://cohwiki.slitherine.com/index.php?title=MediaWiki:Common.js&feed=atom&action=history
MediaWiki:Common.js - Revision history
2024-03-28T17:04:22Z
Revision history for this page on the wiki
MediaWiki 1.38.2
https://cohwiki.slitherine.com/index.php?title=MediaWiki:Common.js&diff=349&oldid=prev
Valery at 01:44, 31 May 2012
2012-05-31T01:44:03Z
<p></p>
<a href="https://cohwiki.slitherine.com/index.php?title=MediaWiki:Common.js&diff=349&oldid=345">Show changes</a>
Valery
https://cohwiki.slitherine.com/index.php?title=MediaWiki:Common.js&diff=345&oldid=prev
Valery: Created page with "/* Any JavaScript here will be loaded for all users on every page load. */ /** Collapsible tables ********************************************************* * * Description..."
2012-05-28T22:45:40Z
<p>Created page with "<span dir="auto"><span class="autocomment">Any JavaScript here will be loaded for all users on every page load.: </span> /** Collapsible tables ********************************************************* * * Description..."</span></p>
<p><b>New page</b></p><div>/* Any JavaScript here will be loaded for all users on every page load. */<br />
<br />
/** Collapsible tables *********************************************************<br />
*<br />
* Description: Allows tables to be collapsed, showing only the header. See<br />
* http://www.mediawiki.org/wiki/Manual:Collapsible_tables.<br />
* Maintainers: [[en:User:R. Koot]]<br />
*/<br />
<br />
var autoCollapse = 2;<br />
var collapseCaption = 'hide';<br />
var expandCaption = 'show';<br />
<br />
function collapseTable( tableIndex ) {<br />
var Button = document.getElementById( 'collapseButton' + tableIndex );<br />
var Table = document.getElementById( 'collapsibleTable' + tableIndex );<br />
<br />
if ( !Table || !Button ) {<br />
return false;<br />
}<br />
<br />
var Rows = Table.rows;<br />
<br />
if ( Button.firstChild.data == collapseCaption ) {<br />
for ( var i = 1; i < Rows.length; i++ ) {<br />
Rows[i].style.display = 'none';<br />
}<br />
Button.firstChild.data = expandCaption;<br />
} else {<br />
for ( var i = 1; i < Rows.length; i++ ) {<br />
Rows[i].style.display = Rows[0].style.display;<br />
}<br />
Button.firstChild.data = collapseCaption;<br />
}<br />
}<br />
<br />
function createCollapseButtons() {<br />
var tableIndex = 0;<br />
var NavigationBoxes = new Object();<br />
var Tables = document.getElementsByTagName( 'table' );<br />
<br />
for ( var i = 0; i < Tables.length; i++ ) {<br />
if ( hasClass( Tables[i], 'collapsible' ) ) {<br />
<br />
/* only add button and increment count if there is a header row to work with */<br />
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];<br />
if ( !HeaderRow ) {<br />
continue;<br />
}<br />
var Header = HeaderRow.getElementsByTagName( 'th' )[0];<br />
if ( !Header ) {<br />
continue;<br />
}<br />
<br />
NavigationBoxes[tableIndex] = Tables[i];<br />
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );<br />
<br />
var Button = document.createElement( 'span' );<br />
var ButtonLink = document.createElement( 'a' );<br />
var ButtonText = document.createTextNode( collapseCaption );<br />
<br />
Button.className = 'collapseButton'; // Styles are declared in [[MediaWiki:Common.css]]<br />
<br />
ButtonLink.style.color = Header.style.color;<br />
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );<br />
ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );<br />
ButtonLink.appendChild( ButtonText );<br />
<br />
Button.appendChild( document.createTextNode( '[' ) );<br />
Button.appendChild( ButtonLink );<br />
Button.appendChild( document.createTextNode( ']' ) );<br />
<br />
Header.insertBefore( Button, Header.childNodes[0] );<br />
tableIndex++;<br />
}<br />
}<br />
<br />
for ( var i = 0; i < tableIndex; i++ ) {<br />
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {<br />
collapseTable( i );<br />
} else if ( hasClass( NavigationBoxes[i], 'innercollapse' ) ) {<br />
var element = NavigationBoxes[i];<br />
while ( element = element.parentNode ) {<br />
if ( hasClass( element, 'outercollapse' ) ) {<br />
collapseTable( i );<br />
break;<br />
}<br />
}<br />
}<br />
}<br />
}<br />
<br />
addOnloadHook( createCollapseButtons );<br />
<br />
/** Test if an element has a certain class **************************************<br />
*<br />
* Description: Uses regular expressions and caching for better performance.<br />
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]<br />
*/<br />
<br />
var hasClass = ( function() {<br />
var reCache = {};<br />
return function( element, className ) {<br />
return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );<br />
};<br />
})();</div>
Valery