Results 1 to 10 of 10

Thread: Switch Content Script Issue II

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default Switch Content Script Issue II

    1) Script Title: Switch Content Script Issue

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

    3) Describe problem:

    I'm using it on my portfolio to display and not display a prologue for a book I'm writing. I have two issues:

    one, it's showing the "minus" content on page load, and I want it to be hidden. Since that's the whole reason I have the script. If I wanted the info there at first sight, I wouldn't have any use for this script. how do I change it to hide the content on page load?

    two, the actual text "View Prologue" isn't linked along with the image. I would like it to appear like a link. People will have to play around until they realize they have to click the plus sign to show the content. I'd rather the text be linked, as well. How can I do this?

    The example:

    http://flamehtmlstudios.com/alexjewe...ss&file=nivlaC
    Last edited by alexjewell; 07-19-2006 at 12:25 AM.

  2. #2
    Join Date
    Aug 2004
    Posts
    9,878
    Thanks
    3
    Thanked 962 Times in 951 Posts
    Blog Entries
    15

    Default

    Regarding 1), the easiest way would be to modify function do_onload() as follows:

    Code:
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    ccollect=getElementbyClass(alltags, "switchcontent")
    statecollect=getElementbyClass(alltags, "showstate")
    sweeptoggle('contract')
    if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0)
    revivecontent()
    if (ccollect.length>0 && statecollect.length>0)
    revivestatus()
    }
    The code in red is new. For 2), just add move the onClick code for the plus/minus sign to encompass the entire DIV header code:

    Code:
    <div class="headers" onClick="expandcontent(this, 'sc1')" style="color: blue; text-decoration: underline"><img src="minus.gif" class="showstate"/>What is JavaScript?</div>

  3. #3
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contract on first view

    Just a slight variation on #1 above:

    Like the poster above, I want contract to be the default, except if a user has a cookie specifying otherwise.

    It seems the solution above will always contract on load. Is there a way to defer to the cookies if the user has opened it before?

    Thanks.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

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

    Default Something in the revised code conflicts with CMotion Image Gallery

    I was excited to find this enhancement to the Switch Content II script, and it worked as anticipated with one exception:

    Any instance that I had of the CMotion Image Gallery stopped working when I switched to the revised version of the Switch Content script. They all work perfectly under the original script.

    So... what is conflicting?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Mminnig
    I was excited to find this enhancement to the Switch Content II script, and it worked as anticipated with one exception:

    Any instance that I had of the CMotion Image Gallery stopped working when I switched to the revised version of the Switch Content script. They all work perfectly under the original script.

    So... what is conflicting?
    Most likely it is an onload conflict but, it could be something else. Generally these type of questions are often ignored due to their complexity but, if you would be willing to provide a link to your page that is exhibiting this problem, I will see if I can find it and fix it.
    - John
    ________________________

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

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

    Default Very Odd

    Thank you for your help. Below are links to sample pages with the original Switch Content Script as well as one with the new Script.

    Original Switch Content Script (note the red and purple areas scroll):
    http://www.kydex.com/test/default_working.asp

    New Switch Content Script (scrolling in red and purple areas stopped):
    http://www.kydex.com/test/default.asp

    The only difference between these two links is the updated Switch Content Script.

    The original works as expected with the exception that I would prefer it to start with all items closed.

    Let me know if you need more info about the structure of the pages or the thought process behind them as I realize that this is probably really hard to track down. I greatly appreciate your help.


    As an added note: The collapsable areas each contain an IFRAME which points to the content housed in seperate .asp files. If you go directly to the .asp file, everything works beautifully: http://www.kydex.com/test/widget_articles.asp.
    Last edited by Mminnig; 08-25-2006 at 05:22 PM.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    First of all, both demos worked in Opera. The updated one did not work in IE or FF.

    If I thought about this for awhile I could probably figure out why but, instinctively I just tried initializing the CMotion Image Gallery in its iframe after it had been expanded:

    Code:
    window.frames[2].fillup()
    from the top page for the widget_partgallery.asp iframe and:

    Code:
    window.frames[3].fillup()
    for the widget_articles.asp iframe. That did the trick. So, apparently these scripts need to be initialized after their content is displayed. How soon after, will determine the exact type of code fix required but, if we are lucky, something like so will work -

    Change this:

    Code:
    onClick="expandcontent(this, 'partgallery')"
    to this:

    Code:
    onClick="expandcontent(this, 'partgallery');window.frames[2].fillup();"
    and similarly for the 'articles':

    Code:
    onClick="expandcontent(this, 'articles');window.frames[3].fillup();"
    If we are not so lucky, we may need to devise a poll so that the content being initialized is fully available before it is initialized. And we may need to prevent these extra calls from firing more than once but, give it a try and see what happens. I usually fully test something like this locally myself but, due to the nature of iframes and security across domains, any test of that sort here on my machine would be quite complicated to setup. Since you already have all the files in one place, it should be fairly simple for you to see what happens.

    Let me know.
    - John
    ________________________

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

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

    Default Very Nice!

    Thank you. It looks like you are correct!
    http://www.kydex.com/test

    The one catch is that if you leave one of them open.... then refresh the page... you have to close and reopen the content to initialize it and get it to scroll....

    Can we put the call to initialize on something other than the "OnClick"?

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,192 Times in 3,155 Posts
    Blog Entries
    12

    Default

    I would think that we would still need the onclick event for those times when the content was not initially displayed. There is a place in the Switch Content script where the items open from the previous page load, if any were open, are opened. Right after that would probably be a good place to also initialize these two iframe's content:

    Code:
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    ccollect=getElementbyClass(alltags, "collapsable_content_green")
    statecollect=getElementbyClass(alltags, "showstate")
    if(!initialstate){
    sweeptoggle('contract', 1)
    document.getElementById('added').disabled=true
    }
    if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0) {
    revivecontent()
    window.frames[2].fillup();
    window.frames[3].fillup();
    }
    if (ccollect.length>0 && statecollect.length>0)
    revivestatus()
    }
    Be sure not to miss both of the added curly braces. Once again, this might be a problem for when those items aren't displayed and a poll or test may need to be developed to prevent them from firing when it is inappropriate and to fire at the optimal point in time as well. Ideally, a separate function could be made up that takes care of all that. It could be called from the above function and from each item's onclick event. However, if there are no errors, this would be more trouble than it is worth in my opinion.
    - 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
  •