Skip to content

Instantly share code, notes, and snippets.

@creativeaura
Created April 30, 2012 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creativeaura/2556401 to your computer and use it in GitHub Desktop.
Save creativeaura/2556401 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
// jQuery Plugin Boilerplate
// A boilerplate for jumpstarting jQuery plugins development
;(function($) {
$.pluginName = function(el, options) {
var defaults = {
propertyName: 'value',
onSomeEvent: function() {}
}
var plugin = this;
plugin.settings = {}
var init = function() {
plugin.settings = $.extend({}, defaults, options);
plugin.el = el;
// code goes here
}
plugin.foo_public_method = function() {
// code goes here
}
var foo_private_method = function() {
// code goes here
}
init();
}
})(jQuery);
/*
* Usage for the plugin
*/
$(document).ready(function() {
// create a new instance of the plugin
var myplugin = new $.pluginName($('#element'));
// call a public method
myplugin.foo_public_method();
// get the value of a public property
myplugin.settings.property;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment