Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Fix/jquery touch #10797

Closed
wants to merge 4 commits into from
Closed

Conversation

pomerantsev
Copy link
Contributor

This is an addition to PR #8584. The discussion is also there.

jasonals and others added 2 commits January 17, 2015 23:33
@googlebot
Copy link

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.

@lgalfaso
Copy link
Contributor

the patch looks fine, but please

  • it looks like the new tests only check 2 of the 3 changes
  • rebase this into a single commit
  • follow the commit message conventions

@mzgol can you double check that everything is fine?


browserTrigger(element, 'touchstart');
browserTrigger(element, 'touchend');
expect($rootScope.event.originalEvent).toBeUndefined();
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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).

Copy link
Member

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.

@pomerantsev
Copy link
Contributor Author

@mzgol - sorry, I'm not following.

This would be a false positive on browserTrigger(element, 'click'), though (which you should test as well as it's patched, too).

What exactly should I test in browserTrigger? You're absolutely right about the false positive - clientX and clientY are always there on the event object in tests.

BTW, this test will pass even if only touchend is patched. It'd be good to test them both.

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?

@mgol
Copy link
Member

mgol commented Jan 22, 2015

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.

This would be a false positive on browserTrigger(element, 'click'), though (which you should test as well as it's patched, too).

What exactly should I test in browserTrigger? You're absolutely right about the false positive - clientX and clientY are always there on the event object in tests.

I've applied your test on master and just changed it to check for clientX/clientY and the test failed as expected in jQuery tests (it didn't fail on jqLite as expected).

How about you add those two clientX/clientY checks without removing your originalEvent one and create a separate test for the click event where you only check for the missing originalEvent property?

@pomerantsev
Copy link
Contributor Author

I've updated tests and I actually had to include the same transformation to the click handler.
The failing test is most probably a flake - some WebDriver stuff.
I will squash / rebase commits if needed, but I feel slightly bad about squashing someone else's commits with mine.

@petebacondarwin petebacondarwin added this to the 1.4.x milestone Jan 24, 2015
@petebacondarwin petebacondarwin assigned lgalfaso and unassigned lgalfaso Jan 24, 2015
@petebacondarwin
Copy link
Member

@lgalfaso and @mzgol can you decide who should own this and then see if we can get it into 1.4.x?

@mgol
Copy link
Member

mgol commented Jan 24, 2015

@petebacondarwin I can take it.

@mgol mgol self-assigned this Jan 24, 2015
@petebacondarwin
Copy link
Member

Magic! Thanks @mzgol

@pomerantsev
Copy link
Contributor Author

@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];
Copy link
Contributor

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;

Copy link
Contributor Author

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.

mgol added a commit that referenced this pull request Mar 31, 2015
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
@mgol
Copy link
Member

mgol commented Mar 31, 2015

I went in another direction as just assigning $event.originalEvent to $event breaks the general assumption that $event is a jQuery/jqLite event object, not a native one. Please see #11471.

mgol added a commit to mgol/angular.js that referenced this pull request Mar 31, 2015
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
mgol added a commit to mgol/angular.js that referenced this pull request Mar 31, 2015
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
mgol added a commit to mgol/angular.js that referenced this pull request Mar 31, 2015
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
mgol added a commit to mgol/angular.js that referenced this pull request Mar 31, 2015
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
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Apr 2, 2015
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
@mgol mgol closed this in 06a9f0a Apr 2, 2015
mgol added a commit that referenced this pull request Apr 2, 2015
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
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants