Add Test for Safari WebKit Force Touch Events #1613

Merged
merged 1 commit into from Nov 27, 2015

Projects

None yet

4 participants

@KraigWalker
Contributor

Will test if the currently defined flow of webkitmouseforce events from Apple is supported by the browser, and if the browser provides the WEBKIT_FORCE_AT_MOUSE_DOWN and WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN constants on the MouseEvent object.

https://developer.apple.com/library/prerelease/mac/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/RespondingtoForceTouchEventsfromJavaScript.html#//apple_ref/doc/uid/TP40016162-SW1

@modernizr-savage

Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED

Commit: 116035a
Build details: https://travis-ci.org/modernizr-savage/Modernizr/builds/71570544

(Please note that this is a fully automated comment.)

@modernizr-savage

Tests passed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: CONFIRMED

Commit: 4cd0df2
Build details: https://travis-ci.org/modernizr-savage/Modernizr/builds/71571124

(Please note that this is a fully automated comment.)

@KraigWalker
Contributor

See #1606

@ryanseddon ryanseddon commented on an outdated diff Aug 2, 2015
feature-detects/forcetouch.js
+ "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'], function(Modernizr, hasEvent) {
+ Modernizr.addTest('forcetouch', function() {
+
+ // Test if the browser supports the force touch event progression (see notes link)
+ if (!hasEvent('webkitmouseforcewillbegin', window) &&
@ryanseddon
ryanseddon Aug 2, 2015 Member

We should probably generate these event names via Modernizr.prefixed so in the case they become unprefixed.

@KraigWalker
Contributor

@ryanseddon thanks for looking into that. I'll be adding a revision over this with Modernizr.prefixed today.

@KraigWalker
Contributor

Updated to use Modernizr.prefixed

@patrickkettner
Member

@KraigWalker looks like you have committed with git's markers in it still. Wanna clean it up and squash it down to a single commit?

@patrickkettner
Member
@KraigWalker
Contributor

+1 #cantbelieveijustleftthiswhatwasithinking sorry! 😓

@patrickkettner
Member

sorry, where you going to be able to update?

cheers!

@KraigWalker
Contributor

Hey, Patrick. Most likely tonight. Going to dedicate some time to fix my broken PR (it seems to exist across two branches, which really isn't nice)

Sent from my iPhone

On 9 Nov 2015, at 17:10, patrick kettner notifications@github.com wrote:

sorry, where you going to be able to update?

cheers!


Reply to this email directly or view it on GitHub.

@patrickkettner
Member
@KraigWalker
Contributor

That's it sorted now.

@patrickkettner patrickkettner commented on an outdated diff Nov 16, 2015
feature-detects/forcetouch.js
+ 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) &&
+ !hasEvent(prefixed('mouseforcedown', window, false), window) &&
+ !hasEvent(prefixed('mouseforceup', window, false), window) &&
+ !hasEvent(prefixed('mouseforcechanged', window, false), window)) {
+ return false;
+ }
+
+ // Test if the browser provides thresholds defining a "force touch" from a normal touch/click event
+ if (MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN && MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN) {
+ return true;
+ } else {
+ return false;
+ }
@patrickkettner
patrickkettner Nov 16, 2015 Member

this should just be return MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN && MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN

@patrickkettner patrickkettner commented on an outdated diff Nov 16, 2015
feature-detects/forcetouch.js
+ "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) &&
@patrickkettner
patrickkettner Nov 16, 2015 Member

keying off of one of these events is fine. Its extremely unlikely to have a situation where mouseforcewillbegin exists but the others do not. Removign the others saves a fair amount of bits

@patrickkettner
Member

sorry, couple more nits then we will be all good and merged

@KraigWalker
Contributor

No problem. Thanks for reviewing it.

On 16 Nov 2015, at 22:55, patrick kettner notifications@github.com wrote:

sorry, couple more nits then we will be all good and merged


Reply to this email directly or view it on GitHub.

@KraigWalker KraigWalker Add Feature Detect for Force Touch (AKA 3d Touch)
Adds a feature detect for mouse force related events, and whether force values can
be read from the MouseEvent object.
93ceb13
@patrickkettner patrickkettner merged commit 9743105 into Modernizr:master Nov 27, 2015

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@patrickkettner
Member

cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment