Copy the nodeContains module from static_upstream.
Ben Newman committed
Oct 1, 2013 at 19:17 UTC
e66287f92ea25c60ffc5f85a9431d91ec44c3d5f
2 files changed
+79
src/vendor/core/dom/isTextNode.js
new
+30
@@ -0,0 +1,30 @@
1
+/**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule isTextNode
17
+ * @typechecks
18
+ */
19
+
20
+var isNode = require('isNode');
21
+
22
+/**
23
+ * @param {*} object The object to check.
24
+ * @return {boolean} Whether or not the object is a DOM text node.
25
+ */
26
+function isTextNode(object) {
27
+ return isNode(object) && object.nodeType == 3;
28
+}
29
+
30
+module.exports = isTextNode;
src/vendor/core/dom/nodeContains.js
new
+49
@@ -0,0 +1,49 @@
1
+/**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule nodeContains
17
+ * @typechecks
18
+ */
19
+
20
+var isTextNode = require('isTextNode');
21
+
22
+/*jslint bitwise:true */
23
+
24
+/**
25
+ * Checks if a given DOM node contains or is another DOM node.
26
+ *
27
+ * @param {?DOMNode} outerNode Outer DOM node.
28
+ * @param {?DOMNode} innerNode Inner DOM node.
29
+ * @return {boolean} True if `outerNode` contains or is `innerNode`.
30
+ */
31
+function nodeContains(outerNode, innerNode) {
32
+ if (!outerNode || !innerNode) {
33
+ return false;
34
+ } else if (outerNode === innerNode) {
35
+ return true;
36
+ } else if (isTextNode(outerNode)) {
37
+ return false;
38
+ } else if (isTextNode(innerNode)) {
39
+ return nodeContains(outerNode, innerNode.parentNode);
40
+ } else if (outerNode.contains) {
41
+ return outerNode.contains(innerNode);
42
+ } else if (outerNode.compareDocumentPosition) {
43
+ return !!(outerNode.compareDocumentPosition(innerNode) & 16);
44
+ } else {
45
+ return false;
46
+ }
47
+}
48
+
49
+module.exports = nodeContains;