-
Notifications
You must be signed in to change notification settings - Fork 46
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
Prevent click at end of drag #19
Comments
Thanks for your help @jlgrall |
I have forked the repo and added a fix here: https://github.com/AdvancedClimateSystems/snap.svg.zpd |
it seems this does not work in firefox, it returns timestamp not relative to epoch 0:0:0 UTC 1st January 1970. |
I added this code by @jlgrall to snap.svg.zpd library in m project. It works inChrome and IE, but did not work on my version of firefox 42.0. timeStamp value is different in firefox as I could see in console. |
Im editing my answer. I removed some of my code used for fixing this issue and used only fork code to test. I can confirm that fork does not work on Firefox due to different value of timeStamp, explained bellow, and in Chrome and IE 100 is too big interval, sometimes it does not catch click event. e.timeStamp - zpdElement.data.mouseupTime < 5 from @jlgrall and event.timeStamp - dragStartTime > 100 from @jaapz will not work because firefox returns this values for event.timeStamp and dragStartTime respectively: |
Yeah I found out my solution is not consistent at all across browsers. It's also just a dirty hack to look at time stamps IMO. I am looking into alternatives but have not found a better way yet... |
Also checking timestamps is not only inconsistent across browsers, it's also inconsistent across computers. My linux laptop running chrome behaves slightly different than my coworkers windows desktop using chrome. |
Using Date.now() inside clickHandler instead timeStamp will solve issue with firefox on my desktop. Agree this hack is not the most elegent way to do this, will try to come up with better option. Also condition (event.timeStamp - dragStartTime > 100) does not behave good, I used @jlgrall instructions to change code and it is more consistent, 100 is pretty large time offset, so it does not work sometimes. |
I don't know if you finally found a solution but since the issue is still opened I think it's a no. var flag = 0;
var element = xxxx;
element.addEventListener("mousedown", function(){
flag = 0;
}, false);
element.addEventListener("mousemove", function(){
flag = 1;
}, false);
element.addEventListener("mouseup", function(){
if(flag === 0){
console.log("click");
}
else if(flag === 1){
console.log("drag");
}
}, false); This solution launched the // outside of the handlers
var lastEvent = 0;
// in the mouseup handler
if (lastEvent === e.timeStamp) {return}
lastEvent = e.timeStamp perhaps using Undescore's isEqual or an equivalent can make the comparison cleaner |
Here is a quick workaround that should work in all browsers targeted by Snap.svg (IE 9+), though I cannot test it in IE. It is partly inspired by ThreeDubMedia's jquery.event.drag, which has a well though event code.
The text was updated successfully, but these errors were encountered: