aboutsummaryrefslogtreecommitdiff
path: root/node_modules/fbjs/lib/containsNode.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/fbjs/lib/containsNode.js')
-rw-r--r--node_modules/fbjs/lib/containsNode.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/node_modules/fbjs/lib/containsNode.js b/node_modules/fbjs/lib/containsNode.js
new file mode 100644
index 000000000..ba30d1a73
--- /dev/null
+++ b/node_modules/fbjs/lib/containsNode.js
@@ -0,0 +1,39 @@
+'use strict';
+
+/**
+ * Copyright (c) 2013-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ *
+ *
+ */
+
+var isTextNode = require('./isTextNode');
+
+/*eslint-disable no-bitwise */
+
+/**
+ * Checks if a given DOM node contains or is another DOM node.
+ */
+function containsNode(outerNode, innerNode) {
+ if (!outerNode || !innerNode) {
+ return false;
+ } else if (outerNode === innerNode) {
+ return true;
+ } else if (isTextNode(outerNode)) {
+ return false;
+ } else if (isTextNode(innerNode)) {
+ return containsNode(outerNode, innerNode.parentNode);
+ } else if ('contains' in outerNode) {
+ return outerNode.contains(innerNode);
+ } else if (outerNode.compareDocumentPosition) {
+ return !!(outerNode.compareDocumentPosition(innerNode) & 16);
+ } else {
+ return false;
+ }
+}
+
+module.exports = containsNode; \ No newline at end of file