pvdung / ourlibrary

Automatically exported from code.google.com/p/ourlibrary
0 stars 0 forks source link

importNode reverses the order of child nodes #38

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
fixed with change:

        importNode = function(node, bImportChildren, docNode) {
          var i, name, nodeNew, nodeChild, value,len;

          docNode = docNode || global.document;
          switch (node.nodeType) {
          case 1:
            nodeNew = createElement(getElementNodeName(node), docNode);
            if (nodeNew) {
              if (node.attributes && node.attributes.length) {
                i = node.attributes.length;
                while (i--) {
                  if (node.attributes[i].specified) {
                    name = node.attributes[i].nodeName;
                    value = getAttribute(node, node.attributes[i].nodeName);
                    if (value !== null) { nodeNew = setAttribute(nodeNew, name, value); }
                  }
                }
              }
              if (bImportChildren && node.childNodes && node.childNodes.length) {
                len = node.childNodes.length;
                for(i=0;i<len;++i)
                {
                  nodeChild = importNode(node.childNodes[i], bImportChildren, docNode);
                  if (nodeChild) {
                    if (nodeChild.nodeType != 1) {
                      if (elementCanHaveChildren(nodeNew) && (reNotEmpty.test(nodeChild.data) || getElementNodeName(nodeNew) == 'pre')) {
                        nodeNew.appendChild(nodeChild);
                      }
                      else {
                        if (getElementNodeName(nodeNew) == 'script' && typeof setElementScript == 'function') {
                          setElementScript(nodeNew, nodeChild.nodeValue);
                        }
                      }
                    }
                    else {
                      if (elementCanHaveChildren(nodeNew)) {
                        nodeNew.appendChild(nodeChild);
                      }
                    }
                  }
                }
              }
              return nodeNew;
            }
            break;
          case 3:
            return docNode.createTextNode(node.nodeValue);
          }
        };

Original issue reported on code.google.com by johnwloc...@gmail.com on 26 Apr 2011 at 9:43

GoogleCodeExporter commented 9 years ago

Original comment by dmark.ci...@gmail.com on 27 Apr 2011 at 5:39

GoogleCodeExporter commented 9 years ago

Original comment by dmark.ci...@gmail.com on 27 Apr 2011 at 5:39

GoogleCodeExporter commented 9 years ago

Original comment by dmark.ci...@gmail.com on 27 Apr 2011 at 5:40