Skip to content

Instantly share code, notes, and snippets.

@dniswhite
Created April 28, 2014 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dniswhite/11375377 to your computer and use it in GitHub Desktop.
Save dniswhite/11375377 to your computer and use it in GitHub Desktop.
starting point for a jQuery plugin
(function($) {
// using $.fn.extend allows us to expand on jquery
$.fn.extend({pluginName:function(options){
// save a link to your instance
var plugin = this;
var defaultOptions = {
// add what you know are default values for your options
};
// connect your default values to what the user has added
// I connect everything into the current instance so that it
// can be referenced later if needed.
if (options)
plugin.Settings = $.extend(defaultOptions, options);
else
plugin.Settings = defaultOptions;
// private functions
function functionName(values){
// code here
}
// public functions
plugin.functionName = function(values){
// code here
}
// implement get/set for your object properties
var variableName;
plugin.variableName = function(v){
// validate data sent in
if(undefined !== v){
variableName = v;
}
return variableName;
}
return this.each(function(){
// initialization code goes here
});
}});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment