diff options
author | Brion Vibber <brion@pobox.com> | 2010-12-22 15:20:07 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-12-22 15:22:02 -0800 |
commit | e0606d3eca761bda5fb804f6522028280d3396e8 (patch) | |
tree | 6a25c7d9b7f5419b0d4103d64101a7d2eccfe1de /js/xbImportNode.js | |
parent | 8babcc2ad21f70745ce261476ffe74b42603419a (diff) |
Break xbImportNode.js and geometa.js back out of util.js; the Makefile in js has been updated to combine them with util.js source when building util.min.js0.9.x
Revert "combine our standard scripts into one big script"
This reverts parts of commit 0c5ca46ba3a070803d993b0244fcc69d33875ebd.
Diffstat (limited to 'js/xbImportNode.js')
-rw-r--r-- | js/xbImportNode.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/js/xbImportNode.js b/js/xbImportNode.js new file mode 100644 index 000000000..f600a4789 --- /dev/null +++ b/js/xbImportNode.js @@ -0,0 +1,47 @@ +/* is this stuff defined? */ +if (!document.ELEMENT_NODE) { + document.ELEMENT_NODE = 1; + document.ATTRIBUTE_NODE = 2; + document.TEXT_NODE = 3; + document.CDATA_SECTION_NODE = 4; + document.ENTITY_REFERENCE_NODE = 5; + document.ENTITY_NODE = 6; + document.PROCESSING_INSTRUCTION_NODE = 7; + document.COMMENT_NODE = 8; + document.DOCUMENT_NODE = 9; + document.DOCUMENT_TYPE_NODE = 10; + document.DOCUMENT_FRAGMENT_NODE = 11; + document.NOTATION_NODE = 12; +} + +document._importNode = function(node, allChildren) { + /* find the node type to import */ + switch (node.nodeType) { + case document.ELEMENT_NODE: + /* create a new element */ + var newNode = document.createElement(node.nodeName); + /* does the node have any attributes to add? */ + if (node.attributes && node.attributes.length > 0) + /* add all of the attributes */ + for (var i = 0, il = node.attributes.length; i < il;) { + if (node.attributes[i].nodeName == 'class') { + newNode.className = node.getAttribute(node.attributes[i++].nodeName); + } else { + newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName)); + } + } + /* are we going after children too, and does the node have any? */ + if (allChildren && node.childNodes && node.childNodes.length > 0) + /* recursively get all of the child nodes */ + for (var i = 0, il = node.childNodes.length; i < il;) + newNode.appendChild(document._importNode(node.childNodes[i++], allChildren)); + return newNode; + break; + case document.TEXT_NODE: + case document.CDATA_SECTION_NODE: + case document.COMMENT_NODE: + return document.createTextNode(node.nodeValue); + break; + } +}; + |