/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// A boilerplate for kick-starting jQuery plugins development // version 1.2, April 29th, 2011 // by Stefan Gabos // with help from Steven Black, Rob Lifford (function($) { $.fn.pluginName = function(method) { var defaults = { foo: 'bar' } var settings = {} var methods = { init : function(options) { settings = $.extend({}, defaults, options) return this.each(function() { var $element = $(this), element = this; // code goes here }); }, foo_public_method: function() { // code goes here } } var helpers = { foo_private_method: function() { // code goes here } } if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method) { return methods.init.apply(this, arguments); } else { $.error( 'Method "' + method + '" does not exist in pluginName plugin!'); } } })(jQuery);