Skip to content

Instantly share code, notes, and snippets.

@hawkapparel
Created February 22, 2017 15:25
Show Gist options
  • Save hawkapparel/9f0060510ea616ad33a356a59f42d2de to your computer and use it in GitHub Desktop.
Save hawkapparel/9f0060510ea616ad33a356a59f42d2de to your computer and use it in GitHub Desktop.
//It's not available, but if you really would like to have this property,
//then you could extend the native prototype of the Event object like so:
if (!("path" in Event.prototype))
Object.defineProperty(Event.prototype, "path", {
get: function() {
var path = [];
var currentElem = this.target;
while (currentElem) {
path.push(currentElem);
currentElem = currentElem.parentElement;
}
if (path.indexOf(window) === -1 && path.indexOf(document) === -1)
path.push(document);
if (path.indexOf(window) === -1)
path.push(window);
return path;
}
});
Ref: http://stackoverflow.com/questions/36845515/mouseevent-path-equivalent-in-firefox-safari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment