I have in window.onload the following Event.observe(''image'', ''click'', function(){ new ImageLoad($(''image'').id) }) In the ImageLoad class i clone $(''image'') with var clone = $(''image'').cloneNode(true); and then insert it somewhere else $(''oldimage'').appendChild(clone); In IE7 (and maybe other IEs) the ''click'' Event is still active on the clone. Even with changed ID, changed size, everything ... I tried to stopObserve with the same parameters, aswell as using the clone-variable, before and after clone modification, but nothing seems to work. What can i do? -- Regards, Kjell www.m3nt0r.de --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Kjell, I had the same problem on IE6 and IE7. The only solution I found that worked was to delete the elements and recreate them. It''s quite sad to use this kind of (ugly and embarrassing) hack, so if anyone has a better solution to it I would be very grateful :-) Miguel Kjell Bublitz wrote:> I have in window.onload the following > > Event.observe(''image'', ''click'', function(){ new ImageLoad($(''image'').id) }) > > In the ImageLoad class i clone $(''image'') with > > var clone = $(''image'').cloneNode(true); > > and then insert it somewhere else > > $(''oldimage'').appendChild(clone); > > In IE7 (and maybe other IEs) the ''click'' Event is still active on the > clone. Even with changed ID, changed size, everything ... > > I tried to stopObserve with the same parameters, aswell as using the > clone-variable, before and after clone modification, but nothing seems > to work. > > What can i do? > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Apr-10 02:20 UTC
Re: Event.observe & cloneNode = events copied :/
Could you use stopObserving() to stop the event listeners prior to cloning the nodes? -- Dash -- Miguel wrote:> Hi Kjell, > > I had the same problem on IE6 and IE7. > The only solution I found that worked was to delete the elements and > recreate them. > It''s quite sad to use this kind of (ugly and embarrassing) hack, so if > anyone has a better solution to it I would be very grateful :-) > > Miguel > > > Kjell Bublitz wrote: > >> I have in window.onload the following >> >> Event.observe(''image'', ''click'', function(){ new ImageLoad($(''image'').id) }) >> >> In the ImageLoad class i clone $(''image'') with >> >> var clone = $(''image'').cloneNode(true); >> >> and then insert it somewhere else >> >> $(''oldimage'').appendChild(clone); >> >> In IE7 (and maybe other IEs) the ''click'' Event is still active on the >> clone. Even with changed ID, changed size, everything ... >> >> I tried to stopObserve with the same parameters, aswell as using the >> clone-variable, before and after clone modification, but nothing seems >> to work. >> >> What can i do? >> >> >> > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 10, 11:55 am, "Kjell Bublitz" <m3nt0r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have in window.onload the following > > Event.observe(''image'', ''click'', function(){ new ImageLoad($(''image'').id) })My first, more detailed response was trashed by Google Groups, here''s a more concise version... Consider: $(''image'').onclick = function(){new ImageLoad(this.id)};> > In the ImageLoad class i clone $(''image'') with > > var clone = $(''image'').cloneNode(true); > > and then insert it somewhere else > > $(''oldimage'').appendChild(clone); > > In IE7 (and maybe other IEs) the ''click'' Event is still active on the > clone. Even with changed ID, changed size, everything ...Don''t use Event.observe unless you have a really good reason for doing so, just use the element''s onclick property. Then the handlers aren''t cloned with the element. Using Event.observe (and hence attachEvent and addEventListener), the behaviour of event hanlders is quite different across browsers. Prototype fixes the different setting of the handler''s this keyword but not the different treatment of handlers on cloned nodes nor does it replicate the W3C capture phase for IE. For in-line hanlders, IE and Firefox keep them when nodes are clonde. When added to the dot property ( el.onclick = function(){...}; or someFn;) both will drop the handler from cloned nodes. But for attachEvent/addEventListener, IE keeps them and Firefox drops them.> I tried to stopObserve with the same parameters, aswell as using the > clone-variable, before and after clone modification, but nothing seems > to work.You can''t remove an anonymous function event handler that is added using addEventListener or attachEvent (other than Firefox removing them when the node is cloned).> What can i do?Use the on<event> property of the element, then the handler isn''t cloned. If you *must* use Event.observe (there are very few situations where its use is required), use a function reference rather than an anonymous function, remove it before cloning, then re-attach it. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
You are absolutely right. Don''t know what i was thinking. Thank you for this excellent post Rob! On 4/10/07, RobG <rgqld-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> > On Apr 10, 11:55 am, "Kjell Bublitz" <m3nt0r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have in window.onload the following > > > > Event.observe(''image'', ''click'', function(){ new ImageLoad($(''image'').id) }) > > My first, more detailed response was trashed by Google Groups, here''s > a more concise version... > > Consider: > > $(''image'').onclick = function(){new ImageLoad(this.id)}; > > > > > In the ImageLoad class i clone $(''image'') with > > > > var clone = $(''image'').cloneNode(true); > > > > and then insert it somewhere else > > > > $(''oldimage'').appendChild(clone); > > > > In IE7 (and maybe other IEs) the ''click'' Event is still active on the > > clone. Even with changed ID, changed size, everything ... > > Don''t use Event.observe unless you have a really good reason for doing > so, just use the element''s onclick property. Then the handlers aren''t > cloned with the element. > > Using Event.observe (and hence attachEvent and addEventListener), the > behaviour of event hanlders is quite different across browsers. > Prototype fixes the different setting of the handler''s this keyword > but not the different treatment of handlers on cloned nodes nor does > it replicate the W3C capture phase for IE. > > For in-line hanlders, IE and Firefox keep them when nodes are clonde. > When added to the dot property ( el.onclick = function(){...}; or > someFn;) both will drop the handler from cloned nodes. But for > attachEvent/addEventListener, IE keeps them and Firefox drops them. > > > > I tried to stopObserve with the same parameters, aswell as using the > > clone-variable, before and after clone modification, but nothing seems > > to work. > > You can''t remove an anonymous function event handler that is added > using addEventListener or attachEvent (other than Firefox removing > them when the node is cloned). > > > > What can i do? > > Use the on<event> property of the element, then the handler isn''t > cloned. If you *must* use Event.observe (there are very few > situations where its use is required), use a function reference rather > than an anonymous function, remove it before cloning, then re-attach > it. > > > -- > Rob > > > > >-- Regards, Kjell www.m3nt0r.de --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---