jQuery Plugin Template


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.