This repository was archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathcapture.js
72 lines (70 loc) · 1.78 KB
/
capture.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import dispatcher from './dispatcher';
var n = window.navigator;
var s, r, h;
function assertActive(id) {
if (!dispatcher.pointermap.has(id)) {
var error = new Error('NotFoundError');
error.name = 'NotFoundError';
throw error;
}
}
function assertConnected(elem) {
var parent = elem.parentNode;
while (parent && parent !== elem.ownerDocument) {
parent = parent.parentNode;
}
if (!parent) {
var error = new Error('InvalidStateError');
error.name = 'InvalidStateError';
throw error;
}
}
function inActiveButtonState(id) {
var p = dispatcher.pointermap.get(id);
return p.buttons !== 0;
}
if (n.msPointerEnabled) {
s = function(pointerId) {
assertActive(pointerId);
assertConnected(this);
if (inActiveButtonState(pointerId)) {
dispatcher.setCapture(pointerId, this, true);
this.msSetPointerCapture(pointerId);
}
};
r = function(pointerId) {
assertActive(pointerId);
dispatcher.releaseCapture(pointerId, true);
this.msReleasePointerCapture(pointerId);
};
} else {
s = function setPointerCapture(pointerId) {
assertActive(pointerId);
assertConnected(this);
if (inActiveButtonState(pointerId)) {
dispatcher.setCapture(pointerId, this);
}
};
r = function releasePointerCapture(pointerId) {
assertActive(pointerId);
dispatcher.releaseCapture(pointerId);
};
}
h = function hasPointerCapture(pointerId) {
return !!dispatcher.captureInfo[pointerId];
};
export function applyPolyfill() {
if (window.Element && !window.Element.prototype.setPointerCapture) {
Object.defineProperties(window.Element.prototype, {
'setPointerCapture': {
value: s
},
'releasePointerCapture': {
value: r
},
'hasPointerCapture': {
value: h
}
});
}
}