This repository was archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathdom.js
More file actions
60 lines (52 loc) · 1.61 KB
/
dom.js
File metadata and controls
60 lines (52 loc) · 1.61 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
// Copyright 2013 Google Inc. All Rights Reserved.
/**
* @fileoverview Functions that help jsaction interact with the DOM. We
* deliberately don't use the closure equivalents here because we want
* to exercise very tight control over the dependencies.
*/
goog.provide('jsaction.dom');
/**
* Determines if one node is contained within another. Adapted from
* {@see goog.dom.contains}.
* @param {!Node} node Node that should contain otherNode.
* @param {Node} otherNode Node being contained.
* @return {boolean} True if otherNode is contained within node.
*/
jsaction.dom.contains = function(node, otherNode) {
if (otherNode === null) {
return false;
}
// We use browser specific methods for this if available since it is faster
// that way.
// IE DOM
if ('contains' in node && otherNode.nodeType == 1) {
return node.contains(otherNode);
}
// W3C DOM Level 3
if ('compareDocumentPosition' in node) {
return node == otherNode ||
Boolean(node.compareDocumentPosition(otherNode) & 16);
}
// W3C DOM Level 1
while (otherNode && node != otherNode) {
otherNode = otherNode.parentNode;
}
return otherNode == node;
};
/**
* Helper method for broadcastCustomEvent. Returns true if any member of
* the set is an ancestor of element.
*
* @param {!Element} element
* @param {!NodeList} nodeList
* @return {boolean}
*/
jsaction.dom.hasAncestorInNodeList = function(element, nodeList) {
for (let idx = 0; idx < nodeList.length; ++idx) {
const member = nodeList[idx];
if (member != element && jsaction.dom.contains(member, element)) {
return true;
}
}
return false;
};