Skip to content

Instantly share code, notes, and snippets.

@solomonrothman
Last active March 3, 2016 23:10
Show Gist options
  • Save solomonrothman/9c094485d8e96919b034 to your computer and use it in GitHub Desktop.
Save solomonrothman/9c094485d8e96919b034 to your computer and use it in GitHub Desktop.
jQuery Plugin Simple Example
//Sample code for elements in a simple chainable jQuery plugin. This code dosn't do anything, just has the "moving" parts
(function ($) {
$.fn.testcal = function (options) {
var opts = $.extend({}, $.fn.testcal.defaults, options); // Get options and extend defaults
return this.each(function () {
var elem = $(this);
console.log(elem); // do something on each element, this just logs it for now
}
);
};
$.fn.testcal.helper = function (more_options) {
privatePrint('This is a private method');
};
$.fn.testcal.defaults = {
sampleOption: "sampleValue", // set defaults outside of main function
};
function privatePrint(more_options) {
console.log('Anything in here is private from global scope.' + more_options);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment