You are absolutely right. Don't know what i was thinking.
Thank you for this excellent post Rob!
On 4/10/07, RobG <[EMAIL PROTECTED]> wrote:
>
> On Apr 10, 11:55 am, "Kjell Bublitz" <[EMAIL PROTECTED]> 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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---