PDA

View Full Version : Switch Content Script tweak



ardesmond
01-15-2007, 11:08 PM
1) Script Title: Switch Content Script

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

jscheuer1
01-16-2007, 05:26 AM
You are supposed to leave the headers, ex:


<h3 id="bobcontent1-title" class="handcursor">What is JavaScript?</h3>

for each content division, ex:


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

ardesmond
01-16-2007, 05:52 AM
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!

ddadmin
01-16-2007, 05:57 AM
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?

ardesmond
01-16-2007, 01:39 PM
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.

ardesmond
01-17-2007, 03:44 AM
Perhaps an example would help...

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

jscheuer1
01-17-2007, 05:17 AM
In the version of the script that you are using, just find this function and add the red comment delimiters as shown:


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

ddadmin
01-17-2007, 07:08 AM
Yep, didn't know you were referring to the old version of the script. It has been recently rewritten fyi: http://www.dynamicdrive.com/dynamicindex17/switchcontent.htm

ardesmond
01-17-2007, 01:39 PM
Would this same fix work for the rewritten version?

That works perfectly, thanks!

jscheuer1
01-17-2007, 03:30 PM
No. If you were to make this modification (add the red part):


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.