Re: [jQuery] animate problem

2006-10-10 Thread Klaus Hartl


David Duymelinck schrieb:
 i know somewhere in the list there is a solution but i can't find it at 
 the moment.
 
 I want to pass the animate hash as an option so i don't need to go into 
 the plugin to change the animation effects.
 
 $('#test').plugin({anihide: {opacity: 'hide'}, anishow: {opacity: 
 'show'}, anitime: 3000});
 
 $.fn.test = function(options){
 var anihide = options.anihide;
 var anishow = options.anishow;
 var anitime = options.anitime;
 $(img).siblings(img:visible).animate(anihide, 
 anitime).end().animate(anishow, anitime);
 }
 
 The last line is from the actual plugin, the other code is pseudo code. 
 But i think you can understand the point i'm trying to make.
 When i alert anihide the first time i get the opacity value but the 
 second time i get true as value.
 


I ran into the same problem with the tabs plugin. The original object is 
modified for the animation, so as a workaround I copy the object each 
time before passing it to animate:


$.fn.test = function(options){
 var anihide = $.extend({}, options.anihide); // copy object
 var anishow = $.extend({}, options.anishow);
 var anitime = options.anitime;
 $(img).siblings(img:visible).animate(anihide, 
anitime).end().animate(anishow, anitime);
;

Jörn has already filed a ticket for this:
http://jquery.com/dev/bugs/bug/237/

-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread David Duymelinck
Klaus Hartl schreef

 I ran into the same problem with the tabs plugin. The original object is 
 modified for the animation, so as a workaround I copy the object each 
 time before passing it to animate:


 $.fn.test = function(options){
  var anihide = $.extend({}, options.anihide); // copy object
  var anishow = $.extend({}, options.anishow);
  var anitime = options.anitime;
  $(img).siblings(img:visible).animate(anihide, 
 anitime).end().animate(anishow, anitime);
 ;

 Jörn has already filed a ticket for this:
 http://jquery.com/dev/bugs/bug/237/

 -- Klaus

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


   
i was also thinking about copying the object but in a more basic version :)

 var anihide = options.anihide;
 var anihide2 = anihide;
 $(img).siblings(img:visible).animate(anihide2, 
anitime).end().animate(anishow, anitime);
;

But that didn't work and i regret to say your workaround didn't work either. :( 
 

I downloaded the uncompressed jquery and according to firebug the error is 
situated in lines 91, 344, 979, 1350, 1359, 1370 and 1380. But that is after 
the anihide object is set to true so i don't know if it's useful information.

If i find another way to avoid this i will let you know.

-- 
David Duymelinck

[EMAIL PROTECTED]


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Jörn Zaefferer
Hi David!

 I want to pass the animate hash as an option so i don't need to go into 
 the plugin to change the animation effects.
 
 $('#test').plugin({anihide: {opacity: 'hide'}, anishow: {opacity: 
 'show'}, anitime: 3000});
 
 $.fn.test = function(options){
 var anihide = options.anihide;
 var anishow = options.anishow;
 var anitime = options.anitime;
 $(img).siblings(img:visible).animate(anihide, 
 anitime).end().animate(anishow, anitime);
 }
 
 The last line is from the actual plugin, the other code is pseudo code. 
 But i think you can understand the point i'm trying to make.
 When i alert anihide the first time i get the opacity value but the 
 second time i get true as value.

This is a known problem: http://jquery.com/dev/bugs/bug/237/

The workaround is to clone the hash before you pass it to animate, eg:
$().animate($.extend({}, hash), 5);

Klaus Hartl's tabs plugin has the same issue. If the above does not work, take 
a peek at his code: http://stilbuero.de/jquery/tabs/

-- Jörn
-- 
GMX DSL-Flatrate 0,- Euro* - Überall, wo DSL verfügbar ist!
NEU: Jetzt bis zu 16.000 kBit/s! http://www.gmx.net/de/go/dsl

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Klaus Hartl

 i was also thinking about copying the object but in a more basic version :)
 
  var anihide = options.anihide;
  var anihide2 = anihide;
  $(img).siblings(img:visible).animate(anihide2, 
 anitime).end().animate(anishow, anitime);
 ;
 
 But that didn't work and i regret to say your workaround didn't work either. 
 :(  
 
 I downloaded the uncompressed jquery and according to firebug the error is 
 situated in lines 91, 344, 979, 1350, 1359, 1370 and 1380. But that is after 
 the anihide object is set to true so i don't know if it's useful information.
 
 If i find another way to avoid this i will let you know.
 

Maybe you didn't copy it in the right place... see it has to be copied 
every time animate is called.

In the tabs plugin that looks something like:

jQuery.fn.tabs = function(options) {

 // copying here from options is not sufficient...

 return this.each(function() {
 jQuery('a').click(function() {
 // 1. copy objects
 // 2. call animate...
 });
 });

};

Would be great if this bug is fixed, because I could completely move 
that out from the click event making the whole thing perform better I 
guess...

-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Brandon Aaron
If I understand the issue correctly changing this line (#318) in fx.js:
this.curAnim = prop;
to this;
this.curAnim = jQuery.extend({}, prop);

Should fix the problem. However, I have no test case to run this against.

--
Brandon Aaron

On 10/10/06, Klaus Hartl [EMAIL PROTECTED] wrote:

  i was also thinking about copying the object but in a more basic version :)
 
   var anihide = options.anihide;
   var anihide2 = anihide;
   $(img).siblings(img:visible).animate(anihide2,
  anitime).end().animate(anishow, anitime);
  ;
 
  But that didn't work and i regret to say your workaround didn't work 
  either. :(
 
  I downloaded the uncompressed jquery and according to firebug the error is 
  situated in lines 91, 344, 979, 1350, 1359, 1370 and 1380. But that is 
  after the anihide object is set to true so i don't know if it's useful 
  information.
 
  If i find another way to avoid this i will let you know.
 

 Maybe you didn't copy it in the right place... see it has to be copied
 every time animate is called.

 In the tabs plugin that looks something like:

 jQuery.fn.tabs = function(options) {

  // copying here from options is not sufficient...

  return this.each(function() {
  jQuery('a').click(function() {
  // 1. copy objects
  // 2. call animate...
  });
  });

 };

 Would be great if this bug is fixed, because I could completely move
 that out from the click event making the whole thing perform better I
 guess...

 -- Klaus

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Klaus Hartl


Brandon Aaron schrieb:
 If I understand the issue correctly changing this line (#318) in fx.js:
 this.curAnim = prop;
 to this;
 this.curAnim = jQuery.extend({}, prop);
 
 Should fix the problem. However, I have no test case to run this against.

Yes, that looks good I think. Mike once pointed out that $.extend does 
only a shallow copy , so if the animate hash is going to be changed to 
hold another object as a value we will run into new problems. This is 
not very likely, but we should keep that in mind...


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Brandon Aaron
If someone can send me a test case I'd be more than happy to commit this to SVN.

--
Brandon Aaron

On 10/10/06, Klaus Hartl [EMAIL PROTECTED] wrote:


 Brandon Aaron schrieb:
  If I understand the issue correctly changing this line (#318) in fx.js:
  this.curAnim = prop;
  to this;
  this.curAnim = jQuery.extend({}, prop);
 
  Should fix the problem. However, I have no test case to run this against.

 Yes, that looks good I think. Mike once pointed out that $.extend does
 only a shallow copy , so if the animate hash is going to be changed to
 hold another object as a value we will run into new problems. This is
 not very likely, but we should keep that in mind...


 -- Klaus

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Jörn Zaefferer
Brandon Aaron schrieb:
 If someone can send me a test case I'd be more than happy to commit this to 
 SVN.
   
Just add something like this to animate:
@test stop();
var hash = {opacity: 'hide'};
var hashCopy = $.extend({}, hash);
$('#foo').animate(hash, 'fast', function() {
  ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the 
hash parameter' );
  start();
});

Using stop() and start() like that is necessary to test the asynchronous 
code. I'm not sure wheather that comparision suffices. Just run it 
against the current code to see if it fails.

-- Jörn

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Brandon Aaron
Thanks Jörn! I finally took some time to play around with the test
suite... good job!

This is now fixed in SVN.

--
Brandon Aaron

On 10/10/06, Jörn Zaefferer [EMAIL PROTECTED] wrote:
 Brandon Aaron schrieb:
  If someone can send me a test case I'd be more than happy to commit this to 
  SVN.
 
 Just add something like this to animate:
 @test stop();
 var hash = {opacity: 'hide'};
 var hashCopy = $.extend({}, hash);
 $('#foo').animate(hash, 'fast', function() {
   ok( hash.opacity == hashCopy.opacity, 'Check if animate changed the
 hash parameter' );
   start();
 });

 Using stop() and start() like that is necessary to test the asynchronous
 code. I'm not sure wheather that comparision suffices. Just run it
 against the current code to see if it fails.

 -- Jörn

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Jörn Zaefferer
Brandon Aaron schrieb:
 Thanks Jörn! I finally took some time to play around with the test
 suite... good job!

 This is now fixed in SVN.
   
Cool.

Is there a reason for not adding the test, too? The one big reason I put 
so much time into the test suite: By adding a test for every bug that 
occurs (before fixing it), odds are good that you notice them when they 
reoccur.

-- Jörn

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] animate problem

2006-10-10 Thread Brandon Aaron
To true ... wouldn't want to see it pop back up. I'll add it in.

--
Brandon Aaron

On 10/10/06, Jörn Zaefferer [EMAIL PROTECTED] wrote:
 Brandon Aaron schrieb:
  Thanks Jörn! I finally took some time to play around with the test
  suite... good job!
 
  This is now fixed in SVN.
 
 Cool.

 Is there a reason for not adding the test, too? The one big reason I put
 so much time into the test suite: By adding a test for every bug that
 occurs (before fixing it), odds are good that you notice them when they
 reoccur.

 -- Jörn

 ___
 jQuery mailing list
 discuss@jquery.com
 http://jquery.com/discuss/


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/