Skip to content

Instantly share code, notes, and snippets.

@appkr
Created February 5, 2015 00:47
Show Gist options
  • Save appkr/4f7538622ab54659b879 to your computer and use it in GitHub Desktop.
Save appkr/4f7538622ab54659b879 to your computer and use it in GitHub Desktop.
jQuery Plugin Template
// 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