Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created October 20, 2011 23:15
Show Gist options
  • Save fideloper/1302685 to your computer and use it in GitHub Desktop.
Save fideloper/1302685 to your computer and use it in GitHub Desktop.
jQuery plugin template - legit
(function($){
var environment = {};
var methods = {
init:function(options) {
var options = $.extend({}, options);
return this.each(function() {
});
}
};
$.fn.nameOfTemplate = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.nameOfTemplate' );
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment