hi there,
i need to implement a "toggle" effect (
http://docs.jquery.com/Effects/slideToggle) within a wicket page. i checked out wickext's latest trunk version but i haven't found it.
so i implemented my own:
public class SlideToggleEffect implements Effect {
public String getEffectString() {
return "slideToggle";
}
}
but quite troublesome with the usage. i didn't find any examples of this (or similar).
what is not really clear to me, is the fact that the effects are triggered when the behaviour is added to the component - i doubt this is desirable.
for example, if i do: comp.add(new EffectBehavior(new SlideToggleEffect(), EffectSpeed.SLOW); and my comp to the page, then when i load the page on my browser i'll notice the effect (basically a slow slideUp, because the target div was already displayed).
how can i avoid this? i mean, i just wanted to be able to associate a trigger (like the WickextEventBehavior) to a link and fire the effect from there.
i ultimately came up with a sort of workaround...
makeCommentLink.add(new WickextEventBehavior(MouseEvent.CLICK) {
@Override
public CharSequence callbackStatement() {
return makeCommentToggleEffectBehavior.getCallbackStatement();
}
});
add(makeCommentLink);
and adding to EffectBehavior.java
public CharSequence getCallbackStatement() {
JavaScriptBuilder queryBuilder = new JavaScriptBuilder();
queryBuilder = new JavaScriptBuilder(component);
queryBuilder.$().call(this);
return queryBuilder.getStatement();
}
but i don't feel this is clean. i still have to add the behaviour to my component, which triggers the effect on page loading. if i do this via an AjaxLink, and call: comp.add(slideToggleEffectBehavior); target.addComponent(comp); -> each time this callback is executed, i add once again the behavior, and thus the effect is trigger more than once! after the second or third click you see it going up and down, up and down... which means i will have to keep some state and decide whether or not to update. this path seems too complex.
what's the proper (or intended) way of calling an effect? could you provide the "wickext approach" / best practice? can i just use it with standard onClick method of a Link and avoid the MouseEvent.CLICK?
thanks a lot! good work, btw.
francisco