Skip to content

Instantly share code, notes, and snippets.

@mi3tek-amb
Last active December 23, 2015 10:49
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 mi3tek-amb/6623892 to your computer and use it in GitHub Desktop.
Save mi3tek-amb/6623892 to your computer and use it in GitHub Desktop.
(function($){
$.fn.myPlugin = function myPlugin(options){
var that = this;
that.options = $.extend(
{
optionA:'A',
optionB:'B'
}
,options
);
myPlugin.log(that);
myPlugin.dir(that);
};
$.extend(
$.fn.myPlugin,
{
log : function(element){
console.log(element);
},
dir : function(element){
console.dir(element);
}
}
);
})(jQuery);
(function($){
$.fn.myPlugin = function(options){
return new $.fn.myPlugin.init(options)
};
$.fn.myPlugin.init = function( options ){
$.extend(
this.defaultOptions
, options
);
this.log();
this.dir();
return this;
};
$.fn.myPlugin.init.prototype = {
defaultOptions : {
optionA:'A',
optionB:'B'
},
log : function(){
console.log(this.optionA);
},
dir : function(){
console.dir(this.optionB);
}
};
})(jQuery);
$.fn.pluginName = function(callback){
return this.each(function(){
var
self = $.extend(new jQuery.fn.init(this),$.fn.pluginName.init);
callback.call(self);
});
};
$.fn.pluginName.init = (function init(){
return {
log : function(){
console.dir(this);
}
}
})();
$('#div').pluginName(function(){
this.log();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment