Skip to content

Instantly share code, notes, and snippets.

@ifahrentholz
Last active December 16, 2015 05:19
Show Gist options
  • Save ifahrentholz/5384068 to your computer and use it in GitHub Desktop.
Save ifahrentholz/5384068 to your computer and use it in GitHub Desktop.
A boilerplate for jumpstarting jQuery plugins development
/**
* *******************************
* XOLOTL jQuery-lightbox Plugin *
* *******************************
* @author Ingo Fahrentholz *
* @since Version 0.1.0 *
* *******************************
*/
!function(exports, $, undefined) {
var pluginName = "xolotl";
var Plugin = function(options) {
/*-------- PLUGIN VARS ------------------------------------------------------------*/
var debug = true,
priv = {}, // private API
Plugin = {}, // public API
defaults = {}; // Plugin defaults
/*-------- PRIVATE METHODS --------------------------------------------------------*/
priv.method1 = function() {
console.log('Private method 1 called...');
};
/*-------- PUBLIC METHODS ----------------------------------------------------------*/
if(debug) {
Plugin.options = priv.options;
}
/**
* Options called in public methods must access through the priv obj
*/
Plugin.method1 = function() {
console.log('Public method 1 called...');
};
/**
* Plugin initialization
* @param {Object} options user settings on init
* @return {Object} expose the Plugin object
*/
Plugin.init = function(options) {
//console.log('new plugin initialization...');
$.extend(priv.options, defaults, options);
priv.method1();
return Plugin;
};
/*
* Return the Public API (Plugin) we want to expose
*/
return Plugin.init();
};
exports.Plugin = Plugin;
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if ( !$.data(this, "dnb_" + pluginName )) {
$.data( this, "dnb_" + pluginName, new Plugin( this, options ));
}
});
};
}(this, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment