Skip to content

Commit

Permalink
Add test for Proximity Events
Browse files Browse the repository at this point in the history
  • Loading branch information
alrra committed Sep 24, 2014
1 parent f643942 commit 0af0953
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions feature-detects/proximity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*!
{
"authors": ["Cătălin Mariș"],
"caniuse": "proximity",
"name": "Proximity API",
"notes": [{
"name": "MDN documentation",
"href": "https://developer.mozilla.org/en-US/docs/Web/API/Proximity_Events"
},{
"name": "W3C specification",
"href": "http://www.w3.org/TR/proximity/"
}],
"property": "proximity",
"tags": ["events", "proximity"]
}
!*/
/* DOC
Detects support for an API that allows users to get proximity related information from the device's proximity sensor.
*/
define(['Modernizr', 'addTest'], function( Modernizr, addTest ) {

Modernizr.addAsyncTest(function () {

var timeout;
var timeoutTime = 300;

function advertiseSupport() {

// Clean up after ourselves
clearTimeout(timeout);
window.removeEventListener('deviceproximity', advertiseSupport);

// Advertise support as the browser supports
// the API and the device has a proximity sensor
addTest('proximity', true);

}

// Check if the browser has support for the API
if ( 'ondeviceproximity' in window && 'onuserproximity' in window ) {

// Check if the device has a proximity sensor
// ( devices without such a sensor support the events but
// will never fire them resulting in a false positive )
window.addEventListener('deviceproximity', advertiseSupport);

// If the event doesn't fire in a reasonable amount of time,
// it means that the device doesn't have a proximity sensor,
// thus, we can advertise the "lack" of support
timeout = setTimeout(function() {
window.removeEventListener('deviceproximity', advertiseSupport);
addTest('proximity', false);
}, timeoutTime);

} else {
addTest('proximity', false);
}

});

});
1 change: 1 addition & 0 deletions lib/config-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"test/pointerevents",
"test/pointerlock-api",
"test/postmessage",
"test/proximity",
"test/quota-management-api",
"test/requestanimationframe",
"test/script/async",
Expand Down
1 change: 1 addition & 0 deletions test/modular.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ <h1>Config JSON</h1>
"test/pointerevents",
"test/pointerlock-api",
"test/postmessage",
"test/proximity",
"test/quota-management-api",
"test/requestanimationframe",
"test/svg",
Expand Down

0 comments on commit 0af0953

Please sign in to comment.