Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
Last active August 29, 2015 14:05
Show Gist options
  • Save RyoSugimoto/16cfc40b79ee428a79c7 to your computer and use it in GitHub Desktop.
Save RyoSugimoto/16cfc40b79ee428a79c7 to your computer and use it in GitHub Desktop.
jQueryのプラグイン作成用のひな形と関数。
!(function ($, window, document, undefined) {
var pluginName = '';
var defaults = {
name: 'value'
};
function Plugin (elment, options) {
this.elment = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
},
myMethod: function () {
}
});
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, pluginName)) {
$.data(this, pluginName, new Plugin(this, options));
}
});
};
}(jQuery, window, document));
!(function ($, window, document, undefined) {
$.createPlugin = function (pluginName, properties, init, methods) {
function Plugin(element, options) {
this.element = element;
this.options = $.extend({}, properties, options);
this._default = properties;
this.name = pluginName;
this.init();
}
Plugin.prototype = methods;
Plugin.prototype.init = init;
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, pluginName)) {
$.data(this, pluginName, new Plugin(this, options));
}
});
};
};
}(jQuery, window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment