-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Conversation
When jQuery is included touches are found on event.originalEvent
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
the patch looks fine, but please
@mzgol can you double check that everything is fine? |
|
||
browserTrigger(element, 'touchstart'); | ||
browserTrigger(element, 'touchend'); | ||
expect($rootScope.event.originalEvent).toBeUndefined(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather you check here for $rootScope.event.{clientX,clientY}
as this is what's actually important here. This should still fail without the patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this test will pass even if only touchend
is patched. It'd be good to test them both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather you check here for $rootScope.event.{clientX,clientY} as this is what's actually important here.
This would be a false positive on browserTrigger(element, 'click')
, though (which you should test as well as it's patched, too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgalfaso We should most likely just create a Protractor test for such stuff, too much hacking must happen here to test anything.
@mzgol - sorry, I'm not following.
What exactly should I test in
Right, I couldn't find a way to unit-test the rest. I'll be happy to write a protractor test for this change. Should I put it in test/e2e/tests? |
I wrote it too fast. We run Protractor tests on Chrome, Firefox & Safari so touch events won't work there, we probably need to stay with just unit tests for now.
I've applied your test on How about you add those two |
I've updated tests and I actually had to include the same transformation to the |
@petebacondarwin I can take it. |
Magic! Thanks @mzgol |
@mzgol - like I said, I'll be happy to help to get it merged. |
@@ -238,6 +244,8 @@ ngTouch.directive('ngClick', ['$parse', '$timeout', '$rootElement', | |||
element.on('touchend', function(event) { | |||
var diff = Date.now() - startTime; | |||
|
|||
// Use JQuery originalEvent | |||
event = event.originalEvent || event; | |||
var touches = (event.changedTouches && event.changedTouches.length) ? event.changedTouches : | |||
((event.touches && event.touches.length) ? event.touches : [event]); | |||
var e = touches[0].originalEvent || touches[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: as far as I know, there's no "originalEvent" in touches[0]
- only in the event itself. This would allow you to reduce these two variables to:
var e = (event.changedTouches && event.changedTouches.length) ? event.changedTouches[0] :
((event.touches && event.touches.length) ? event.touches[0] : event;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - thanks for noticing it. I guess I'd just like to get it merged sooner rather than later, and then we can clean it up. Let's see what @mzgol says.
If jQuery was used with Angular the touch logic was looking for touches under the original event objects. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes #4001 Closes #8584 Closes #10797
I went in another direction as just assigning |
If jQuery was used with Angular the touch logic was looking for touches under the original event objects. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes #4001 Closes #8584 Closes #10797 Closes #11488
If jQuery was used with Angular the touch logic was looking for touches under the original event object. However, jQuery wraps all events, keeping the original one under the originalEvent property and copies/normalizes some of event properties. Not all properties are copied, e.g. touches which caused them to not be recognized properly. Thanks to @mcmar & @pomerantsev for original patch ideas. Fixes angular#4001 Closes angular#8584 Closes angular#10797 Closes angular#11488
This is an addition to PR #8584. The discussion is also there.