-
-
Save Raynos/f1eeacdaf1adb4107840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DOCUMENT_POSITION_CONTAINED_BY = 16 | |
module.exports = contains | |
function contains(container, elem) { | |
if (container.contains) { | |
return container.contains(elem) | |
} | |
var comparison = container.compareDocumentPosition(elem) | |
return comparison === 0 || comparison & DOCUMENT_POSITION_CONTAINED_BY | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var contains = require("./contains") | |
var parents = require("ancestors") | |
var slice = Array.prototype.slice | |
module.exports = getCommonAncestor | |
function getCommonAncestor(node) { | |
if (arguments.length < 2) { | |
return node | |
} | |
var nodes = slice.call(arguments, 1) | |
return parents(node).filter(function (parent) { | |
return nodes.every(function (node) { | |
return contains(parent, node) | |
}) | |
})[0] || null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment