Skip to content

Instantly share code, notes, and snippets.

@Nedudi
Created April 8, 2014 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nedudi/10110672 to your computer and use it in GitHub Desktop.
Save Nedudi/10110672 to your computer and use it in GitHub Desktop.
(function($) {
var methods = {
init: function(options) {
return this.each(function() {
var defaults = {
param1:false,
param2:100,
onChange:function(){
},
onBlur:function(){
}
};
var that = {};
this.item = that;
var $that = $(this);
that.options = jQuery.extend(defaults,options);
that.do1 = function(){
};
that.do2 = function(opts){
};
return this;
});
},
do1: function(opts){
this.each(function() {
if(this.item) this.item.do1();
});
return this;
},
do2: function(){
this.each(function() {
if(this.item) this.item.do2();
});
return this;
}
};
$.fn.myPluginName = function(method) {
if (methods[method]) {
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 ' + method + ' does not exist on $.myPluginName');
}
return this;
};
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment