PDA

View Full Version : Switch Content - always have 1 group expanded



katebellami
05-14-2013, 10:13 PM
1) Script Title: Switch Content Script

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

3) Describe problem: Hi,
I just finished setting up the switch content script on this site page: http://www.promisefoundation.org/newsite/awareness.php

I would like to always have 1 group expanded (so that each will only contract when swapped with another). No more than one should be open at a time. And I am not worried about whether or not persist works.

Any help would be much appreciated. Thanks!

jscheuer1
05-15-2013, 06:20 AM
I see you've already modified the switchcontent.js file to include some image swapping. And, as it turns out I already had a version of this script that includes a keepOneOpen() function. But it was from before the AJAX update. However, you're not using that. So here's what to do. Download and use this version of the script to which I've already added your swap() function modifications (right click and 'Save As'):

5060

Then in the on page init for the script, change:


<script type="text/javascript">
// MAIN FUNCTION: new switchcontent("class name", "[optional_element_type_to_scan_for]") REQUIRED
// Call Instance.init() at the very end. REQUIRED

var promiseexample=new switchcontent("switchgroup1", "div") //Limit scanning of switch contents to just "div" elements
promiseexample.setColor('darkred', 'black')
promiseexample.setPersist(true)
promiseexample.collapsePrevious(true) //Only one content open at any given time
promiseexample.init()
</script>


to:


<script type="text/javascript">
// MAIN FUNCTION: new switchcontent("class name", "[optional_element_type_to_scan_for]") REQUIRED
// Call Instance.init() at the very end. REQUIRED

var promiseexample=new switchcontent("switchgroup1", "div") //Limit scanning of switch contents to just "div" elements
promiseexample.setColor('darkred', 'black')
promiseexample.keepOneOpen('remain')
promiseexample.collapsePrevious(true) //Only one content open at any given time
promiseexample.defaultExpanded(0)
promiseexample.setPersist(true)
promiseexample.init()
</script>


The browser cache may need to be cleared and/or the page refreshed to see changes.

katebellami
05-16-2013, 12:09 AM
Worked like a charm! As always, thank you and you are awesome!!