Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created November 18, 2011 23:44
Show Gist options
  • Save Raynos/1378123 to your computer and use it in GitHub Desktop.
Save Raynos/1378123 to your computer and use it in GitHub Desktop.
var adoptNode = (function () {
function setOwnerDocument(node, doc) {
// implement this. Step 1 of DOM4 adopt a node algorithm
node.triggerBaseUrlChange();
node._ownerDocument = doc;
node._attributes._ownerDocument = doc;
[].forEach.call(node.childNodes, function (node) {
setOwnerDocument(node, doc);
});
}
function adoptNode(node, doc) {
if (node.nodeType === Node.DOCUMENT_NODE) {
throw new core.DOMException(NOT_SUPPORTED_ERR, "Attempted to adopt a Document node into another node");
}
node.parentNode = null;
setOwnerDocument(node, doc);
}
return adoptNode;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment