]> cat aescling's git repositories - mastodon.git/commitdiff
Set touchstart listener to 'passive', remove 'once' (#5011)
authorNolan Lawson <nolan@nolanlawson.com>
Tue, 19 Sep 2017 15:00:29 +0000 (08:00 -0700)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 19 Sep 2017 15:00:29 +0000 (17:00 +0200)
app/javascript/mastodon/is_mobile.js

index e9903d59ef9ec33dc7601279a38740041945d6a2..dbdb30081dba0979a7494a3929cbb3e331c2d038 100644 (file)
@@ -1,3 +1,5 @@
+import detectPassiveEvents from 'detect-passive-events';
+
 const LAYOUT_BREAKPOINT = 1024;
 
 export function isMobile(width) {
@@ -5,11 +7,16 @@ export function isMobile(width) {
 };
 
 const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
+
 let userTouching = false;
+let listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false;
 
-window.addEventListener('touchstart', () => {
+function touchListener() {
   userTouching = true;
-}, { once: true });
+  window.removeEventListener('touchstart', touchListener, listenerOptions);
+}
+
+window.addEventListener('touchstart', touchListener, listenerOptions);
 
 export function isUserTouching() {
   return userTouching;