User:Chillispike/monaco.js

/* Collapsable Divs */

var hideText = "hide"; var showText = "show";

function toggleDiv ( divIndex ) {   var Button = document.getElementById("divCollapseButton" + divIndex); var Div = document.getElementById("collapsibleDiv" + divIndex);

if (!Div || !Button) { return false; }

if (Div.style.display == "none") {     Div.style.display = ""; Button.firstChild.data = hideText; }else{ Div.style.display = "none"; Button.firstChild.data = showText; } }

function makeDivButtons {  var divIndex = 0; var DivArray = new Object; var Divs = document.getElementsByTagName ("div");

for (var i = 0; i < Divs.length; i++) {    if (hasClass( Divs[i], "collapse")) {      DivArray[divIndex] = Divs[i]; Divs[i].setAttribute("id", "collapsibleDiv" + divIndex); var Button = document.createElement("span"); var ButtonLink = document.createElement("a"); if (Divs[i].style.display == "none") {        var ButtonText = document.createTextNode(showText); }else{ var ButtonText = document.createTextNode(hideText); }

/*   Button.style.styleFloat = "right" Button.style.cssFloat = "right"; */ Button.style.fontWeight = "normal"; Button.style.textAlign = "right"; Button.style.width = "3.5em";

ButtonLink.setAttribute("id", "divCollapseButton" + divIndex); ButtonLink.setAttribute("href", "javascript:toggleDiv(" + divIndex + ");" ); ButtonLink.appendChild( ButtonText );

Button.appendChild( document.createTextNode( "[" ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( "]" ) ); if(hasClass( Divs[i], "hdr")) {         Button.style.marginLeft = "3px"; Button.style.fontSize = "75%"; Divs[i].previousSibling.previousSibling.appendChild(Button); }else{ Divs[i].parentNode.insertBefore( Button, Divs[i]); }    divIndex++; }  } }

addOnloadHook( makeDivButtons );