Last active
March 3, 2016 23:10
-
-
Save solomonrothman/9c094485d8e96919b034 to your computer and use it in GitHub Desktop.
jQuery Plugin Simple Example
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
//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