views:

222

answers:

1

Is there a way to extend the toggle method in prorotypejs to allow for injection of an effect function, eg, scriptaculous effects or FBJS

A: 

You could use something similar to this that I wrote for the Effect.SlideDown/Up, should work for Fade/Appear. jQuery provides a slideToggle function, which has similar syntax... this could be written better, but for lack of time:

<script>
function slideToggle(id,time) {

    toggle = typeof(toggle)=='undefined' ? true : toggle;

    if (toggle) {
     Effect.SlideDown(id, { duration: time });
     toggle = false;
    }
    else {
     Effect.SlideUp(id, { duration: time });
     toggle = true;
    }
}
</script>

<a href="#" onclick="javascript:slideToggle('hidden',0.5); return false;">Click to Toggle</a>

<div id="hidden" style="display:none;">
<div>Hey Yourself!</div>
</div>
Bryan