(function($){
$.fn.extend({
swec_hello_world : function(user_options) {
return this.each(function() {
var defaults = {
'bgcolor' : '#cccccc',
'width' : '400px',
'on_load' : function() {
//callback function
return "";
}
};
//accept options from user
var options = $.extend(defaults, user_options);
//Creating a reference to the object $("#hello_world")
var obj = $(this);
//call init to setup the object
init();
function init()
{
obj.html("Hello World");
obj.css({
"background-color" : options.bgcolor,
"width" : options.width
});
//execute a user hook function
options.on_load();
}
});
}
});
})(jQuery);
To use this plugin, add the following to your html page.
<script>
$(document).ready(function(){
$("#hello_world").swec_hello_world({
"bgcolor" : "#ff0000",
"width" : "400px",
"on_load" : function() {
//this is defined in the plugin, will be called after object is created...
$("#hello_world").css("height", "200px");
}
});
});
</script>
<div id="hello_world"></div>