Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Created July 16, 2012 15:55
Show Gist options
  • Select an option

  • Save rogeruiz/3123483 to your computer and use it in GitHub Desktop.

Select an option

Save rogeruiz/3123483 to your computer and use it in GitHub Desktop.
jQuery Boilerplate
/*!
* jQuery namespaced 'Starter' plugin boilerplate
* Author: @dougneiner
* Further changes: @addyosmani
* Licensed under the MIT license
*/
;(function($) {
// Create the Caesars namespace if it doesn't exist
if (!$.Caesars){ $.Caesars = {}; }
/**
* @name $.Caesars.<#Your Plugin's Name#>
* @description <#This is a boilerplate plugin with an init method#>
* @param {String} el The element being passed into the plugin
* @param {Object} options The options object to override plugin options
* @author <#Your Email Here#>
*/
$.Caesars.<#pluginName#> = function(el, options){
// use a reference for the plugin's scope
var base = this;
// make a reference for jQuery element & DOM element
base.$el = $(el);
base.el = el;
// private methods
base.init = function(){
// copy and override the passed defaultOptions with the passed in options
base.options = $.extend({}, $.Caesars.<#pluginName#>.defaultOptions, options);
base.options.$el = base.$el;
base.options.el = base.el;
// Put your initialization code here, dude.
return base.options.onInit !== undefined ? base.options.onInit() : true;
};
// Run init
base.init();
}
$.Caesars.<#pluginName#>.defaultOptions = {
onInit: undefined
}
$.fn.Caesars_<#pluginName#> = function(options){
return this.each(function(){
(new $.Caesars.<#pluginName#>(this, options));
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment