PDA

View Full Version : Switch Content Script Issue II



alexjewell
07-18-2006, 11:53 PM
1) Script Title: Switch Content Script Issue

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.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/alexjewell/port/writing/?catagory=Novel&progress=In%20Progress&file=nivlaC

ddadmin
07-19-2006, 02:52 AM
Regarding 1), the easiest way would be to modify function do_onload() as follows:


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:


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

ctrauer
07-28-2006, 06:07 PM
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.

jscheuer1
07-30-2006, 09:13 AM
see:

http://www.dynamicdrive.com/forums/showpost.php?p=31994&postcount=2

Mminnig
08-25-2006, 04:15 PM
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?

jscheuer1
08-25-2006, 04:51 PM
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.

Mminnig
08-25-2006, 05:16 PM
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.

jscheuer1
08-25-2006, 07:34 PM
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:


window.frames[2].fillup()

from the top page for the widget_partgallery.asp iframe and:


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:


onClick="expandcontent(this, 'partgallery')"

to this:


onClick="expandcontent(this, 'partgallery');window.frames[2].fillup();"

and similarly for the 'articles':


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.

Mminnig
08-25-2006, 08:02 PM
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"?

jscheuer1
08-25-2006, 08:47 PM
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:


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.