On gists
jQuery plugin skeleton
Plugin patterns
jQuery-plugins
skeleton.js
Raw
#
/*!
* AW {{PROJECTNAME}}
*
*
* @author {{firstname lastname}} <{{email}}>
* @version 1.0.0
*
*/
/*
{{PLUGIN}} => realname of project, eg: awBestPlugin
*/
;(function() {
'use strict';
function {{PLUGIN}}(element, options) {
this.self = $(element);
this.settings = $.extend(true, {}, $.fn.{{PLUGIN}}.defaults, options);
}
{{PLUGIN}}.prototype = {
/* PRIVATE METHODS */
_create: function() {
}
/* PUBLIC METHODS */
};
(function ($) {
$.fn.{{PLUGIN}} = function(options) {
var
args = Array.prototype.slice.call(arguments, 1),
method = {{PLUGIN}}.prototype[options];
return this.each(function() {
var self = $(this);
var instance = self.data('{{PLUGIN}}');
if (!instance) {
instance = new {{PLUGIN}}(this, options);
instance._create();
self.data('{{PLUGIN}}', instance);
}
if (method && options.substring(0, 1) == '_')
$.error('Cannot use private method "' + options + '" outside of object');
if (method) {
method.apply(instance, args);
} else if (options && typeof options !== 'object') {
$.error('Method "' + options + '" not found.');
}
});
};
$.fn.{{PLUGIN}}.defaults = {
};
})(jQuery);
})();