]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/xbImportNode.js
no notice form on invites
[quix0rs-gnu-social.git] / js / xbImportNode.js
1 /* is this stuff defined? */
2 if (!document.ELEMENT_NODE) {
3         document.ELEMENT_NODE = 1;
4         document.ATTRIBUTE_NODE = 2;
5         document.TEXT_NODE = 3;
6         document.CDATA_SECTION_NODE = 4;
7         document.ENTITY_REFERENCE_NODE = 5;
8         document.ENTITY_NODE = 6;
9         document.PROCESSING_INSTRUCTION_NODE = 7;
10         document.COMMENT_NODE = 8;
11         document.DOCUMENT_NODE = 9;
12         document.DOCUMENT_TYPE_NODE = 10;
13         document.DOCUMENT_FRAGMENT_NODE = 11;
14         document.NOTATION_NODE = 12;
15 }
16
17 document._importNode = function(node, allChildren) {
18         /* find the node type to import */
19         switch (node.nodeType) {
20                 case document.ELEMENT_NODE:
21                         /* create a new element */
22                         var newNode = document.createElement(node.nodeName);
23                         /* does the node have any attributes to add? */
24                         if (node.attributes && node.attributes.length > 0)
25                                 /* add all of the attributes */
26                                 for (var i = 0, il = node.attributes.length; i < il;) {
27                                         if (node.attributes[i].nodeName == 'class') {
28                                                 newNode.className = node.getAttribute(node.attributes[i++].nodeName);
29                                         } else {
30                                                 newNode.setAttribute(node.attributes[i].nodeName, node.getAttribute(node.attributes[i++].nodeName));
31                                         }
32                                 }
33                         /* are we going after children too, and does the node have any? */
34                         if (allChildren && node.childNodes && node.childNodes.length > 0)
35                                 /* recursively get all of the child nodes */
36                                 for (var i = 0, il = node.childNodes.length; i < il;)
37                                         newNode.appendChild(document._importNode(node.childNodes[i++], allChildren));
38                         return newNode;
39                         break;
40                 case document.TEXT_NODE:
41                 case document.CDATA_SECTION_NODE:
42                 case document.COMMENT_NODE:
43                         return document.createTextNode(node.nodeValue);
44                         break;
45         }
46 };
47