-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathNodeList.java
More file actions
46 lines (39 loc) · 1.03 KB
/
NodeList.java
File metadata and controls
46 lines (39 loc) · 1.03 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
package snap.webapi;
/**
* This class is a wrapper for Web API NodeList (https://developer.mozilla.org/en-US/docs/Web/API/NodeList).
*/
public class NodeList extends JSProxy {
/**
* Constructor.
*/
public NodeList(Object jsObj)
{
super(jsObj);
}
/**
* The length of the array.
*/
public int getLength() { return getMemberInt("length"); }
/**
* Returns the array of nodes.
*/
public Node[] getItems()
{
return getNodeArrayForNodeList(_jsObj);
}
/**
* Returns an array of nodes for given NodeList.
*/
public static Node[] getNodeArrayForNodeList(Object nodeList)
{
int length = WebEnv.get().getMemberInt(nodeList, "length");
// Convert to Node array
Node[] nodeArray = new Node[length];
for (int i = 0; i < length; i++) {
Object nodeJS = WebEnv.get().call(nodeList, "item", i);
nodeArray[i] = Node.getNodeForNodeJS(nodeJS);
}
// Return
return nodeArray;
}
}