Posted By

onefastsnail on 05/24/12


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mister
hurcy


jquery plugin


 / Published in: JavaScript
 

  1. (function($){
  2.  
  3. $.fn.extend({
  4. fvalidator:function(options) {
  5.  
  6. var base = this;
  7.  
  8. //Set the default values, use comma to separate the settings, example:
  9. var defaults = {
  10. padding: 20,
  11. mouseOverColor : '#000000',
  12. mouseOutColor : '#ffffff'
  13. }
  14.  
  15. //add user defined settings
  16. var options = $.extend(defaults, options);
  17.  
  18. // initialization code here
  19. base.init = function(){
  20. alert(base.attr("id"));
  21. };
  22.  
  23. // example Function declare before the base.init call
  24. // base.functionName = function(paramaters){
  25. //
  26. // };
  27.  
  28. // Run initializer
  29. base.init();
  30.  
  31. //more code here
  32.  
  33. return base;
  34.  
  35. }
  36. });
  37.  
  38. })(jQuery);
  39.  
  40.  
  41.  
  42.  
  43. (function($){
  44.  
  45. $.fn.extend({
  46.  
  47. //pass the options variable to the function
  48. pluginname: function(options) {
  49.  
  50.  
  51. //Set the default values, use comma to separate the settings, example:
  52. var defaults = {
  53. padding: 20,
  54. mouseOverColor : '#000000',
  55. mouseOutColor : '#ffffff'
  56. }
  57.  
  58. var options = $.extend(defaults, options);
  59.  
  60. return this.each(function() {
  61. var o = options;
  62.  
  63. //code to be inserted here
  64. //you can access the value like this
  65. alert(o.padding);
  66.  
  67. });
  68. }
  69. });
  70.  
  71. })(jQuery);
  72.  
  73. (function($){
  74. $.yourPluginName = function(el, radius, options){
  75. // To avoid scope issues, use 'base' instead of 'this'
  76. // to reference this class from internal events and functions.
  77. var base = this;
  78.  
  79. // Access to jQuery and DOM versions of element
  80. base.$el = $(el);
  81. base.el = el;
  82.  
  83. // Add a reverse reference to the DOM object
  84. base.$el.data("yourPluginName", base);
  85.  
  86. base.init = function(){
  87. if( typeof( radius ) === "undefined" || radius === null ) radius = "20px";
  88.  
  89. base.radius = radius;
  90.  
  91. base.options = $.extend({},$.yourPluginName.defaultOptions, options);
  92.  
  93. // Put your initialization code here
  94. };
  95.  
  96. // Sample Function, Uncomment to use
  97. // base.functionName = function(paramaters){
  98. //
  99. // };
  100.  
  101. // Run initializer
  102. base.init();
  103. };
  104.  
  105. $.yourPluginName.defaultOptions = {
  106. radius: "20px"
  107. };
  108.  
  109. $.fn.yourPluginName = function(radius, options){
  110. return this.each(function(){
  111. (new $.yourPluginName(this, radius, options));
  112.  
  113. // HAVE YOUR PLUGIN DO STUFF HERE
  114.  
  115. // END DOING STUFF
  116.  
  117. });
  118. };
  119.  
  120. })(jQuery);

Report this snippet  

You need to login to post a comment.