/ Published in: JavaScript
Expand |
Embed | Plain Text
(function($){ $.fn.extend({ fvalidator:function(options) { var base = this; //Set the default values, use comma to separate the settings, example: var defaults = { padding: 20, mouseOverColor : '#000000', mouseOutColor : '#ffffff' } //add user defined settings var options = $.extend(defaults, options); // initialization code here base.init = function(){ alert(base.attr("id")); }; // example Function declare before the base.init call // base.functionName = function(paramaters){ // // }; // Run initializer base.init(); //more code here return base; } }); })(jQuery); (function($){ $.fn.extend({ //pass the options variable to the function pluginname: function(options) { //Set the default values, use comma to separate the settings, example: var defaults = { padding: 20, mouseOverColor : '#000000', mouseOutColor : '#ffffff' } var options = $.extend(defaults, options); return this.each(function() { var o = options; //code to be inserted here //you can access the value like this alert(o.padding); }); } }); })(jQuery); (function($){ $.yourPluginName = function(el, radius, options){ // To avoid scope issues, use 'base' instead of 'this' // to reference this class from internal events and functions. var base = this; // Access to jQuery and DOM versions of element base.$el = $(el); base.el = el; // Add a reverse reference to the DOM object base.$el.data("yourPluginName", base); base.init = function(){ if( typeof( radius ) === "undefined" || radius === null ) radius = "20px"; base.radius = radius; base.options = $.extend({},$.yourPluginName.defaultOptions, options); // Put your initialization code here }; // Sample Function, Uncomment to use // base.functionName = function(paramaters){ // // }; // Run initializer base.init(); }; $.yourPluginName.defaultOptions = { radius: "20px" }; $.fn.yourPluginName = function(radius, options){ return this.each(function(){ (new $.yourPluginName(this, radius, options)); // HAVE YOUR PLUGIN DO STUFF HERE // END DOING STUFF }); }; })(jQuery);
You need to login to post a comment.
