Skip to content

Instantly share code, notes, and snippets.

@msenkpiel
Created September 18, 2014 07:01
Show Gist options
  • Save msenkpiel/69189be33e3666276b1c to your computer and use it in GitHub Desktop.
Save msenkpiel/69189be33e3666276b1c to your computer and use it in GitHub Desktop.
jQuery Plugin Pattern
;
(function ($, window, document, undefined) {
'use strict';
var pluginName = 'plugin',
defaults = {
propertyName: "value"
};
function Plugin(element, options) {
var plugin = this;
plugin.element = element;
plugin.settings = $.extend({}, defaults, options);
plugin._defaults = defaults;
plugin._name = pluginName;
var init = function () {
console.log('init plugin - element:', plugin.element);
};
var privateMethod = function () {
};
plugin.publicMethod = function () {
};
init();
}
$.fn[pluginName] = function (options) {
var p = new Plugin(this, options);
$(this).data(pluginName, p);
return p;
};
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment