Skip to content

Commit

Permalink
Added workaround for missing event.path
Browse files Browse the repository at this point in the history
  • Loading branch information
maciex committed Aug 5, 2016
1 parent bc51773 commit 03e7ce5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions js/content_scripts/context-menu-content-scripts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function getEventPath(event) {
var path = [];
var node = event.target;
while(node != document.body) {
path.push(node);
node = node.parentNode;
}
return path;
}

function addContextMenuTo(selector) {
selector = selector + ', ' + selector + ' *';
var matches;
Expand All @@ -11,14 +21,16 @@ function addContextMenuTo(selector) {
var isHovering = false;
document.addEventListener('mouseover', function(event) {
if (event.target && event.target[matches](selector)) {
if (event.path) {
for (var i = 0; i < event.path.length; i++) {
var element = event.path[i];
if (element[matches] && element[matches]('a')) {
createContextMenu(element.href);
isHovering = true;
break;
}
if (!event.path) {
console.log("Using workaround to get event.path");
event.path = getEventPath(event);
}
for (var i = 0; i < event.path.length; i++) {
var element = event.path[i];
if (element[matches] && element[matches]('a')) {
createContextMenu(element.href);
isHovering = true;
break;
}
}
} else if (isHovering) {
Expand Down

0 comments on commit 03e7ce5

Please sign in to comment.