Skip to content

Instantly share code, notes, and snippets.

@zhuochun
Created October 28, 2012 15:47
Show Gist options
  • Save zhuochun/3968950 to your computer and use it in GitHub Desktop.
Save zhuochun/3968950 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
/* ========================================
* <Project> - <Description>
*
* Author:
* Last Edit:
* ========================================
* <License>
* ======================================== */
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;(function($) {
"use strict";
/*jshint browser:true, jquery:true, laxcomma:true, maxerr:50*/
/* PLUGIN CLASS DEFINITION
* ======================================== */
// TODO: change to your project, used as prefix
var _project = "<projectName>_"
// TODO: change to your plugin name
, _pluginName = "<pluginName>"
// TODO: define default options
// default options for plugin
, defaults = {
//<propertyName : "value">
}
// Plugin constructor
, Plugin = function(element, options) {
this.elem = element;
this.options = $.extend({}, defaults, options) ;
this.init();
};
Plugin.prototype.init = function() {
// TODO: define initialization logic
this.$elem = $(this.elem);
};
/* PLUGIN DEFINITION
* ======================================== */
// TODO: change $.fn.pluginName to your plugin name
$.fn.pluginName = function(options) {
return this.each(function () {
if (!$.data(this, _project + _pluginName)) {
$.data(this, _project + _pluginName, new Plugin(this, options));
}
});
};
}(jQuery));
// reference: http://jqueryboilerplate.com/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment