(function($){ $.fn.changeColor = function(options) { function onClick(event){ //cialo metody prywatnej $this = $(this); data = $this.data('changeColor'); data.first = !data.first; $this.css("backgroundColor", data.first ? data.colorSecond : data.colorFirst); return true; } //metody publiczne var methods = { swapColors: function(){ $this=$(this); data = $this.data('changeColor'); tmp = data.colorSecond; data.colorSecond = data.colorFirst; data.colorFirst = tmp; }, destroy: function(){ //destruktor $this = $(this); $this.unbind("click"); $this.css("background-color",""); $this.removeData("changeColor"); } }; return this.each(function(){ if(methods[options]) { return methods[options].apply(this,arguments); } else if (typeof options === 'object' || ! options){ //parametry pluginu var settings = $.extend({ colorFirst:'Red', colorSecond:'Green' },options); $this = $(this); data = $this.data('changeColor'); if (!data) { data = $this.data('changeColor',settings); $this.bind("click",onClick); } $this.css("background-color",settings.colorFirst); data.first=true; return; } else{ //bład $.error('changeColor: no method: '+ options); } }); } })(jQuery);