Skip to content

Instantly share code, notes, and snippets.

@tonycaputome
Created April 7, 2012 12:17
Show Gist options
  • Save tonycaputome/2328314 to your computer and use it in GitHub Desktop.
Save tonycaputome/2328314 to your computer and use it in GitHub Desktop.
Javascript : jQuery plugin boilerplate
// remember to replace all occurences of:
// boilerplate
// with your plugin namespace
(function ($) {
var settings = {
'setting': 'value'
};
var methods = {
init: function (options) {
if (options) {
$.extend(settings, options);
}
return this;
},
reposition: function () { },
show: function () { },
hide: function () { }
};
$.fn.boilerplate = 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 on jQuery.boilerplate');
}
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment