Last active
August 29, 2015 13:57
-
-
Save burt202/9496435 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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