-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
51 lines (48 loc) · 2.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!doctype html>
<title>Proximity Events</title>
<h1>Proximity Events</h1>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
height="120px">
<circle id="userprox" cx="50" cy="50" r="40" stroke="black" stroke-width="2"
fill="red"></circle>
<text id="userprox_text" y="110" style="stroke:none; fill:#000000; font-family: Arial;
font-size : 20;">near/far</text>
<circle id="deviceprox" cx="170" cy="50" r="40" stroke="white"
stroke-width="2" fill="black"></circle>
<text id="deviceprox_text" y="110" x="110" style="stroke:none; fill:#000000; font-family: Arial;
font-size : 20;">device proximity</text>
</svg>
<h2>Tests</h2>
<p>Remember that this is a polyfill, so some errors are expected as we can't fully implement native stuff in JavaScript.</p>
<div id="log"></div>
<script src="http://www.w3c-test.org/resources/testharness.js"></script>
<script src="DeviceProximityEvent.js"></script>
<script src="UserProximityEvent.js"></script>
<script src="DeviceProximityEvent_tests.js"></script>
<script src="UserProximityEvent_tests.js"></script>
<script>
(function setup() {
var userprox = document.querySelector('#userprox'),
deviceprox = document.querySelector('#deviceprox'),
userprox_text = document.querySelector('#userprox_text').firstChild,
deviceprox_text = document.querySelector('#deviceprox_text').firstChild;
window.addEventListener('userproximity', handleUserProx);
window.addEventListener('deviceproximity', handleDeviceProx);
function handleDeviceProx(e) {
if (e.value !== Infinity) {
deviceprox.setAttribute('r', String(e.value * 4));
deviceprox_text.data = 'Device proximity: ' + e.value;
}
}
function handleUserProx(e) {
var state = 'far',
color = 'red';
if (e.near) {
state = 'near';
color = 'green';
}
userprox.setAttribute('fill', color);
userprox_text.data = state;
}
})();
</script>