jQuery插件开发标准框架
Liber 2012-10-18 10:05 (updated at 2014-10-02 09:05)
From jQuery Team
(function ($) {
var methods = {
init : function(options) {
var defaults = {};
var settings = $.extend(defaults, options);
},
addEvent : function() {
}
}
$.fn.pluginname = function(method) {
if(methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error( '插件中没有 '+method+' 方法' );
}
};
})(jQuery);
From Bootstrap Team
+function ($) {
'use strict';
var Awesome = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, Waterfall.DEFAULTS, options)
this.initialize()
}
Awesome.VERSION = '0.0.1'
Awesome.DEFAULTS = {
}
Awesome.prototype.initialize = function () {
}
function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('namespace.awesome')
var options = typeof option == 'object' && option
if(!data) $this.data('namespace.awesome', (data = new Awesome(this, options)))
})
}
var old = $.fn.awesome
$.fn.awesome = Plugin
$.fn.awesome.Constructor = Awesome
$.fn.awesome.noConflict = function () {
$.fn.awesome = old
return this
}
}(jQuery);