spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column12
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Logo

Expandable Outlines
Multi-Item Expansion


The Page HTML

<P>
<A HREF="#"
   onClick="expandAll(); return false">   // top "ALL" link
    <IMG NAME="imEx" SRC="triDown.gif"    // not in DIV
         WIDTH=16 HEIGHT=16 BORDER=0
         ALT="Expand/Collapse All">
</A>
    Display/Hide All
</P>

<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 bottom "ALL" link in DIV
.
<DIV ID="elEndParent" CLASS="parent">
<A HREF="#"
   onClick="expandAll(); return false">
    <IMG NAME="imEx" SRC="triDown.gif"
         WIDTH=16 HEIGHT=16 BORDER=0
         ALT="Expand/Collapse All">
</A>
    Display/Hide All
</DIV>
.
. 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">
<!--

NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

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>");
    }
}

isExpanded = false;

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();
    }
}

function expandAll() {
    if (!ver4) return;
    newSrc = (isExpanded) ? "triDown.gif" : "triUp.gif";

    if (NS4) {
        document.images["imEx"].src = newSrc;
        for (i=firstInd; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Parent") != -1) {
                whichEl.document.images["imEx"].src = newSrc;
            }
            if (whichEl.id.indexOf("Child") != -1) {
                whichEl.visibility = (isExpanded) ? "hide" : "show";
            }
        }

        arrange();
        if (isExpanded) scrollTo(0,document.layers[firstInd].pageY);
    }
    else {
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            if (divColl(i).className == "child") {
                divColl(i).style.display = (isExpanded) ? "none" : "block";
            }
        }
        imColl = document.images.item("imEx");
        for (i=0; i<imColl.length; i++) {
            imColl(i).src = newSrc;
        }
    }
    
    isExpanded = !isExpanded;
}

onload = initIt;

//-->
</SCRIPT>

Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

All Rights Reserved. Legal Notices.
Created: Jan. 14, 1998
Revised: Jan. 18, 1998

URL: http://www.webreference.com/dhtml/column12/outALLtwo.html