Created
July 24, 2009 15:43
-
-
Save neerajsingh0101/154375 to your computer and use it in GitHub Desktop.
a jQuery plugin base to create new jQuery plugins
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
// 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