-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpointer.js
More file actions
42 lines (42 loc) · 1.21 KB
/
Copy pathpointer.js
File metadata and controls
42 lines (42 loc) · 1.21 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
"use strict";
/// <reference path="roads.d.ts" />
var pointer = {
dragging: false,
x: 0,
y: 0,
};
function setPointerPosition(event) {
pointer.x = (event.clientX - container.offsetLeft) * cscale;
pointer.y = (event.clientY - container.offsetTop) * cscale;
}
addEventListener('mousedown', function (event) {
event.preventDefault();
pointer.dragging = true;
setPointerPosition(event);
});
addEventListener('mousemove', function (event) {
event.preventDefault();
setPointerPosition(event);
});
addEventListener('mouseup', function (event) {
event.preventDefault();
pointer.dragging = false;
});
document.addEventListener('touchstart', function (event) {
var target = event.target;
if (target.tagName != 'INPUT' && target.tagName != 'LABEL') {
event.preventDefault();
}
pointer.dragging = true;
setPointerPosition(event.targetTouches[0]);
});
document.addEventListener('touchmove', function (event) {
event.preventDefault();
setPointerPosition(event.targetTouches[0]);
});
document.addEventListener('touchend', function (event) {
pointer.dragging = false;
});
document.addEventListener('touchcancel', function (event) {
pointer.dragging = false;
});