forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
40 lines (35 loc) · 1.15 KB
/
utils.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
(function () {
Spark._labelFromIdOrName = function(n) {
var label = null;
if (n.nodeType === 1 /*ELEMENT_NODE*/) {
if (n.id) {
label = '#' + n.id;
} else if (n.getAttribute("name")) {
label = n.getAttribute("name");
// Radio button special case: radio buttons
// in a group all have the same name. Their value
// determines their identity.
// Checkboxes with the same name and different
// values are also sometimes used in apps, so
// we treat them similarly.
if (n.nodeName === 'INPUT' &&
(n.type === 'radio' || n.type === 'checkbox') &&
n.value)
label = label + ':' + n.value;
// include parent names and IDs up to enclosing ID
// in the label
while (n.parentNode &&
n.parentNode.nodeType === 1 /*ELEMENT_NODE*/) {
n = n.parentNode;
if (n.id) {
label = '#' + n.id + "/" + label;
break;
} else if (n.getAttribute('name')) {
label = n.getAttribute('name') + "/" + label;
}
}
}
}
return label;
};
})();