Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: Re: Clone node with events Date: Sat, 12 Jan 2013 22:57:50 +0100 Organization: Aioe.org NNTP Server Lines: 61 Message-ID: References: <3cfb8a75-8706-42d6-9cc5-fbd293ee29f9@10g2000yqo.googlegroups.com> NNTP-Posting-Host: zYd0PXwpR9QMvAmoEDGsiw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:18094 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/