Skip to content

Instantly share code, notes, and snippets.

@siggysamson
Last active January 26, 2016 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siggysamson/e1108b4bd8b8e93c0494 to your computer and use it in GitHub Desktop.
Save siggysamson/e1108b4bd8b8e93c0494 to your computer and use it in GitHub Desktop.
(function($) {
"use strict";
// Create the defaults once
var pluginName = "defaultPluginName";
var defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin (element, options) {
this.$element = $(element);
this.settings = $.extend( {}, defaults, options );
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
// initial plugin call
},
yourOtherFunction: function () {
// some logic
}
});
$.fn[pluginName] = function (options) {
return this.each(function() {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment