PDA

View Full Version : Switch Content Expand Single Group



rhoadesm
09-08-2008, 03:25 PM
1) Script Title: Switch Content Script II (icon based)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

3) Describe problem: I see there is a 'instance.sweepToggle('contract/expand')' function to expand all contents within a switch group but I only wish to expand on a certain section within the switch group. How do I do this? I can do the basics in javascript but that is about it.

Thanks

ddadmin
09-08-2008, 11:32 PM
It really depends on the details as far as which contents you wish to exclude from contracting/ expanding within the group when calling sweepToggle(). The pertaining function inside switchcontent.js FYI is:


switchcontent.prototype.sweepToggle=function(setting){ //PUBLIC: Expand/ contract all contents method. (Values: "contract"|"expand")
if (typeof this.headers!="undefined" && this.headers.length>0){ //if there are switch contents defined on the page
for (var i=0; i<this.headers.length; i++){
if (setting=="expand")
this.expandcontent(this.headers[i]) //expand each content
else if (setting=="contract")
this.contractcontent(this.headers[i]) //contract each content
}
}
}

Lets say you're able to label the target icons manually using a "title" attribute like so:


What is JavaScript? <span id="faq1-title" class="iconspan"><img src="minus.gif" /></span>
<div id="faq1" class="icongroup1" title="exclude">
JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents.
</div>

What is DHTML? <span id="faq2-title" class="iconspan" title="exclude"><img src="minus.gif" /></span>
<div id="faq2" class="icongroup1">
DHTML is the embodiment of a combination of technologies
</div>

Then you can modify the pertaining function above to ignore those icons' contents by doing:


switchcontent.prototype.sweepToggle=function(setting){ //PUBLIC: Expand/ contract all contents method. (Values: "contract"|"expand")
if (typeof this.headers!="undefined" && this.headers.length>0){ //if there are switch contents defined on the page
for (var i=0; i<this.headers.length; i++){
if (setting=="expand" && this.headers[i].title!="exclude")
this.expandcontent(this.headers[i]) //expand each content
else if (setting=="contract" && this.headers[i].title!="exclude")
this.contractcontent(this.headers[i]) //contract each content
}
}
}