From dccf0c6ba39af9949611867d0c15bf9a90eec0ec Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Wed, 12 Mar 2014 13:04:46 -0400 Subject: [PATCH] Work around IE bug related to relatedTarget --- src/wrappers/events.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wrappers/events.js b/src/wrappers/events.js index a4da32e..faaa5c9 100644 --- a/src/wrappers/events.js +++ b/src/wrappers/events.js @@ -261,12 +261,20 @@ if ('relatedTarget' in event) { var originalEvent = unwrap(event); + var unwrappedRelatedTarget = originalEvent.relatedTarget; + // 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); + + // In IE we can get objects that are not EventTargets at this point. + // Safari does not have an EventTarget interface so revert to checkin for + // addEventListener as an approximation. + + if (unwrappedRelatedTarget && unwrappedRelatedTarget instanceof Object && + unwrappedRelatedTarget.addEventListener) { + var relatedTarget = wrap(unwrappedRelatedTarget); var adjusted = adjustRelatedTarget(currentTarget, relatedTarget); if (adjusted === target)