mirror of
https://github.com/videojs/video.js.git
synced 2025-03-31 22:22:09 +02:00
fix: Use passive event listeners for touchstart/touchmove (#4440)
If passive event listening is supported, we should use it. Fixes #4432.
This commit is contained in:
parent
b63666379d
commit
b4dc4f85b0
@ -202,6 +202,33 @@ export function fixEvent(event) {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether passive event listeners are supported
|
||||||
|
*/
|
||||||
|
let _supportsPassive = false;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
const opts = Object.defineProperty({}, 'passive', {
|
||||||
|
get() {
|
||||||
|
_supportsPassive = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('test', null, opts);
|
||||||
|
} catch (e) {
|
||||||
|
// disregard
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Touch events Chrome expects to be passive
|
||||||
|
*/
|
||||||
|
const passiveEvents = [
|
||||||
|
'touchstart',
|
||||||
|
'touchmove'
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an event listener to element
|
* Add an event listener to element
|
||||||
* It stores the handler function in a separate cache object
|
* It stores the handler function in a separate cache object
|
||||||
@ -273,7 +300,13 @@ export function on(elem, type, fn) {
|
|||||||
|
|
||||||
if (data.handlers[type].length === 1) {
|
if (data.handlers[type].length === 1) {
|
||||||
if (elem.addEventListener) {
|
if (elem.addEventListener) {
|
||||||
elem.addEventListener(type, data.dispatcher, false);
|
let options = false;
|
||||||
|
|
||||||
|
if (_supportsPassive &&
|
||||||
|
passiveEvents.indexOf(type) > -1) {
|
||||||
|
options = {passive: true};
|
||||||
|
}
|
||||||
|
elem.addEventListener(type, data.dispatcher, options);
|
||||||
} else if (elem.attachEvent) {
|
} else if (elem.attachEvent) {
|
||||||
elem.attachEvent('on' + type, data.dispatcher);
|
elem.attachEvent('on' + type, data.dispatcher);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user