Created
February 5, 2015 00:47
-
-
Save appkr/4f7538622ab54659b879 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
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
// Polyfill for Old Browser | |
if (typeof Object.create !== "function") { | |
Object.create = function(obj) { | |
function F() {}; | |
F.prototype = obj; | |
return new F(); | |
} | |
} | |
// Plugin | |
(function($, window, document, undefined) { | |
var ClassName = { | |
init: function(options, elem) { | |
var self = this; | |
self.elem = elem; | |
self.$elem = $(elem); | |
self.options = self.options = $.extend({}, $.fn.pluginName.options, options); | |
self.main(); | |
}, | |
main: function() {} | |
}; | |
$.fn.pluginName = function(options) { | |
return this.each(function() { | |
var pluginObject = Object.create(ClassName); | |
pluginObject.init(options, this); | |
$.data(this, 'pluginName', pluginObject); | |
}); | |
}; | |
$.fn.pluginName.options = {); | |
})(jQuery, window, document); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment