From cb17fed82eff544b3e8a340584dd8f61a905f06f Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Wed, 17 Nov 2021 14:30:20 +0100
Subject: [PATCH] Improve playing experience on smartphones

---
 base_rules.js | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/base_rules.js b/base_rules.js
index 4808d0c..82eec3a 100644
--- a/base_rules.js
+++ b/base_rules.js
@@ -876,6 +876,8 @@ export default class ChessRules {
         startPiece, curPiece = null,
         sqSize;
     const mousedown = (e) => {
+      // Disable zoom on smartphones:
+      if (e.touches && e.touches.length > 1) e.preventDefault();
       r = container.getBoundingClientRect();
       sqSize = this.getSquareWidth(r.width);
       const square = this.idToCoords(e.target.id);
@@ -943,9 +945,10 @@ export default class ChessRules {
       document.addEventListener("mouseup", mouseup);
     }
     if ('ontouchstart' in window) {
-      document.addEventListener("touchstart", mousedown);
-      document.addEventListener("touchmove", mousemove);
-      document.addEventListener("touchend", mouseup);
+      // https://stackoverflow.com/a/42509310/12660887
+      document.addEventListener("touchstart", mousedown, {passive: false});
+      document.addEventListener("touchmove", mousemove, {passive: false});
+      document.addEventListener("touchend", mouseup, {passive: false});
     }
   }
 
-- 
2.44.0