Last active
December 23, 2015 10:49
-
-
Save mi3tek-amb/6623892 to your computer and use it in GitHub Desktop.
This file contains 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($){ | |
$.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); |
This file contains 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($){ | |
$.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); |
This file contains 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
$.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