diff --git a/CHANGELOG.md b/CHANGELOG.md index 2be10d6d07..a601bd1ba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ CHANGELOG * @mmcc added the vjs-big-play-centered class ([view](https://github.com/videojs/video.js/pull/2293)) * @thijstriemstra added a logged error when a plugin is missing ([view](https://github.com/videojs/video.js/pull/1931)) * @gkatsev fixed the texttrackchange event and text track display for non-native tracks ([view](https://github.com/videojs/video.js/pull/2215)) +* @mischizzle fixed event.relatedTarget in Firefox ([view](https://github.com/videojs/video.js/pull/2025)) -------------------- diff --git a/src/js/utils/events.js b/src/js/utils/events.js index c4357c047c..15c8115121 100644 --- a/src/js/utils/events.js +++ b/src/js/utils/events.js @@ -238,9 +238,11 @@ export function fixEvent(event) { } // Handle which other element the event is related to - event.relatedTarget = event.fromElement === event.target ? - event.toElement : - event.fromElement; + if (!event.relatedTarget) { + event.relatedTarget = event.fromElement === event.target ? + event.toElement : + event.fromElement; + } // Stop the default browser action event.preventDefault = function () { diff --git a/test/unit/events.test.js b/test/unit/events.test.js index 19bd671e82..1083c095d4 100644 --- a/test/unit/events.test.js +++ b/test/unit/events.test.js @@ -219,3 +219,23 @@ test('should have a defaultPrevented property on an event that was prevent from Events.trigger(el, 'test'); }); + +test('should have relatedTarget correctly set on the event', function() { + expect(2); + + var el1 = document.createElement('div'), + el2 = document.createElement('div'), + relatedEl = document.createElement('div'); + + Events.on(el1, 'click', function(e){ + equal(e.relatedTarget, relatedEl, 'relatedTarget is set for all browsers when related element is set on the event'); + }); + + Events.trigger(el1, { type:'click', relatedTarget:relatedEl }); + + Events.on(el2, 'click', function(e) { + equal(e.relatedTarget, null, 'relatedTarget is null when none is provided'); + }); + + Events.trigger(el2, { type:'click', relatedTarget:undefined }); +});