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.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to