[ 5 posts ]

Allan Jardine

  • Username: theallan
  • Joined: Mon Jul 26, 2010 11:42 am
  • Posts: 3
  • Offline
  • Profile

Usage of getListeners - seems to give null for every node

Post Posted: Mon Jul 26, 2010 11:55 am
+0-
Hello all,

I might be making a very basic mistake here (in which case, my apologies) but I can't seem to get even a very basic use of Y.Event.getListeners to return anything other than null.

On this demo page there is a 'click' event attached to the element with an ID of "container": http://developer.yahoo.com/yui/3/exampl ... clean.html . So I would have expected the following to give me back that event:

Code:
YUI().use("event", function (Y) {
   console.dir( Y.Event.getListeners(document.getElementById('container')) );
} );


I'm sure I'm missing something but I can't see what. I've added a bit of debug into the event core as well, it has the internal variable "_el_events" as null. Is there a closure going on here?

Many thanks,
Allan

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile
Tags:

Re: Usage of getListeners - seems to give null for every nod

Post Posted: Mon Jul 26, 2010 1:26 pm
+0-
Hi,

Not sure. This works:
Code:
YUI().use('event', function (Y) {
  Y.one("#div1").on("click", function(){console.log("clicked on div1");});
  console.log(Y.Event.getListeners(Y.one("#div1")));
});


But the docs say getListeners argument is a string or HTML element, rather than a YUI Node. But like you I can't get it to work with a string or HTML element, so don't know if this is a documenting bug or there is something else going on.

Matt

Allan Jardine

  • Username: theallan
  • Joined: Mon Jul 26, 2010 11:42 am
  • Posts: 3
  • Offline
  • Profile

Re: Usage of getListeners - seems to give null for every nod

Post Posted: Mon Jul 26, 2010 11:07 pm
+0-
Hi Matt,

Thanks for the reply! Indeed what you have works great on the example. However the following does not:

Code:
YUI().use('event', function (Y) {
   Y.one("#container").on("click", function(){
      console.log("clicked on container");
   })
});

YUI().use('event', function (Y) {
   console.log(Y.Event.getListeners(Y.one("#container")));
});


So it looks like there is a closure going on here - one instance of Y cannot see the events which are applied by another instance (presuming they are separate instances).

So the question arises, is there any way to get the events for events which have already been assigned?

Regards,
Allan

Matt Parker

YUI Contributor

  • Username: mattatlamplight
  • Joined: Mon Apr 20, 2009 12:03 pm
  • Posts: 466
  • Location: London UK
  • GitHub: mattparker
  • Gists: mattparker
  • Offline
  • Profile
Tags:

Re: Usage of getListeners - seems to give null for every nod

Post Posted: Mon Jul 26, 2010 11:41 pm
+0-
That's right, each instance of Y has it's own cache of Nodes, which won't be available to another Y, which I think is why your example fails.

I don't know the answer to your question: my suspicion is that the answer is no, not directly. However, you should, I think be able to use broadcasting http://developer.yahoo.com/yui/3/event/#broadcast to do what you need.

Others may have other/better ideas...

Matt

Allan Jardine

  • Username: theallan
  • Joined: Mon Jul 26, 2010 11:42 am
  • Posts: 3
  • Offline
  • Profile
Tags:

Re: Usage of getListeners - seems to give null for every nod

Post Posted: Tue Jul 27, 2010 12:38 am
+0-
Hi Matt,

Thanks for the information. I was hoping to be able to add YUI 3 support to my Visual Event tool: http://www.sprymedia.co.uk/article/Visual+Event . YUI 2 support is available through the getListeners function, but it looks like the sand boxing / closure in YUI 3 is going to make adding support impossible without having a requirement for the developer to modify their code in some predefined manner.

Regards,
Allan
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum