Cytat(trueblue @ 10.05.2014, 16:49:05 )

return this.each(function(){
Dziękować - potforna literówka.
Tyle, że teraz wyskakuje mi błąd - nie wiem czemu.
rror: changeColor: no method: [object Object] i wskazuje mi na linię 247 jquery.js
************
A zabawne, że oryginał działa;-)) Pewnie znowu jakaś literówka.
**********
Mam wrażenie, że nie jasno opisałem mój problem. Może dlatego, że sam nie bardzo wiem na czym on polega.
Porównałem wszystkie pliki i wrzysko jest tak samo. Tyle, że oryginał działa a moje wersje nie. I tyle. Będę wdzięczny za jakieś sugestie.
Okej, dla jasności wrzucam wszystkie kody. Tak będzie chyba najłatwiej znaleźć błąd.
Kod html:
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="icon" type="image/png" href="favicon.png"/> <link rel="stylesheet" href="style.css"> <script type="text/javascript"> $(document).ready(function(){
$('div').changeColor({colorFirst:'Blue',colorSecond:'Black'});
});
Kod js:
(function($){
$.fn.changeColor = function(options)
{
//cialo metody prywatnej
function onClick(event){
$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("backgroundColor","");
$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);
Hura!! Znalazłem błąd. Chodziło o to, że jak jest if (typeof options === 'object'),to nie można pisać: ' object '. Musi być brak spacji. Wtedy działa. Mam nadzieję, że komuś się to spostrzeżenie przyda.
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);
}