jquery plugin template


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



Copy this code and paste it in your HTML
  1. (function($){
  2. $.yourPluginName = function(el, radius, options){
  3. // To avoid scope issues, use 'base' instead of 'this'
  4. // to reference this class from internal events and functions.
  5. var base = this;
  6.  
  7. // Access to jQuery and DOM versions of element
  8. base.$el = $(el);
  9. base.el = el;
  10.  
  11. // Add a reverse reference to the DOM object
  12. base.$el.data("yourPluginName", base);
  13.  
  14. base.init = function(){
  15. if( typeof( radius ) === "undefined" || radius === null ) radius = "20px";
  16.  
  17. base.radius = radius;
  18.  
  19. base.options = $.extend({},$.yourPluginName.defaultOptions, options);
  20.  
  21. // Put your initialization code here
  22. };
  23.  
  24. // Sample Function, Uncomment to use
  25. // base.functionName = function(paramaters){
  26. //
  27. // };
  28.  
  29. // Run initializer
  30. base.init();
  31. };
  32.  
  33. $.yourPluginName.defaultOptions = {
  34. radius: "20px"
  35. };
  36.  
  37. $.fn.yourPluginName = function(radius, options){
  38. return this.each(function(){
  39. (new $.yourPluginName(this, radius, options));
  40.  
  41. // HAVE YOUR PLUGIN DO STUFF HERE
  42.  
  43. // END DOING STUFF
  44.  
  45. });
  46. };
  47.  
  48. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.