Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Add work around for X-Tag issue related to relatedTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Oct 10, 2013
1 parent 5bb221b commit e83c09e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,19 @@

if ('relatedTarget' in event) {
var originalEvent = unwrap(event);
var relatedTarget = wrap(originalEvent.relatedTarget);

var adjusted = adjustRelatedTarget(currentTarget, relatedTarget);
if (adjusted === target)
return true;

relatedTargetTable.set(event, adjusted);
// X-Tag sets relatedTarget on a CustomEvent. If they do that there is no
// way to have relatedTarget return the adjusted target but worse is that
// the originalEvent might not have a relatedTarget so we hit an assert
// when we try to wrap it.
if (originalEvent.relatedTarget) {
var relatedTarget = wrap(originalEvent.relatedTarget);

var adjusted = adjustRelatedTarget(currentTarget, relatedTarget);
if (adjusted === target)
return true;

relatedTargetTable.set(event, adjusted);
}
}

eventPhaseTable.set(event, phase);
Expand Down
13 changes: 13 additions & 0 deletions test/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,4 +1277,17 @@ test('retarget order (multiple shadow roots)', function() {
text.dispatchEvent(new Event('x'));
});

test('manual relatedTarget', function() {
var ce = new CustomEvent('x');
ce.relatedTarget = 42;
var count = 0;
document.addEventListener('x', function f(e) {
count++;
assert.equal(e.relatedTarget, 42);
document.removeEventListener('x', f);
});
document.dispatchEvent(ce);
assert.equal(count, 1);
});

});

0 comments on commit e83c09e

Please sign in to comment.