Jump to content

User:TheDJ/usagecollapse.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheDJ (talk | contribs) at 00:08, 30 March 2010 (try like this.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
addOnloadHook( usageCollapser );

function usageCollapser() {
if( wgAction == 'edit' || wgAction == 'submit' ) {
 var tused = getElementsByClassName( document, "div", "templatesUsed" )[0];
 tused.style.display = "none";

 var table = document.createElement( "table" );
 table.className = "collapsible collapsed";
 table.id = "collapsibleTable" + "TemplateUsage";

 var header = document.createElement( "th" );

<!-- show/hide button -->
var Button     = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( expandCaption );

Button.className = "collapseButton";  //Styles are declared in Common.css
Button.style.float = "left";
ButtonLink.setAttribute( "id", "collapseButton"  + "TemplateUsage");
ButtonLink.setAttribute( "href", "javascript:collapseTable('TemplateUsage');" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );

 header.appendChild( Button );
 var elements = getElementsByClassName( tused, "div", "mw-templateUsedExplanation" );
 var single = elements[0];
 header.appendChild( single );
 table.appendChild( document.createElement( "tr").appendChild( header ) );
 table.appendChild( document.createElement( "tr").appendChild( tused.getElementsByTagName("ul")[0] ) );
 tused.parentNode.insertBefore( table, tused);
}
}