PDA

View Full Version : Switch Content II



Mminnig
08-29-2006, 07:06 PM
1) Script Title: Switch Content II

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

3) Describe problem: Is it possible to alter this script so that only one content area can be open at a time? In other words, opening one area will cause any others that are open to be closed?

My sample site is at: http://www.kydex.com/test

Currently, you can open any or all of the content areas on the right. I would like to make it so that only one can be open at a time.

ddadmin
08-30-2006, 03:48 AM
Well, the easiest way is just to modify function expandcontent() with one new line:


function expandcontent(curobj, cid){
sweeptoggle("contract")
if (ccollect.length>0){
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
}
}

The only issue I see is that the content in question can't be closed explicitly, but rather, swapping visibility amongst the other contents. If you need that added feature, I'll have to post an update later.

Mminnig
08-30-2006, 09:15 PM
Thank you for your response. It worked very well. How difficuly would it be to modify the script so that each could be closed explicitly?

www.kydex.com/test

Mminnig
09-05-2006, 04:55 PM
So... is it possible to modify this (Switch Content II) script such that only one content area can be open at a time, but each can be closed explicitly?

ddadmin
09-05-2006, 06:55 PM
It definitely is possible, though if I recall not as simple as I thought it'd be. I'll have to get back to this thread when I have some free time this week.

Mminnig
09-07-2006, 01:11 PM
Thank you ahead of time. Any help you can provide is greatly appreciated.

ddadmin
09-13-2006, 05:32 AM
Ok, script updated to resolve the issue with the current content not being able to be explicitly closed. Replace function sweeptoogle() and expandcontent() in the original script with the below versions instead:


function sweeptoggle(ec, optignore){
var inc=0
while (ccollect[inc]){
if (!(typeof optignore!="undefined" && ccollect[inc].id==optignore))
ccollect[inc].style.display=(ec=="contract")? "none" : ""
inc++
}
revivestatus()
}


function expandcontent(curobj, cid){
sweeptoggle("contract", cid)
if (ccollect.length>0){
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
}
}

The parts in red are new (from the original code). To summarize again, the above changes will cause the script to only open one switch content at any given time (closing the rest). The target switch content can still be closed or open as desired.