1
0
mirror of https://github.com/videojs/video.js.git synced 2025-03-17 21:18:27 +02:00

revert: fix(events): ensure we attach events to objects we know how to (#3727)

This reverts commit bfcb9e2fb5935345c462bc4691faa16cb87932da.
This commit is contained in:
Gary Katsevman 2016-12-02 16:11:04 -05:00
parent bfcb9e2fb5
commit bed19be9cd
2 changed files with 9 additions and 22 deletions

View File

@ -778,17 +778,18 @@ class Component {
// Add the same function ID so we can easily remove it later
cleanRemover.guid = fn.guid;
// If we are attaching to a component like object use the preferred `on` method
if (typeof target.on === 'function') {
// Add the listener to the other component
target.on(type, fn);
target.on('dispose', cleanRemover);
} else if (Events.canAttachEvent(target)) {
// Check if this is a DOM node
if (first.nodeName) {
// Add the listener to the other element
Events.on(target, type, fn);
Events.on(target, 'dispose', cleanRemover);
} else {
log.warn(`Not adding ${type} listener. Not sure how to add it.`);
// Should be a component
// Not using `instanceof Component` because it makes mock players difficult
} else if (typeof first.on === 'function') {
// Add the listener to the other component
target.on(type, fn);
target.on('dispose', cleanRemover);
}
}

View File

@ -203,20 +203,6 @@ export function fixEvent(event) {
return event;
}
/**
* Determine if the events utility will be able to attach events to this object.
*
* @param {Object} obj Object to check
* @method canAttachEvent
* @return {Boolean} True if events can be attached to this object
*/
export function canAttachEvent(obj) {
const hasAddListener = typeof obj.addEventListener === 'function';
const hasAttachEvent = typeof obj.attachEvent === 'function';
return hasAddListener || hasAttachEvent;
}
/**
* Add an event listener to element
* It stores the handler function in a separate cache object