Created
June 6, 2012 13:05
-
-
Save spilliams/2881728 to your computer and use it in GitHub Desktop.
Boilerplate jQuery Plugin. Copypasta.
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
// replace instances of "myPlugin" with your plugin name | |
(function($){ | |
var methods = { | |
init : function( options ) { | |
var defaults = { | |
}; | |
var options = $.extend(defaults,options) | |
return this.each(function() { | |
obj = $(this); | |
// do stuff to obj | |
}); // this.each | |
}, // init | |
// more methods | |
} | |
$.fn.myPlugin = 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.myPlugin' ); | |
} | |
}; // myPlugin function | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment