Skip to content

Instantly share code, notes, and snippets.

@neerajsingh0101
Created July 24, 2009 15:43
Show Gist options
  • Save neerajsingh0101/154375 to your computer and use it in GitHub Desktop.
Save neerajsingh0101/154375 to your computer and use it in GitHub Desktop.
a jQuery plugin base to create new jQuery plugins
// app.js
$(document).ready(function(){
$('#calendar').calendarize({
param2: 'custom param2'
});
});
//calendarize.js
(function($){
$.fn.calendarize = function(opt){
/* if there are no elements then just return */
if (!this.length) return this;
var defaults = {
param1: 'param1',
param2: 'param2'
};
var options = $.extend(defaults,opt);
alert('param1 has value ' + options.param1);
alert('param2 has value ' + options.param2);
return this.each(function(){
// real business logic will go in here
// options is directly accessible. No need to pass it around
var $this = $(this);
function test1(){
alert('this is test1');
alert(options.param1);
}
function test2(){
alert('this is test2');
}
test1();
test2();
}); // end of return this.each(function())
}; // end of plugin
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment