Created
April 15, 2013 14:39
-
-
Save robflaherty/5388589 to your computer and use it in GitHub Desktop.
data attribute initializing boilerplate
This file contains hidden or 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
| (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