Skip to content

Instantly share code, notes, and snippets.

@ornj
Created July 2, 2012 14:01
Show Gist options
  • Save ornj/3033395 to your computer and use it in GitHub Desktop.
Save ornj/3033395 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
(function($) {
var methods = {
init: function(options) {
return this; // Always return this to maintain ability to chain functions together
},
update: function(options) {
return this;
},
destroy: function() {
return this; // I guess
}
};
$.fn.MY_PLUGIN_NAME = function(method_options) {
if (methods[method_options]) {
return methods[method_options].apply(this, Array.prototype.slice.call(arguments, 1));
}
else if (typeof method_options === 'object' || !method_options) {
return methods.init.apply(this, arguments);
}
else {
$.error('Method ' + method + 'does not exist. What are you doing?');
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment