| Page 1 of 1 | [ 5 posts ] |
|
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 ParkerYUI Contributor
|
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 |
|
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 ParkerYUI Contributor
|
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 |
|
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 |
| Page 1 of 1 | [ 5 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group