PDA

View Full Version : SwitchContent - Strange Timing(?) Bug



ExTexan
11-29-2008, 03:45 PM
Switch Content Script II (icon based)
http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

I just installed the above script and got it working - sort of. But here's the strange part... I have to insert an "alert" to get it to work. I'm relatively sure I have all my HTML stuff set up right, coz I CAN get it to work in one situation.

=== This does NOT work...

var details = new switchicon("detailgroup", "div");
details.setHeader('<img src="<?php echo $sRelPath ?>css/basic/minus.gif" />', '<img src="<?php echo $sRelPath ?>css/basic/plus.gif" />');
details.collapsePrevious(false);
details.setPersist(false);
details.init();
details.sweepToggle('expand');

=== This DOES work...

var details = new switchicon("detailgroup", "div");
alert('got here');
details.setHeader('<img src="<?php echo $sRelPath ?>css/basic/minus.gif" />', '<img src="<?php echo $sRelPath ?>css/basic/plus.gif" />');
details.collapsePrevious(false);
details.setPersist(false);
details.init();
details.sweepToggle('expand');

I'm stumped. Any help would be greatly appreciated.

ddadmin
11-30-2008, 01:13 AM
The first scenario should work too.Make sure the configuration code:


var details = new switchicon("detailgroup", "div");
details.setHeader('<img src="<?php echo $sRelPath ?>css/basic/minus.gif" />', '<img src="<?php echo $sRelPath ?>css/basic/plus.gif" />');
details.collapsePrevious(false);
details.setPersist(false);
details.init();
details.sweepToggle('expand');

is called at the end, following all the HTML for the switch contents themselves. If you still need help, please post a link to the page on your site that contains the problematic script so we can check it out.

p.s: Please try and format any code in your post using the CODE tags. It just makes it easier to read.

ExTexan
12-04-2008, 05:47 AM
That's what I thought. Question is... why does it work *with* the alert?

I'm testing this locally, so unfortunately I don't have it online for you to see yet. I guess I need to give a few more details about my scripts...

I have a main script that sets up a tabbed page using DIVs (named divtab0,1,...n) for each tab. The div content is supplied via AJAX calls to "mainviewtab0,1,2...n". The collapsible divs are rendered in "mainviewtab0" (in this case).

In "main", when I click a button, it executes a javascript function that does the AJAX call. When it returns from the AJAX call (using prototypejs), I then do the "details = new switchicon(...)" there. Forgive the newbie stuff here, but I couldn't figure out how to make the "details" var (function) global so that it would work when i clicked the + and - icons for my collapsible DIVs. Perhaps that's the source of the problem. I set "details" to null outside the function to make it global, then let it get "redefined" inside. How can I make your DD switchcontent work in this situation?

ddadmin
12-04-2008, 06:35 AM
It's hard to get a complete idea of how you have everything set up based on just the above. If you're saying the contents for Switch Content script are fetched dynamically via Ajax, with a call to new switchicon() occuring after that, it's possible you're calling switchicon() prematurely. Make sure you're calling it through some event handler that fires when the Ajax request has fully completed.

The reason why by adding an alert() things seem to work is probably because of the delay it adds.