Skip to content

Instantly share code, notes, and snippets.

@robflaherty
Created April 15, 2013 14:39
Show Gist options
  • Select an option

  • Save robflaherty/5388589 to your computer and use it in GitHub Desktop.

Select an option

Save robflaherty/5388589 to your computer and use it in GitHub Desktop.
data attribute initializing boilerplate
(function($, window, undefined) {
"use strict";
var Plugin = function(element, options) {
this.element = element;
this.$element = $(element);
this.init();
};
Plugin.prototype.init = function () {
console.log(this)
};
$.fn.plugin = function(options) {
return this.each(function() {
var settings = $.extend({}, $.fn.plugin.defaults, options);
if (!$.data(this, 'plugin')) {
$.data(this, 'plugin', new Plugin(this, settings));
}
});
};
$.fn.plugin.defaults = {
option1: true,
option2: false
};
$.fn.plugin.Constructor = Plugin;
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment