Skip to content

Instantly share code, notes, and snippets.

@musukvl
Last active March 31, 2017 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musukvl/c8b351f7854932c8f61c13c910845d23 to your computer and use it in GitHub Desktop.
Save musukvl/c8b351f7854932c8f61c13c910845d23 to your computer and use it in GitHub Desktop.
JQuery Plugin Template
(function ($) {
$.pluginName = function (el, options) {
// To avoid scope issues, use 'self' instead of 'this'
// to reference this class from internal events and functions.
var self = this;
// Access to jQuery and DOM versions of element
self.$el = $(el);
self.el = el;
self.elId = self.$el.attr('id');
// Add a reverse reference to the DOM object
self.$el.data("pluginName", self);
self.init = function () {
self.options = $.extend({}, $.pluginName.defaultOptions, options);
self.$el.click(onStarClick);
//subscribe to element events
};
// Run initializer
self.init();
};
$.pluginName.defaultOptions = {
cookieKey: 'pluginName'
};
$.fn.pluginName = function (options) {
return this.each(function () {
(new $.pluginName(this, options));
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment