-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclosest.js
80 lines (79 loc) · 2 KB
/
closest.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
module.exports = {
name: "closest",
ns: "dom",
title: "Closest",
async: true,
description: " Finds the closest parent that matches a selector.",
expose: ["document"],
dependencies: {
npm: {
"discore-closest": require('discore-closest')
}
},
phrases: {
active: "Finding closest parent: {{input.selector}}"
},
ports: {
input: {
element: {
title: "Element",
description: "will check this elements parents",
type: "HTMLElement",
async: true,
fn: function __ELEMENT__(data, source, state, input, $, output, discore_closest) {
var r = function() {
var sel = discore_closest(
$.element, $.selector, $.checkSelf,
$.within || document
);
var res = {
element: $.get('element')
};
if (sel) {
res.selection = $.create(sel);
} else {
res.error = $.create(new Error('Selector didn\'t match:' + $.selector));
}
output(res);
}.call(this);
return {
state: state,
return: r
};
}
},
selector: {
title: "Selector",
description: "CSS selector to match parents",
type: "string"
},
checkSelf: {
title: "Check Self",
description: "check element. If falsey, will begin with element.parentNode and is synonymous to $.fn.parents. Otherwise, it's $.fn.closest.",
type: "boolean",
"default": false
},
within: {
title: "Within",
description: "check only within this element. By default, document",
type: "HTMLElement",
required: false
}
},
output: {
element: {
title: "Element",
type: "HTMLElement"
},
selection: {
title: "Selection",
type: "HTMLElement"
},
error: {
title: "Error",
type: "Error"
}
}
},
state: {}
}