aboutsummaryrefslogtreecommitdiffhomepage
path: root/ui/static/js
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-07-10 20:41:27 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-07-10 20:41:27 -0700
commit3bdb9251da602067e365fe45f3c6259b0ca27a0a (patch)
treebdf2fff7d827138c1fd82fca734d34d70a07ac29 /ui/static/js
parent6d25e02cb5e3ddd9f3fc8dfb44cf29c98866d587 (diff)
Use passive event listeners for touch events
Avoid this warning in Chrome console: https://www.chromestatus.com/feature/5745543795965952
Diffstat (limited to 'ui/static/js')
-rw-r--r--ui/static/js/dom_helper.js19
-rw-r--r--ui/static/js/touch_handler.js9
2 files changed, 24 insertions, 4 deletions
diff --git a/ui/static/js/dom_helper.js b/ui/static/js/dom_helper.js
index 8a0644b..903e9a9 100644
--- a/ui/static/js/dom_helper.js
+++ b/ui/static/js/dom_helper.js
@@ -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;
+ }
}
diff --git a/ui/static/js/touch_handler.js b/ui/static/js/touch_handler.js
index 69488a5..a6c5c81 100644
--- a/ui/static/js/touch_handler.js
+++ b/ui/static/js/touch_handler.js
@@ -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);
});
}
}