I would like a bit of assistance from anyone who can help me create a plugin to encapsulate my code...
I understand the basics of plugin development... what I don't understand is how to best handle different methods/functions. And maybe a plugin is not the right approach?
Let's say I want to do 3 possible things in my plugin.
1. register a form to be validated and submitted
2. un-register a form
3. process form submission results returned via json
Using the standard pattern, i would declare the function and it would loop through all the selectors passed. However, I don't understand how i would one time register... and the next unregister... using a solid/proven jQuery patterned approach!
a. Would I use options, and within the body call the appropriate function(s)?
$.fn. pluginName {options...
for this.each( function()...
if optA then Register...
etc....
});
return this;
};
register = function()...
unRegister = function()...
}
b. would I write different plugins:
$.fn.pluginRegister...
$.fn.pluginUnRegister...
c. or possibly different functions in the plugin:
$.fn.pluginName.register...
$.fn. pluginName.unRegister...
and then call them $("selector").pluginName.register(...);
d. or finally should i just do global functions and clutter up the namespace?
$.register...
$.unRegister...
From an object oriented development approach, I can model this different ways, however, it seems like I'm missing something regarding the jQuery encapsulation. I would appreciate some good help
btw... i've reviewed all the plugin development examples on the web, and they all handle basic scenarios. also, i've looked an many of the popular plugins i'm using, and they use such different approaches, i'm still just feel like i'm missing something.
thanks!
Patrick