Created
October 28, 2012 15:47
-
-
Save zhuochun/3968950 to your computer and use it in GitHub Desktop.
jQuery Plugin Boilerplate
This file contains hidden or 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
/* ======================================== | |
* <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