-
Notifications
You must be signed in to change notification settings - Fork 0
/
addPointerEvent.js
100 lines (98 loc) · 2.27 KB
/
addPointerEvent.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module.exports = {
name: "addPointerEvent",
ns: "dom",
description: "Add Pointer Event Listener",
async: true,
phrases: {
active: "Adding {{input.event}} handler"
},
ports: {
input: {
"in": {
title: "Input",
type: "any",
async: true,
"default": null,
fn: function __IN__(data, source, state, input, $, output) {
var r = function() {
state.in = $.in;
}.call(this);
return {
state: state,
return: r
};
}
},
element: {
type: "HTMLElement",
title: "Dom Element",
async: true,
fn: function __ELEMENT__(data, source, state, input, $, output) {
var r = function() {
if (state.in === undefined) return false;
if (state.el) {
state.el.removeEventListener(state.event);
}
state.el = $.element;
state.event = $.event;
state.preventDefault = $.preventDefault;
state.el.addEventListener($.event, state.clickHandler, false);
output({
element: $.get('element')
});
}.call(this);
return {
state: state,
return: r
};
}
},
preventDefault: {
type: "boolean",
title: "Prevent Default Event",
"default": true
},
event: {
type: "string",
"enum": ["pointerdown",
"pointerup",
"pointercancel",
"pointermove",
"pointerover",
"pointerout",
"pointerenter",
"pointerleave",
"gotpointercapture",
"lostpointercapture"
],
title: "Pointer Event"
}
},
output: {
element: {
type: "HTMLElement",
title: "Dom Element"
},
out: {
type: "any",
title: "Output"
},
event: {
type: "PointerEvent",
title: "Event"
}
}
},
state: {
"in": undefined,
event: null,
preventDefault: null,
clickHandler: function(ev) {
if (state.preventDefault) ev.preventDefault();
output({
out: $.clone('in', state.in),
event: $.create(ev)
});
}
}
}