-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Click-event Handling #38
Comments
Do these changes still allow the user to accidentally exit the and come back in without cancelling their signature? |
It sure does. As long as it's within 0.5 seconds, the mouseLeaveTimeout limit. It doesn't actually stop mousemove from working, it adds to it. Now it will 'stop' and 'start' a new line on mouseleave/mousemove, instead of always drawing connect-the-dots like in problem 2... even when off-canvas. And I almost forgot, here's the added signaturePad.css lines...
|
You know what, I don't think I made the logic of those changes really clear. Let me try again. signaturePad is a game of connect-the-dots.
|
Ah, thank you! That explanation was very clear. |
There are some minor issues with signature-pad's click events, and what happens when the mouse goes outside the canvas.
The first three scenarios only apply if you don't linger outside, because mouseLeaveTimeout ends any drawing when triggered.
A bit of extra coding solve both these problems. Namely:
A. Add an optional parameter (e) to stopDrawing that draws one last dot (at the event mouse cursor location) before stopping the draw.
B. mouseleave always calls stopDrawing(e) to send the last known mouse position
[These 2 changes solve problem 1]
C. If stopDrawing is passed an event from mouseleave, don't unbind the mousemove events like normal
D. mousemove detects if the drawing was stopped, and if so, begins a new line
[These 2 changes solve problem 2]
E. Use $(document) instead of canvas for all mouseup event bindings.
F. Create private boolean variable mouseButtonDown that is set to 'true' by mousedown events and 'false' by mouseup/mousedowntimeout events.
G. Mouseup events won't run code unless mouseButtonDown is true.
[These 3 changes solve problem 3]
H. Add a 'noselect' class to signaturepad.css that disables text selection.
I. Add/remove the 'noselect' class on body whereever mouseButtonDown is set to true/false.
[These 2 changes solve problem 4]
Now that you know the "why", here's the actual code...
Notice the added e variable in this block. e is only passed by mouseleave, so this can draw a point at the last known mouse location and leave bindings alone.
I've added this above startDrawing though it doesn't really matter where.
Changed callbacks from drawLine to onMouseMove.
Time to update more mouseup/down/leave bindings.
But I only wrote this today and this really needs more (multi-browser) testing. Hope this helps!
The text was updated successfully, but these errors were encountered: