Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Created May 22, 2012 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rogeruiz/2769723 to your computer and use it in GitHub Desktop.
Save rogeruiz/2769723 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
(function($){
// private methods
var _<#privateMethodName#> = function(){};
// public methods
var methods = {
init: function(options){
if (this.hasInitialized){ return; }
this.settings = $.extend({
<#property#>: <#value#>,
<#property#>: <#value#>,
<#property#>: <#value#>
}, options);
this.hasInitialized = true;
},
<#publicMethodName#>: function(cb){},
<#publicMethodName#>: function(cb){}
}
$.fn.<#PluginNameSpace#> = function(method){
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 jQuery.<#PluginNameSpace#>');
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment