Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18094

Re: Clone node with events

From Cezary Tomczyk <cezary.tomczyk@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Clone node with events
Date 2013-01-12 22:57 +0100
Organization Aioe.org NNTP Server
Message-ID <kcsm8o$8of$1@speranza.aioe.org> (permalink)
References <kcm8um$8pi$1@speranza.aioe.org> <3cfb8a75-8706-42d6-9cc5-fbd293ee29f9@10g2000yqo.googlegroups.com>

Show all headers | View raw


W dniu 2013-01-10 16:30, Scott Sauyet pisze:
> Cezary Tomczyk wrote:
[...]
>> Any idea how to in an efficient and proper way clone node with events?
>
> One problem is that in general it's not always clear that events
> should be cloned, or that if they are cloned that they will now do
> what you'd expect.

> If you have this structure:
>
>      Div 1
>      Div 2
>        Checkbox 2.1
>            EventListener 2.1.1 : toggles Div 1
>        Div 2.2
>        Checkbox 2.3
>            EventListener 2.3.1 : toggles Div 2.2
>
> And want to clone Div 2, all its children and their events, it mostly
> makes sense:
>
>      Div 2a
>        Checkbox 2.1a
>            EventListener 2.1.1a : toggles Div 1
>        Div 2.2a
>        Checkbox 2.3a
>            EventListener 2.3.1a : ??
>
> But what would EventListener 2.3.1a do?  Should it toggle Div 2.2?
> That seems strange.  Probably toggling Div 2.2a makes more sense, but
> how we would we distinguish this from EventListener 2.1.1a, which
> doesn't change it's target?  And of course this doesn't even address
> the fact that we don't actually have a way to convert an event
> listening function that toggles the visibility of one DIV into one
> that toggles the visibility of another.  So we don't really know what
> to do or how to do it.  :-)

Yes, that situation shows that cloning with events is not so clear. But 
consider this simple example:

http://jsfiddle.net/JpLx2/

All I need here is to just copy attached events from old_node to 
new_node, but seems that is not so easy to do. This could be possible 
done by, for example, adding some wrapper to event methods and then use it.

On the other hand I found 
http://www.w3.org/TR/2001/WD-DOM-Level-3-Events-20010823/events.html#Events-EventListenerList, 
but seems that it is not implemented, for example, in Firefox 17.0.1 and 
Opera 12.12. Probably in other browsers also is not implemented :-(

> So event listeners that were copied would have to be smart enough to
> determine their behavior based on where they were triggered.  It gets
> ugly.

Seems it is not so easy case ;-)

-- 
Cezary Tomczyk
http://www.ctomczyk.pl/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Clone node with events Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-10 12:33 +0100
  Re: Clone node with events Scott Sauyet <scott.sauyet@gmail.com> - 2013-01-10 07:30 -0800
    Re: Clone node with events Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-12 22:57 +0100
      Re: Clone node with events Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-01-13 15:07 +0100
        Re: Clone node with events Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-16 20:50 +0100
  Re: Clone node with events Stefan Weiss <krewecherl@gmail.com> - 2013-01-10 17:15 +0100
    Re: Clone node with events Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-01-12 23:00 +0100
  Re: Clone node with events RobG <rgqld@iinet.net.au> - 2013-01-13 22:07 -0800

csiph-web