Skip to content

Instantly share code, notes, and snippets.

@Mr2P
Created March 1, 2012 00:53
Show Gist options
  • Select an option

  • Save Mr2P/1946308 to your computer and use it in GitHub Desktop.

Select an option

Save Mr2P/1946308 to your computer and use it in GitHub Desktop.
jQuery plugin boilerplate based on Jeffrey Way's work
// polyfill for unsupported browsers
if( Object.create !== 'function'){
Object.create = function (o){
function F(){};
F.prototype = o;
return new F();
}
}
(function($, window, document, undefined){
var PluginObj = {
init: function(options, elem){
var self = this;
self.elem = elem;
self.$elem = $(elem);
self.options = $.extend({}, $.fn.pluginName.options, options);
// TODO: call main excute method
},
// TODO: create internal method for PluginObj
};
$.fn.pluginName = function (options){
return this.each(function(){
$.data(this, 'pluginName', Object.create(PluginObj).init(options, this));
});
};
$.fn.pluginName.options = {};
})(jQuery, window, document);
@JeffreyWay
Copy link

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment