Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Forked from oscarotero/jquery.plugin.js
Last active March 7, 2019 00:56
Show Gist options
  • Save eusonlito/6467106 to your computer and use it in GitHub Desktop.
Save eusonlito/6467106 to your computer and use it in GitHub Desktop.
;(function ($, window, document, undefined) {
var pluginName = 'name', defaults = {};
function Plugin (element, options) {
this.element = element;
this.settings = $.extend({}, defaults, options);
this.init();
}
Plugin.prototype = {
init: function () {
}
};
$.fn[pluginName] = function (options) {
if ((options === undefined) || (typeof options === 'object')) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
}
});
}
if ((typeof options === 'string') && (options[0] !== '_') && (options !== 'init')) {
var returns, args = arguments;
this.each(function () {
var instance = $.data(this, 'plugin_' + pluginName);
if ((instance instanceof Plugin) && (typeof instance[options] === 'function')) {
returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
}
if (options === 'destroy') {
$.data(this, 'plugin_' + pluginName, null);
}
});
return returns !== undefined ? returns : this;
}
};
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment