From: Benjamin Auder Date: Wed, 17 Nov 2021 13:30:20 +0000 (+0100) Subject: Improve playing experience on smartphones X-Git-Url: https://git.auder.net/variants/Chakart/config.php?a=commitdiff_plain;h=cb17fed82eff544b3e8a340584dd8f61a905f06f;p=xogo.git Improve playing experience on smartphones --- 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}); } }