mobomo/sketch.js

touchTargets undefined on touchend/touchleave

Opened this issue · 2 comments

When drawing on a canvas on a mobile device, there is an error "Uncaught TypeError: Cannot read property 'pageX' of undefined" on the touchend/touchleave bound to the canvas. The script is trying to call "e.originalEvent.targetTouches[0].pageX;", but it appears that on the touchend/touchleave event, "e.originalEvent.targetTouches[0]" is not defined, causing an error and resetting the entire canvas on mobile. You can simply encase the .pageX and .pageY lines in an if statement checking if both .targetTouches[0] and .targetTouche[0].pageX are defined. See any below:

http://stackoverflow.com/questions/21311073/sketch-js-pagex-undefined-error/22976319#22976319

This fix worked for me...