-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse.js
More file actions
58 lines (46 loc) · 1.57 KB
/
mouse.js
File metadata and controls
58 lines (46 loc) · 1.57 KB
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
52
53
54
55
56
57
58
/**
* Created by andres on 3/3/15.
*/
/**
* Created by andres on 3/3/15.
*/
(function() {
var series = [];
var data = {
start: new Date().getTime()
}
document.onmousemove = handleMouseMove;
function handleMouseMove(event) {
var dot, eventDoc, doc, body, pageX, pageY;
event = event || window.event; // IE-ism
// If pageX/Y aren't available and clientX/Y are,
// calculate pageX/Y - logic taken from jQuery.
// (This is to support old IE)
if (event.pageX == null && event.clientX != null) {
eventDoc = (event.target && event.target.ownerDocument) || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
event.pageX = event.clientX +
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
(doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY +
(doc && doc.scrollTop || body && body.scrollTop || 0) -
(doc && doc.clientTop || body && body.clientTop || 0 );
}
// Use event.pageX / event.pageY here
series.push({
t: new Date().getTime(),
x: event.pageX,
y: event.pageY
});
}
data.series = series;
document.body.addEventListener('keypress', handleKeyPress);
function handleKeyPress (evt) {
var k = evt ? evt.which : window.event.keyCode;
if (k == 32) {
data.end = new Date().getTime();
console.log(JSON.stringify(data));
}
}
})();