Skip to content

Instantly share code, notes, and snippets.

@burt202
Last active August 29, 2015 13:57
Show Gist options
  • Save burt202/9496435 to your computer and use it in GitHub Desktop.
Save burt202/9496435 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
<html>
<head>
<title>jQuery Plugin BoilerPlate</title>
</head>
<body>
<div id="element"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="jquery-plugin-boilerplate.js"></script>
<script>
$('#element').boilerPlate();
console.log($('#element').data('boilerPlate'));
</script>
</body>
</html>
$.fn.boilerPlate = function (options) {
var defaults = {};
return this.each(function () {
if (!$.data(this, 'boilerPlate')) {
$.data(this, 'boilerPlate', new BoilerPlate(this, $.extend(defaults, options)));
}
});
};
function BoilerPlate (element, options) {
this.element = element;
this.options = options;
this.init();
}
BoilerPlate.prototype = {
init: function () {
console.log(this.element, this.options);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment