mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Copy the nodeContains module from static_upstream.
This commit is contained in:
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright 2013 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule isTextNode
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
var isNode = require('isNode');
|
||||
|
||||
/**
|
||||
* @param {*} object The object to check.
|
||||
* @return {boolean} Whether or not the object is a DOM text node.
|
||||
*/
|
||||
function isTextNode(object) {
|
||||
return isNode(object) && object.nodeType == 3;
|
||||
}
|
||||
|
||||
module.exports = isTextNode;
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright 2013 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule nodeContains
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
var isTextNode = require('isTextNode');
|
||||
|
||||
/*jslint bitwise:true */
|
||||
|
||||
/**
|
||||
* Checks if a given DOM node contains or is another DOM node.
|
||||
*
|
||||
* @param {?DOMNode} outerNode Outer DOM node.
|
||||
* @param {?DOMNode} innerNode Inner DOM node.
|
||||
* @return {boolean} True if `outerNode` contains or is `innerNode`.
|
||||
*/
|
||||
function nodeContains(outerNode, innerNode) {
|
||||
if (!outerNode || !innerNode) {
|
||||
return false;
|
||||
} else if (outerNode === innerNode) {
|
||||
return true;
|
||||
} else if (isTextNode(outerNode)) {
|
||||
return false;
|
||||
} else if (isTextNode(innerNode)) {
|
||||
return nodeContains(outerNode, innerNode.parentNode);
|
||||
} else if (outerNode.contains) {
|
||||
return outerNode.contains(innerNode);
|
||||
} else if (outerNode.compareDocumentPosition) {
|
||||
return !!(outerNode.compareDocumentPosition(innerNode) & 16);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = nodeContains;
|
||||
Reference in New Issue
Block a user