PDA

View Full Version : Contractible Headers Script -- Expand/Contract ALL



dlms55
04-24-2006, 04:55 PM
I'm trying to implement the Contractible Headers script (http://www.dynamicdrive.com/dynamicindex1/navigate2.htm) on my intranet site. Some users have asked for the option to expand/contract all sections of the page at once. I've gone brain-dead and cannot seem to figure out how I can do this. Can anyone help?

Thanks!

jscheuer1
04-24-2006, 05:42 PM
Add this function to the script:


function sweeptoggle(state){
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=state=='contract'? "none" : "block"
inc++
}
}

It can go right before this one:


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

Use this markup:


<a href="javascript:sweeptoggle('contract');">Contract All</a>
<a href="javascript:sweeptoggle('expand');">Expand All</a>

Twey
04-24-2006, 06:21 PM
You're using an initializer, a condition, and an incrementer. This is what for loops are for.

function sweeptoggle(state){
for(var inc = 0;ccollect[inc];inc++)
ccollect[inc].style.display = (state == 'contract'? "none" : "block");
}Much neater.

jscheuer1
04-24-2006, 07:57 PM
You're using an initializer, a condition, and an incrementer. This is what for loops are for.

function sweeptoggle(state){
for(var inc = 0;ccollect[inc];inc++)
ccollect[inc].style.display = (state == 'contract'? "none" : "block");
}Much neater.

Just using the code already in the script. Much safer to do it that way, than to test 'improvements'.

dlms55
04-25-2006, 12:58 AM
Add this function to the script:


function sweeptoggle(state){
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=state=='contract'? "none" : "block"
inc++
}
}

It can go right before this one:


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

Use this markup:


<a href="javascript:sweeptoggle('contract');">Contract All</a>
<a href="javascript:sweeptoggle('expand');">Expand All</a>


Thanks a million! Now that I see it I feel silly for asking. You guys are the best! I'm sure both options work -- I just used this one because it is the same as the rest of the script.

Dibble
05-11-2006, 03:30 AM
What could I do to make all sections Contract on page load

Dibble
05-11-2006, 04:31 AM
Sorry I found the answer