I have to create a document that provides a “model” for how to write jQuery plugins for a large site.
For example: all plugins should have:
$.fn.somePlugin = function() {
return this.each(function() {
// Here the plugins does its goal.
});
};
so they respect the fluent model and also they can be called with multiple elements at same time. Some other things I think they should all have are:
- Options getter and setter (like in jQuery-ui)
- Methods (like in jQuery-ui)
- Some way to change default options. Of course this should be done without modifying the plugin file (again, like jQuery-ui).
How would it be your “Model Plugin”? (achieving this and some other things you think necessary in the best possible way).
Result
Here you can see my plugin template based on all the information I read.
The jquery docs have a section on plugin authoring:
http://docs.jquery.com/Plugins/Authoring
and here’s the “slides” from ben almans talk on plugin authoring from the boston jquery conference:
https://github.com/cowboy/talks/blob/master/jquery-plugin-authoring.js
and one more link from ben alman about writing plugins.
http://msdn.microsoft.com/en-us/scriptjunkie/ff696759