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:15, 30 March 2010 (make it wide.). 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";
 table.style.width = "100%";

 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-templatesUsedExplanation" );
 var single = elements[0];
 header.appendChild( single );
 var row1 = document.createElement( "tr");
 row1.appendChild( header );
 var row2 = document.createElement( "tr");
 row2.appendChild( tused.getElementsByTagName("ul")[0] );
 table.appendChild( row1 );
 table.appendChild( row2 );

 tused.parentNode.insertBefore( table, tused);
}
}