Results 1 to 7 of 7

Thread: Contractible Headers Script -- Expand/Contract ALL

  1. #1
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contractible Headers Script -- Expand/Contract ALL

    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!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Add this function to the script:

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

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

    HTML Code:
    <a href="javascript:sweeptoggle('contract');">Contract All</a>
    <a href="javascript:sweeptoggle('expand');">Expand All</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You're using an initializer, a condition, and an incrementer. This is what for loops are for.
    Code:
    function sweeptoggle(state){
      for(var inc = 0;ccollect[inc];inc++)
        ccollect[inc].style.display = (state == 'contract'? "none" : "block");
    }
    Much neater.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    You're using an initializer, a condition, and an incrementer. This is what for loops are for.
    Code:
    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'.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thank you ... Thank you ... Thank you!

    Quote Originally Posted by jscheuer1
    Add this function to the script:

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

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

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

  6. #6
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What could I do to make all sections Contract on page load

  7. #7
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry I found the answer

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
  •