Created
February 6, 2014 22:31
-
-
Save ChrisLTD/8853841 to your computer and use it in GitHub Desktop.
Jquery Plugin template based on http://css-tricks.com/snippets/jquery/jquery-plugin-template/
This file contains hidden or 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
// Usage: | |
// $("#element").yourPluginName("20px"); | |
// | |
// Reference functions | |
// $(‘#element’).data(‘pluginName’).functionName(); | |
(function($){ | |
$.yourPluginName = function(el, options){ | |
// To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions. | |
var base = this; | |
// Access to jQuery and DOM versions of element | |
base.$el = $(el); | |
base.el = el; | |
// Add a reverse reference to the DOM object | |
base.$el.data("yourPluginName", base); | |
base.init = function(){ | |
base.options = $.extend({},$.yourPluginName.defaultOptions, options); | |
// Put your initialization code here | |
}; | |
// Sample Function, Uncomment to use | |
// base.functionName = function(paramaters){ | |
// | |
// }; | |
// Run initializer | |
base.init(); | |
}; | |
$.yourPluginName.defaultOptions = { | |
radius: "20px" | |
}; | |
$.fn.yourPluginName = function(options){ | |
return this.each(function(){ | |
(new $.yourPluginName(this, options)); | |
// HAVE YOUR PLUGIN DO STUFF HERE | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment