Expandable Outlines: The Complete Code 2/2

Expandable Outlines
SPECIAL EDITION; the director's cut 2/2
Page HTML
- <DIV ID="elOneParent" CLASS="parent">
...
</DIV>
<DIV ID="elOneChild" CLASS="child">
...
</DIV>
<DIV ID="elTwoParent" CLASS="parent">
...
</DIV>
<DIV ID="elTwoChild" CLASS="child">
...
</DIV>
.
. continue parent/child groupings until end of outline,
. then enclose remaining page elements in DIVs
.
<DIV ID="elRest1" CLASS="regular">
...
</DIV>
<DIV ID="elRest2" CLASS="regular">
...
</DIV>
.
. possibly more DIVs
.
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
if (NS4) {
firstEl = "elOneParent";
firstInd = getIndex(firstEl);
arrange();
}
//-->
</SCRIPT>
</BODY>
</HTML>
The Script
<SCRIPT LANGUAGE="JavaScript">
<!--
if (ver4) {
with (document) {
write("<STYLE TYPE='text/css'>");
if (NS4) {
write(".parent {position:absolute; visibility:visible}");
write(".child {position:absolute; visibility:visible}");
write(".regular {position:absolute; visibility:visible}")
}
else {
write(".child {display:none}")
}
write("</STYLE>");
}
}
function getIndex(el) {
ind = null;
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}
function arrange() {
nextY = document.layers[firstInd].pageY + document.layers[firstInd].document.height;
for (i=firstInd+1; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}
function initIt(){
if (!ver4) return;
if (NS4) {
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
}
arrange();
}
else {
divColl = document.all.tags("DIV");
for (i=0; i<divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == "child") whichEl.style.display = "none";
}
}
}
function expandIt(el) {
if (!ver4) return;
if (IE4) {
whichEl = eval(el + "Child");
whichIm = event.srcElement;
if (whichEl.style.display == "none") {
whichEl.style.display = "block";
whichIm.src = "triUp.gif";
}
else {
whichEl.style.display = "none";
whichIm.src = "triDown.gif";
}
}
else {
whichEl = eval("document." + el + "Child");
whichIm = eval("document." + el + "Parent.document.images['imEx']");
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
whichIm.src = "triUp.gif";
}
else {
whichEl.visibility = "hide";
whichIm.src = "triDown.gif";
}
arrange();
}
}
onload = initIt;
//-->
</SCRIPT>
Bonus
For outlines with many expandable items, we look at expanding/collapsing all of them with one click.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.Created: Jan. 14, 1998
Revised: Jan. 18, 1998
URL: http://www.webreference.com/dhtml/column12/allCode2.html


