https://www.noisebridge.net/index.php?title=User:EmbeddedLinuxGuy/common.js&feed=atom&action=history
User:EmbeddedLinuxGuy/common.js - Revision history
2024-03-29T02:09:47Z
Revision history for this page on the wiki
MediaWiki 1.39.4
https://www.noisebridge.net/index.php?title=User:EmbeddedLinuxGuy/common.js&diff=24718&oldid=prev
EmbeddedLinuxGuy: Created page with '/** Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See * …'
2012-03-17T06:24:14Z
<p>Created page with '/** Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See * …'</p>
<p><b>New page</b></p><div>/** Collapsible tables *********************************************************<br />
*<br />
* Description: Allows tables to be collapsed, showing only the header. See<br />
* [[Wikipedia:NavFrame]].<br />
* Maintainers: [[User:R. Koot]]<br />
*/<br />
<br />
var autoCollapse = 2;<br />
var collapseCaption = "hide";<br />
var expandCaption = "show";<br />
<br />
window.collapseTable = function( 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) continue;<br />
var Header = HeaderRow.getElementsByTagName( "th" )[0];<br />
if (!Header) continue;<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 Common.css<br />
<br />
ButtonLink.style.color = Header.style.color;<br />
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );<br />
ButtonLink.setAttribute( "href", "#" );<br />
addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );<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.firstChild );<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 />
} <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 />
$( createCollapseButtons );</div>
EmbeddedLinuxGuy