Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/contains.js Secret
Last active Dec 11, 2015

Embed
What would you like to do?
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
}
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
You can’t perform that action at this time.