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 Test for Safari WebKit Force Touch Events #1613

Merged
merged 1 commit into from Nov 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions feature-detects/forcetouch.js
@@ -0,0 +1,29 @@
/*!
{
"name": "Force Touch Events",
"property": "forcetouch",
"authors": ["Kraig Walker"],
"notes": [{
"name": "Responding to Force Touch Events from JavaScript",
"href": "https://developer.apple.com/library/prerelease/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/RespondingtoForceTouchEventsfromJavaScript.html"
}]
}
!*/
/* DOC
Tests whether the browser supports the detection of Force Touch Events.
Force Touch Events allow custom behaviours and interactions to take place based on the given pressure or change in pressure from a compatible trackpad.

Force Touch events are available in OS X 10.11 and later on devices equipped with Force Touch trackpads.
*/
define(['Modernizr', 'hasEvent', 'prefixed'], function(Modernizr, hasEvent, prefixed) {
Modernizr.addTest('forcetouch', function() {
// github.com/Modernizr/Modernizr/issues/1613
// Test if the browser supports the force touch event progression (see notes link)
if (!hasEvent(prefixed('mouseforcewillbegin', window, false), window)) {
return false;
}

// Test if the browser provides thresholds defining a "force touch" from a normal touch/click event
return MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN && MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN;
});
});