Results 1 to 10 of 10

Thread: Switch Content Script tweak

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

    Default Switch Content Script tweak

    1) Script Title: Switch Content Script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...tchcontent.htm

    3) Describe problem: I'm using this to switch between blocks of content rather than separate the content into separate pages. I've got everything working properly, with one little bug...if the user clicks on the button for the currently active content, the content is hidden and this results in an empty page. Is there a way to tweak the script to check to see if the current div is the one being expanded/contracted, and if so, do nothing?

    Does that make sense?

  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

    You are supposed to leave the headers, ex:

    HTML Code:
    <h3 id="bobcontent1-title" class="handcursor">What is JavaScript?</h3>
    for each content division, ex:

    HTML Code:
    <div id="bobcontent1" class="switchgroup1">
    JavaScript is a scripting language originally developed by Netscape to add interactivity
    and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
    </div>
    outside of the content division. That way, even when everything is contracted, the page is not blank.
    - John
    ________________________

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

  3. #3
    Join Date
    Apr 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By blank I don't mean a completely white screen devoid of graphics or characters. The main content portion of the page is what I'm talking about. The headers are in a separate menu area, so they are always there. I'm just looking for a way to prevent the script from contracting a div that's already visible.

    Thanks!

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

    Default

    Can you clarify what you mean by "button" in the below:

    ...if the user clicks on the button for the currently active content, the content is hidden and this results in an empty page.
    Do you mean "header"? The very nature of the script means clicking a header will either expand or contract it. Are you asking how to basically only have the script expand a header, disabling entirely the contract part?

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

    Default

    Well, that depends on what you mean by entirely. Obviously I want the content to contract when the user clicks on another header, revealing different content.

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

    Default

    Perhaps an example would help...

    http://www.adamandwindy.com/test.htm

  7. #7
    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

    In the version of the script that you are using, just find this function and add the red comment delimiters as shown:

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

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

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

    Default

    Yep, didn't know you were referring to the old version of the script. It has been recently rewritten fyi: http://www.dynamicdrive.com/dynamici...tchcontent.htm

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

    Default

    Would this same fix work for the rewritten version?

    That works perfectly, thanks!

  10. #10
    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

    No. If you were to make this modification (add the red part):

    Code:
    switchcontent.prototype.toggledisplay=function(header){
    var innercontent=document.getElementById(header.id.replace("-title", "")) //Reference content for this header
    if (innercontent.style.display=="block" && this.prevHeader.id!=header.id)
    this.contractcontent(header)
    else{
    this.expandcontent(header)
    if (this.collapsePrev && typeof this.prevHeader!="undefined" && this.prevHeader.id!=header.id) // If "Collapse Previous" is enabled and there's a previous open content
    this.contractcontent(this.prevHeader) //Contract that content first
    }
    if (this.collapsePrev)
    this.prevHeader=header //Set current expanded content as the next "Previous Content"
    }
    It will do it in the newer version, at least for the most part, perhaps entirely. I would want to reserve judgement though until you tried this out thoroughly as, additional modifications might be required to cover all possible contingencies that might arise in the course of using the newer version with this modification.
    - John
    ________________________

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

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
  •