-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathevents.js
More file actions
62 lines (57 loc) · 1.57 KB
/
events.js
File metadata and controls
62 lines (57 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
59
60
61
62
import { documentRef } from "./window";
export const UPLOAD_EVENTS = ["load", "loadend", "loadstart"];
export const COMMON_EVENTS = ["progress", "abort", "error", "timeout"];
const depricatedProp = p =>
["returnValue", "totalSize", "position"].includes(p);
export const mergeObjects = function (src, dst) {
for (let k in src) {
if (depricatedProp(k)) {
continue;
}
const v = src[k];
try {
if (dst[k] !== v) {
Object.defineProperty(dst, k, { value: v });
}
} catch (error) {}
}
return dst;
};
//proxy events from one emitter to another
export const proxyEvents = function (events, src, dst) {
const p = event =>
function (e) {
const clone = {};
//copies event, with dst emitter inplace of src
for (let k in e) {
if (depricatedProp(k)) {
continue;
}
const val = e[k];
clone[k] = val === src ? dst : val;
}
//emits out the dst
return dst.dispatchEvent(event, clone);
};
//dont proxy manual events
for (let event of Array.from(events)) {
if (dst._has(event)) {
src[`on${event}`] = p(event);
}
}
};
//create fake event
export const fakeEvent = function (type) {
if (documentRef && documentRef.createEventObject != null) {
const msieEventObject = documentRef.createEventObject();
msieEventObject.type = type;
return msieEventObject;
}
// on some platforms like android 4.1.2 and safari on windows, it appears
// that new Event is not allowed
try {
return new Event(type);
} catch (error) {
return { type };
}
};