More complete, each widget binds to that remove-event to call its
destroy-method. Though due to the event-handling overhead involved, we
explored other approaches

Jörn

On Mon, Dec 14, 2009 at 6:42 PM, John Resig <jere...@gmail.com> wrote:

> jQuery UI does a similar thing (overriding .remove() to generate a
> .trigger("remove") event). Would something like that work for your
> needs?
>
> --John
>
>
>
> On Mon, Dec 14, 2009 at 11:43 AM, Justin Meyer <justinbme...@gmail.com>
> wrote:
> > Is there a 'teardown' for plugins that can get triggered automatically
> > (similar to that for events)?
> >
> > It's extremely common, and a source of bugs when I see:
> >
> > $.fn.mySuperPlugin = function(){
> > ...code ...
> > $(document).click(function(e) { ...code... });
> > ...code...
> > }
> >
> > Yes, they should be doing adding/removing this event listener every
> > time their widget 'comes to life'.  But there are cases where even
> > this doesn't work.
> >
> > I think I remember John talking about this when we were discussing
> > "jQuery Enterprise".  It was something like:
> >
> > $.fn.extend("pluginName",{
> >  setup: function( ...),
> >  teardown: function( ...)
> > })
> >
> > In JMVC, I've hacked .remove() to enable plugins to write 'teardown'
> > functionality.  For jQuery, when you use the fn.extend function, it
> > will wrap setup with something that would add teardown to something
> > like:
> >
> > $(el).data("plugins")["pluginName"] = teardown.
> >
> >
> > When remove() is called, it will get all the plugins on the current
> > element, and call their teardown code.
> >
> > Someone would also be able to remove a single plugin like:
> >
> > $(el).data("plugins")["pluginName"]()
> >
> >
> > Ugly, but the case where you want to remove just one plugin is rare.
> >
> > Thoughts?
> >
> > --
> >
> > You received this message because you are subscribed to the Google Groups
> "jQuery Development" group.
> > To post to this group, send email to jquery-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com>
> .
> > For more options, visit this group at
> http://groups.google.com/group/jquery-dev?hl=en.
> >
> >
> >
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "jQuery Development" group.
> To post to this group, send email to jquery-...@googlegroups.com.
> To unsubscribe from this group, send email to
> jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to