Results 1 to 7 of 7

Thread: Switch Content II

  1. #1
    Join Date
    Aug 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Content II

    1) Script Title: Switch Content II

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...chcontent2.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.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Well, the easiest way is just to modify function expandcontent() with one new line:

    Code:
    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.

  3. #3
    Join Date
    Aug 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Aug 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is it possible?

    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?

  5. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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.

  6. #6
    Join Date
    Aug 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks

    Thank you ahead of time. Any help you can provide is greatly appreciated.

  7. #7
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •