jQueryのプラグイン作成用のひな形と関数。
!(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));
!(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));