Skip to content

Instantly share code, notes, and snippets.

@jimmont
Last active August 27, 2017 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmont/761369d2f2d3f275e2dd1c70dd4fa563 to your computer and use it in GitHub Desktop.
Save jimmont/761369d2f2d3f275e2dd1c70dd4fa563 to your computer and use it in GitHub Desktop.
collection to sync various api details in Safari-current and Chrome-current
if(!Event.prototype.hasOwnProperty('path')){
/*
in event handlers use the event.path which looks like:
for attached DOM nodes [target,target.parentNode,...<ancestors>...,document,window]
for unattached DOM nodes [target]
for window and document: [window] [document, window]
*/
Object.defineProperty(Event.prototype, 'path', {
// for Safari
get:function(){
var value = [], $0 = this.target, $1;
while($0){
value.push($0);
$0 = $0.parentNode;
};
$0 = value[value.length - 1];
// if last item is a document, include its window
if($0){
$0 = $0.defaultView;
if($0) value.push($0);
};
return value;
}
,set: function(){ }
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment