Skip to content
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

Add suport for unprefixed pointer events #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion faketouches.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
this.touches = [];
this.touch_type = FakeTouches.TOUCH_EVENTS;
this.has_multitouch = true;
this.use_prefixed_pointer_event_names = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better just to figure this out. Something like 'pointerdown' in document.body?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a valid approach (if it works), but for my use case I needed to run a test against both cases, with and without prefixes. The configuration option was the easiest way to do so. Just a thought:

this.use_prefixed_pointer_event_names = 'onpointerdown' in document.body;

That way, it could still be overridden.

Another though: Modernizr has a very rigorous check for supported events: https://github.com/Modernizr/Modernizr/blob/master/src/hasEvent.js

Might be worthwhile to include modernizr for feature detection. I have a gut feeling that this eventName in document.body pattern yields a lot of false-negatives.

PS: sry for following up on this only now.

}

FakeTouches.POINTER_TOUCH_EVENTS = 100;
Expand Down Expand Up @@ -216,10 +217,14 @@
*/
function triggerPointerEvents(type, pointerType) {
var self = this;
var names = {
var names = self.use_prefixed_pointer_event_names ? {
start: 'MSPointerDown',
move: 'MSPointerMove',
end: 'MSPointerUp'
} : {
start: 'pointerdown',
move: 'pointermove',
end: 'pointerup'
};

var touchList = this._createTouchList(this.touches);
Expand Down
51 changes: 27 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
{
"name":"faketouches",
"title":"faketouches.js",
"description":"Fake touch events for testing",
"version":"0.0.4",
"licenses": [{
"type": "MIT",
"url": "https://github.com/jtangelder/faketouches.js/blob/master/LICENSE"
}],

"keywords":["touch","simulate","test"],
"author": {
"name": "Jorik Tangelder",
"email": "[email protected]"
},

"repository": {
"type": "git",
"url": "git://github.com/jtangelder/faketouches.js.git"
},
"bugs": {
"url": "https://github.com/jtangelder/faketouches.js/issues"
},
"devDependencies":{
"name": "faketouches",
"title": "faketouches.js",
"description": "Fake touch events for testing",
"version": "0.1.0",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/jtangelder/faketouches.js/blob/master/LICENSE"
}
}
],
"keywords": [
"touch",
"simulate",
"test"
],
"author": {
"name": "Jorik Tangelder",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "git://github.com/jtangelder/faketouches.js.git"
},
"bugs": {
"url": "https://github.com/jtangelder/faketouches.js/issues"
},
"devDependencies": {}
}