tags:

views:

101

answers:

2

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
+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
Just came back to this and it perfectly solved another (slightly related) problem I was having. Thanks loads.
jammus