Last active
August 29, 2015 14:05
-
-
Save RyoSugimoto/16cfc40b79ee428a79c7 to your computer and use it in GitHub Desktop.
jQueryのプラグイン作成用のひな形と関数。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!(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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!(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