Hi, I want to hide table rows with an effect and then remove them. I do this with Effect.Fade(row_id) Element.remove(row_id) However, it seems that Element.remove is executed in parallel with Effect.Fade, so the element disappears without effect. How can an element be removed with an effect? -- Sava Chankov --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Hey Sava, Sava Chankov a écrit :> Effect.Fade(row_id) > Element .remove(row_id) > > However, it seems that Element.remove is executed in parallel with > Effect.Fade, so the element disappears without effect. How can an > element be removed with an effect?Well, effects are executed asynchronously, so of course your remove call happens right after the effect *starts*. Also, you should always invoke effects using the "new" operator, to ensure proper execution. If you need to remove the element once the effect is complete, use the afterFinish callback: new Effect.Fade(row_id, { afterFinish: function() { Element.remove(row_id) } }); Beware: this won''t work in a loop, as row_id will be shared reference. However, if you need a single call within the scope of declaration of this row_id variable, you''re good to go. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve wrote:> Well, effects are executed asynchronously, so of course your remove call > happens right after the effect *starts*. Also, you should always invoke > effects using the "new" operator, to ensure proper execution. > > If you need to remove the element once the effect is complete, use the! > afterFinish callback: > > new Effect.Fade(row_id, { afterFinish: function() { Element.remove(row_id) } > }); > > Beware: this won''t work in a loop, as row_id will be shared reference. > However, if you need a single call within the scope of declaration of this > row_id variable, you''re good to go.Hi Cristophe, thanks for the fast reply! Unfortunately, afterFinish callback won''t work for me, because I''m creating another element with the id of the removed row. Is there a way to tell the Effect to execute synchronously? -- Sava Chankov --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Hey Sava, Sava Chankov a écrit :> Hi Cristophe, > thanks for the fast reply! Unfortunately, afterFinish callback won''t work for > me, because I''m creating another element with the id of the removed row. IsI don''t understand what you mean. You *must not* create another element with the same ID until after you removed the original one: that would mean two elements with the same ID in your DOM, which is the best way to a multitude of horrendous issues, and goes explicitly against (X)HTML/DOM rules. So your fix lies in NOT using the same ID twice (there are certainly so many ways to achieve your goal besides using duplicate IDs...).> there a way to tell the Effect to execute synchronously?You *do not* want to execute synchronously to the removal. This would just make no sense at all: one operation, the effect, executes over a period of time (default is 1 second); the other operation, the removal, is instantaneous, and would therefore break the effect''s processing. If you can''t find a way not to use the same IDs, just explain what you''re trying to achieve here, and we''ll find a fix for you :-) But please, think this over before engaging on a needlessly twisted path. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
If you''re using the same id, then why not use Element.replace in the afterFinish callback? Christophe makes it sound as if the world will explode if you use duplicate ids. It won''t. It''s certainly a less than ideal solution-- getElementById()/$() functions won''t work as you expect--but the browser takes it in stride. It''s best to avoid it if possible. TAG On Oct 31, 2006, at 8:20 AM, Christophe Porteneuve wrote:> > Hey Sava, > > Sava Chankov a écrit : >> Hi Cristophe, >> thanks for the fast reply! Unfortunately, afterFinish callback >> won''t work for >> me, because I''m creating another element with the id of the >> removed row. Is > > I don''t understand what you mean. You *must not* create another > element > with the same ID until after you removed the original one: that would > mean two elements with the same ID in your DOM, which is the best > way to > a multitude of horrendous issues, and goes explicitly against > (X)HTML/DOM rules. > > So your fix lies in NOT using the same ID twice (there are > certainly so > many ways to achieve your goal besides using duplicate IDs...). > >> there a way to tell the Effect to execute synchronously? > > You *do not* want to execute synchronously to the removal. This would > just make no sense at all: one operation, the effect, executes over a > period of time (default is 1 second); the other operation, the > removal, > is instantaneous, and would therefore break the effect''s processing. > > If you can''t find a way not to use the same IDs, just explain what > you''re trying to achieve here, and we''ll find a fix for you :-) But > please, think this over before engaging on a needlessly twisted path. > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve wrote:> Sava Chankov a écrit : >> Hi Cristophe, >> thanks for the fast reply! Unfortunately, afterFinish callback won''t work for >> me, because I''m creating another element with the id of the removed row. Is > > I don''t understand what you mean. You *must not* create another element > with the same ID until after you removed the original one: that would > mean two elements with the same ID in your DOM, which is the best way to > a multitude of horrendous issues, and goes explicitly against > (X)HTML/DOM rules. > > So your fix lies in NOT using the same ID twice (there are certainly so > many ways to achieve your goal besides using duplicate IDs...). > >> there a way to tell the Effect to execute synchronously? > > You *do not* want to execute synchronously to the removal. This would > just make no sense at all: one operation, the effect, executes over a > period of time (default is 1 second); the other operation, the removal, > is instantaneous, and would therefore break the effect''s processing. > > If you can''t find a way not to use the same IDs, just explain what > you''re trying to achieve here, and we''ll find a fix for you :-) But > please, think this over before engaging on a needlessly twisted path. >Excuse me for not expressing myself well - I meant, is there a way to tell Effect.Fade that it must block execution of the calling function when called (and not start fading the element in background) without having to put Element.remove(row) in afterFinish callback? I was confused, because at first I put only Element.remove in afterFinish. Then I realized that the all statements following Element.remove must go in the callback. The element with the same id as the row is appended after removal of the row, so there are no duplicate ids in the DOM. Thanks again for your help, Sava Chankov --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Hey there! Sava Chankov a écrit :> Excuse me for not expressing myself well - I meant, is there a way to tell > Effect.Fade that it must block execution of the calling function when called > (and not start fading the element in background) without having to put > Element.remove(row) in afterFinish callback?Well, not as such. You see, the only way to make an effect like that is to use timers. By definition, they execute in an asynchronous manner. JS is devoid of synchronization primitives, so you must use callbacks.> I was confused, because at first I put only Element.remove in afterFinish. Then > I realized that the all statements following Element.remove must go in the > callback.If they depend on the remove, yes. You might put them in a standalone function, and call this function from the afterFinish callback.> The element with the same id as the row is appended after removal of > the row, so there are no duplicate ids in the DOM.Excellent. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---