soulwire / sketch.js

Cross-Platform JavaScript Creative Coding Framework
MIT License
4.09k stars 431 forks source link

preserve original event when eventTarget is used #97

Open nikrowell opened 7 years ago

nikrowell commented 7 years ago

Using document.body (or anything other than the default canvas) for eventTarget will hijack the original event. This change checks if the eventTarget is the canvas element before calling preventDefault(). I tried adding a test but getting Cannot simulate touch events - use examples to validate functinality in Chrome.

Easy to verify in the drawing example: with eventTarget: document.body, moves movements underneath the info panel continue painting and clicking "View on Github" follows the link.

akakoori commented 7 years ago

Good job, nikrowell! This's exactly what I'm looking for. preventDefault() makes using document.body for eventTarget actually meaningless.

There are cases where we want to preventDefault() or not judging by the eventType or the srcElement, better let developers to handle that rather than simply prevent all.