Skip to content

Instantly share code, notes, and snippets.

@denis-shvets
Last active August 29, 2015 14:21
Show Gist options
  • Save denis-shvets/0f068dfbe3ece59ff9a0 to your computer and use it in GitHub Desktop.
Save denis-shvets/0f068dfbe3ece59ff9a0 to your computer and use it in GitHub Desktop.
JS: jQuery plugin
;(function($, document, window, undefined) {
'use strict';
var pluginName = 'pluginname';
var instance = 0;
var PluginName = function(el, options, instance) {
this.instance = instance;
this.options = $.extend({}, options);
this.cache = {
el: el
};
this.init();
};
PluginName.prototype = {
init: function() {}
};
$.fn[pluginName] = function(options) {
return this.each(function() {
if (!$.data(this, pluginName)) {
$.data(this, pluginName, new PluginName(this, options, instance++));
}
});
};
})(jQuery, document, window);
// $(selector).pluginname();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment