1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

Checking on the event the relatedTarget exists before setting its property

Fixes a bug where relatedTarget was undefined in Firefox

fixes #2024
closes #2025
This commit is contained in:
Michelle Anderson 2015-04-09 11:03:29 +01:00 committed by heff
parent 004b1e8f7b
commit 3479a545aa
3 changed files with 26 additions and 3 deletions

View File

@ -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))
--------------------

View File

@ -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 () {

View File

@ -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 });
});