Hi,

AFAIK jQuery unbinds all registered event listeners for a DOM element
when this element is removed with jQuery method like #remove(),
#replaceWith(), etc.
But I'm not sure this is the case when you remove a parent element of
an element with event listeners. Better ask in jQuery forums.

On Thu, Mar 15, 2012 at 11:22 AM, Stijn de Witt
<[email protected]> wrote:
> Hi. We are using WiQuery in our application to attach some behaviors to some 
> components. For example a resize behavior to react on the component being 
> resized. I added some debug logging and I see that when we switch panels 
> (through Ajax) all event listeners for the components on the new panel are 
> added, but the old ones from the panel being replaced are never removed. So 
> the list of event handlers just grows and grows...
>
> We register event listeners in the statement method of the WiQuery behavior, 
> like this:
>
> public abstract class BaResizeEventBehavior extends WiQueryAbstractBehavior {
>  // ...
>  @Override public JsStatement statement() {
>    return new JsQuery(getComponent()).$().chain("resize", new JsScope() {
>      @Override public void execute(JsScopeContext aScopeContext) {
>        // event listener implementation here
>      }
>    });
>  }
> }
>
> This will generate Javascript code that looks like this:
>
> $('#componentId').resize(function() {
>  // event listener implementation here
> });
>
> This code will register a jQuery event on the component with id 
> 'componentId'. However when this component disappears from the page, I would 
> like this event handler to be unbound again, but that does not happen.
>
> Any ideas?
>
> Thanks,
>
> -Stijn
>
> P.S:
> This is cross-posted to 
> http://groups.google.com/group/wiquery-plugins/browse_thread/thread/aaceac38d60adbcf
>  because that group seems to have hardly any traffic... Hopefully one of the 
> Wicket gurus here knows a bit about WiQuery as well? Although maybe this 
> question can be formulated for Wicket as well as also there when doing Ajax 
> we need to clean up after components when they are removed from the page 
> right?



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to