Improve playing experience on smartphones
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 17 Nov 2021 13:30:20 +0000 (14:30 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 17 Nov 2021 13:30:20 +0000 (14:30 +0100)
base_rules.js

index 4808d0c..82eec3a 100644 (file)
@@ -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});
     }
   }