Skip to content

Instantly share code, notes, and snippets.

@johnpolacek
Created August 21, 2012 15:06
Show Gist options
  • Save johnpolacek/3416310 to your computer and use it in GitHub Desktop.
Save johnpolacek/3416310 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
/*
PluginName - Plug In Description
by John Polacek (@johnpolacek)
Dual licensed under MIT and GPL.
Dependencies: jQuery
*/
;(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);
/* In the HTML demo page:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.7.2.min.js"><\/script>')</script>
<script>
$(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;
</script>
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment