Skip to content

Instantly share code, notes, and snippets.

@jugglebird
Created January 10, 2014 15:28
Show Gist options
  • Select an option

  • Save jugglebird/8356359 to your computer and use it in GitHub Desktop.

Select an option

Save jugglebird/8356359 to your computer and use it in GitHub Desktop.
A good, minimal template for creating a jQuery plugin.
;(function($) {
// multiple plugins can go here
(function(pluginName) {
var defaults = {
color: 'black',
testFor: function(div) {
return true;
}
};
$.fn[pluginName] = function(options) {
options = $.extend(true, {}, defaults, options);
return this.each(function() {
var elem = this,
$elem = $(elem);
// heres the guts of the plugin
if (options.testFor(elem)) {
$elem.css({
borderWidth: 1,
borderStyle: 'solid',
borderColor: options.color
});
}
});
};
$.fn[pluginName].defaults = defaults;
})('borderize');
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment