mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Use passive event listeners for touch events
Avoid this warning in Chrome console: https://www.chromestatus.com/feature/5745543795965952
This commit is contained in:
parent
6d25e02cb5
commit
3bdb9251da
3 changed files with 29 additions and 7 deletions
|
@ -43,4 +43,23 @@ class DomHelper {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
static hasPassiveEventListenerOption() {
|
||||
var passiveSupported = false;
|
||||
|
||||
try {
|
||||
var options = Object.defineProperty({}, "passive", {
|
||||
get: function() {
|
||||
passiveSupported = true;
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("test", options, options);
|
||||
window.removeEventListener("test", options, options);
|
||||
} catch(err) {
|
||||
passiveSupported = false;
|
||||
}
|
||||
|
||||
return passiveSupported;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,12 +83,13 @@ class TouchHandler {
|
|||
|
||||
listen() {
|
||||
let elements = document.querySelectorAll(".touch-item");
|
||||
let hasPassiveOption = DomHelper.hasPassiveEventListenerOption();
|
||||
|
||||
elements.forEach((element) => {
|
||||
element.addEventListener("touchstart", (e) => this.onTouchStart(e), false);
|
||||
element.addEventListener("touchmove", (e) => this.onTouchMove(e), false);
|
||||
element.addEventListener("touchend", (e) => this.onTouchEnd(e), false);
|
||||
element.addEventListener("touchcancel", () => this.reset(), false);
|
||||
element.addEventListener("touchstart", (e) => this.onTouchStart(e), hasPassiveOption ? { passive: true } : false);
|
||||
element.addEventListener("touchmove", (e) => this.onTouchMove(e), hasPassiveOption ? { passive: true } : false);
|
||||
element.addEventListener("touchend", (e) => this.onTouchEnd(e), hasPassiveOption ? { passive: true } : false);
|
||||
element.addEventListener("touchcancel", () => this.reset(), hasPassiveOption ? { passive: true } : false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue