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


Groups > comp.lang.javascript > #18115

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-16 20:50 +0100
Organization Aioe.org NNTP Server
Message-ID <kd7096$78e$1@speranza.aioe.org> (permalink)
References <kcm8um$8pi$1@speranza.aioe.org> <3cfb8a75-8706-42d6-9cc5-fbd293ee29f9@10g2000yqo.googlegroups.com> <kcsm8o$8of$1@speranza.aioe.org> <4079901.yXqkfi7LMG@PointedEars.de>

Show all headers | View raw


W dniu 2013-01-13 15:07, Thomas 'PointedEars' Lahn pisze:
> Cezary Tomczyk wrote:
[...]
> First of all, you are _not_ copying events.  You could be copying event
> *listeners*, but all you would copy in ECMAScript would be *references* to
> Function instances.
>
> So there is no problem here.  You have a reference to a Function instance,
> and the “click” event bubbles in all know DOM implementations.  So, as
> already suggested, you should use event delegation, in particular use event
> bubbling: Add to a common ancestor element a listener for that event that
> does actions only for specific event targets.  When a cloned target receives
> that event, it has no listener for it; since the event bubbles, it will be
> handled by the ancestor element which has a listener for it.

Yes, that's a good idea and I know that. But, seems that I was 
misunderstood. I want to clone node where I do not know if there are 
attached event listeners or not. The only one thing that can I do is 
write wrapper on addEventListener and attachEvent to collect all event 
listeners and reattach them to specified node after cloning.

> BTW, you should not be using attachEvent() as an alternative to
> addEventListener():

> <http://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html>

Right. I should use "else if".

>> 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 :-(
>
> Neither is it implemented in WebKit WebCore as of Chromium 22.  You are
> referring to an *old* Working Draft.  The *current* Working Draft for W3C
> DOM Level 3 Events is available at
>
> <http://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120906/>.

Ah, yes. My link is very old :/

> You will notice that the EventTarget interface no longer has an
> “eventListeners” attribute of type “EventListenerList”, and that the
> “EventListenerList” interface has been removed:
>
> <http://www.w3.org/TR/2012/WD-DOM-Level-3-Events-20120906/#interface-
> EventTarget>
>
> And it would seem that no replacement for that attribute or interface has
> been suggested yet.
>
> However, with proprietary event handler properties (called “traditional
> event registration” on QuirksMode.org) now perhaps going to be a Web
> standard with the HTML5 API, for elements and events for which only one
> event listener has been added, you could use those properties to retrieve
> the primary event listener for an event on an element:
>
> <http://www.w3.org/html/wg/drafts/html/master/index.html#ix-event-handlers>
> <http://www.w3.org/html/wg/drafts/html/master/webappapis.html#event-
> handlers>
>
> While that has worked even before HTML5 (jsx.dom.*EventListener() are based
> on it), I recommend you use event bubbling here.

I know that I can use event bubbling, but as I mentioned, sometimes I do 
not know if node has an attached any listeners or not. But I think that 
I can do something like I described above.

Heh, I event found your old post 
http://www.velocityreviews.com/forums/t936046-list-events-of-an-element-wired-up-with-addeventlistener.html, 
but this is what I meant :-)

-- 
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