I've created a jQuery wee plugin for myself which takes care of showing, hiding and submitting a form to give in-place editing. Currently I have several of these on a page which function independently and I am happy. However, I'm thinking that an 'Edit All' might be useful. I'd therefore want to be able to access all instances of the plugin within the page and access their show/hide/validate/submit functions in unison. Is there a way to do this?
A:
Hmmm I guess I could create an array of instances...
var plugins = new Array();
plugins.push($('first_editable_section').pluginThing());
plugins.push($('second_editable_section').pluginThing());
and access them through that.
jammus
2008-10-16 12:11:17
+3
A:
Use the custom events in jQuery to make this easy.
Something like this:
(function($) {
$.fn.myPlugin = function() {
return this.each(function(){
//Plugin Code Goes Here
$(this).bind("pluginEdit",function(){
internalEditFunction();
});
});
};
})(jQuery);
Then you can just
$(selector).trigger("pluginEdit");
Josh Bush
2008-10-17 21:35:17
Just came back to this and it perfectly solved another (slightly related) problem I was having. Thanks loads.
jammus
2008-12-01 12:25:11