Skip to content

Instantly share code, notes, and snippets.

@freezvd
Created October 18, 2017 10:19
Show Gist options
  • Save freezvd/a87a22a05bb41e9697f2c4f767f11803 to your computer and use it in GitHub Desktop.
Save freezvd/a87a22a05bb41e9697f2c4f767f11803 to your computer and use it in GitHub Desktop.
JavaScript: jQuery plugin boilerplate by Stefan Gabos #snippet
// jQuery Plugin Boilerplate
// A boilerplate for jumpstarting jQuery plugins development
// version 1.1, May 14th, 2011
// by Stefan Gabos
(function($) {
$.pluginName = function(element, options) {
var plugin = this;
plugin.settings = {}
var $element = $(element),
element = element;
var defaults = {
foo: 'bar',
onFoo: function() {}
}
plugin.init = function() {
plugin.settings = $.extend({}, defaults, options);
// code goes here
}
plugin.foo_public_method = function() {
// code goes here
}
var foo_private_method = function() {
// code goes here
}
plugin.init();
}
$.fn.pluginName = function(options) {
return this.each(function() {
if (undefined == $(this).data('pluginName')) {
var plugin = new $.pluginName(this, options);
$(this).data('pluginName', plugin);
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment