Skip to content

Instantly share code, notes, and snippets.

@sidnei
Created September 28, 2010 19:03
Show Gist options
  • Save sidnei/601575 to your computer and use it in GitHub Desktop.
Save sidnei/601575 to your computer and use it in GitHub Desktop.
// Works. Logs 'click'.
YUI().use("event", "node", "node-event-simulate", function(Y){
var node = Y.one(".item");
node.on("foo|click", function() {
console.log("clicked");
});
node.simulate("click");
node.detach("foo|click");
node.simulate("click");
});
// Does not work. Logs 'click' x2. If called again, x4 and so on.
YUI().use("event", "node", "node-event-simulate", function(Y){
var nodes = Y.all(".item");
var node = Y.one(".item");
nodes.on("foo|click", function() {
console.log("clicked");
});
node.simulate("click");
nodes.detach("foo|click");
node.simulate("click");
});
// Works. Logs 'click' once.
YUI().use("event", "node", "node-event-simulate", function(Y){
var nodes = Y.all(".item");
var node = Y.one(".item");
nodes.each(function(n) {
n.on("foo|click", function() {
console.log("clicked");
});
});
node.simulate("click");
nodes.each(function(n) {
n.detach("foo|click");
});
node.simulate("click");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment