Skip to content

Instantly share code, notes, and snippets.

@aispin
Last active December 27, 2015 17:59
Show Gist options
  • Save aispin/7365971 to your computer and use it in GitHub Desktop.
Save aispin/7365971 to your computer and use it in GitHub Desktop.
A jquery plugin template
/**
* plugin short description
* @author levin
* @version 1.0.0
* @module plugin name
* @class full plugin name like jquery.xxx
* @static
*/
(function($){
//延迟加载模块
$.fn.X = function (opts) {
// Set the options.
var optsType = typeof (opts),
opts1 = optsType !== 'string' ? $.extend(true, {}, $.fn.X.defaults, opts || {}) : $.fn.X.defaults,
args = arguments;
return this.each(function () {
var $me = $(this),
instance = $me.data("X");
if(!instance){
$me.data("X", new model($me,opts1));
return;
};
if (instance[opts]) {
instance[opts].apply(instance, Array.prototype.slice.call(args, 1));
} else if (typeof (opts) === 'object' || !opts) {
instance._update.apply(instance, args);
} else {
console.log('Method ' + opts + ' does not exist in jQuery.fn.X');
}
});
};
$.fn.X.defaults = {
showSpeed:200,
showDelay:300,
hideDelay:0
};
var $win = $(window);
var model = function($item,opts){
this.$dom = $item;
this.opts = opts;
this._init();
};
model.prototype = {
_init:function(){
},
foo:function(){
},
bar:function(){
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment