Skip to content

Instantly share code, notes, and snippets.

@prajwalit
Last active December 21, 2015 08:39
Show Gist options
  • Save prajwalit/6279413 to your computer and use it in GitHub Desktop.
Save prajwalit/6279413 to your computer and use it in GitHub Desktop.
Delegate for webkit
var delegate = function (node, type, listener, selector) {
var handler = node.addEventListener (type, function (e) {
var t = e.target, matched = false;
while (!node.isSameNode (t)) {
if (t.webkitMatchesSelector (selector)) {
matched = true;
break;
} else {
t = t.parentNode;
}
}
if (matched) {
e.currTarget = t;
listener (e);
}
});
return handler;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment