Skip to content

Instantly share code, notes, and snippets.

@hiromitz
Created May 13, 2011 02:50
Show Gist options
  • Save hiromitz/969884 to your computer and use it in GitHub Desktop.
Save hiromitz/969884 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
;!function($) {
var pluginName = 'myPlugin';
$[pluginName] = function(el, op) {
this.options = op = $.extend({}, {
// default options here
}, op);
this.el = el;
};
$[pluginName].prototype = {
methodName: function() { return this; }
};
$.fn[pluginName] = function( method, options ) {
if(typeof method === "object") {
options = method;
method = null;
}
var res;
this.each(function() {
var inst = $.data(this, pluginName) || $.data(this, pluginName, new $[pluginName](this, options));
if(method) {
res = inst[method](options);
}
});
return res || this;
};
}(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment