Hi I am trying to build my first jquery plugin, it basically creates a button from div with mouse over/click states etc, the following code works for the basic button, however I want to create a highlight method to assign a class to replace the 'normal' class. The method gets called however I cant seem to read the options? Also if I assign the class name (addClass) by hardcoding it, I seem to lose the mouse event for the over and click states?
The code:
(function(jQuery) {
jQuery.fn.divbutton = function(options)
{
// default settings
var options = jQuery.extend(
{
width: '75px', // button width
height: '25px', // button height
normal_class: 'brighterbutton', // normal state class
highlight_class: 'brighterbutton-highlight', // normal state class
mouseover_class: 'brighterbutton-mouseover', // mouseover class
mousedown_class: 'brighterbutton-mousedown', // mousedown class
highlighted: false
},
options);
this.each(function()
{
jQuery(this).addClass(options.normal_class);
jQuery(this).width(options.width);
jQuery(this).height(options.height);
jQuery(this).mouseover(function() {
jQuery(this).addClass(options.mouseover_class);
});
jQuery(this).mouseout(function() {
jQuery(this).removeClass(options.mouseover_class);
jQuery(this).removeClass(options.mousedown_class);
});
jQuery(this).mousedown(function() {
jQuery(this).addClass(options.mousedown_class);
});
jQuery(this).mouseup(function() {
jQuery(this).removeClass(options.mousedown_class);
});
});
// public methods
this.doHighlight = function()
{
alert("this doesnt get called");
return this;
};
return this;
};
jQuery.fn.highlight = function()
{
alert("this gets called");
return this.each(function()
{
//this.removeClass(this.options.normal_class);
//this.addClass(this.options.highlight_class);
});
};
})(jQuery);