Posted By

mdrisser on 12/28/09


Tagged

jquery plugins


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

mdrisser
nerdfiles
matpolster


jQuery Plugin Template


 / Published in: JavaScript
 

Pretty straight forward. Replace 'PLUGIN_NAME' with the name of your plugin, add your code in the appropriate places, test and deploy.

Should be pretty easy to use, I commented it heavily.

  1. // Create Closure
  2. (function($) {
  3. $.fn.PLUGIN_NAME = function(options) {
  4. // Extend the defaults, over-writing them with anything passed by the caller
  5. var opts = $.extend({}, $.fn.PLUGIN_NAME.defaults, options);
  6.  
  7. // Iterate over each element
  8. return this.each(function() {
  9. $this = $(this);
  10.  
  11. // Allow for use of the Metadata plugin
  12. var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
  13.  
  14. // YOUR CODE GOES HERE
  15.  
  16. });
  17. };
  18.  
  19. // Additional methods follow the format:
  20. // $.fn.PLUGIN_NAME.format = function(txt) {
  21. // FUNCTION STUFF GOES HERE
  22. // };
  23.  
  24. // Plugin Defaults
  25. $.fn.PLUGIN_NAME.defaults = {
  26.  
  27. };
  28. })(jQuery); // Closure Closed

Report this snippet   <

You need to login to post a comment.