shaack / cm-chessboard

A JavaScript chessboard without dependencies. Rendered in SVG, coded in ES6. Views FEN, handles move input, animated, responsive, expandable
MIT License
209 stars 63 forks source link

fix promotion on mobile (Chrome) in the case that touchstart events get preventDefaulted #131

Closed FurriousFox closed 4 months ago

FurriousFox commented 9 months ago

the mousedown event doesn't get emitted on mobile, making it impossible to promote, so use pointerdown instead

shaack commented 9 months ago

Is this a guess or really tested? I ask, because this script runs on my chess server chessmail.de and is used daily by 3000 users on all devices. https://www.chessmail.de/pages/chess-computer.html

Can you please give me more details on which phone, browser and OS it does not work.

FurriousFox commented 9 months ago

It was tested in my own project, though I assumed the issue was more widespread than it really was.

It seems that this change is only needed for projects where .preventDefault() gets called on touchstart events (which is the case for my project) as it seems that on Chrome (I'm not sure about other browsers), the mousedown event doesn't get fired if the touchstart event got preventDefaulted.

shaack commented 9 months ago

Yes, now it makes sense. Right, if you use .preventDefault(), the mobile browser will not convert the mousedown into an additional touchstart and we can solve this by using pointerdown. I'll check if your pull request works for me and merge it if it does.