Commit 3cdcc2d6 authored by Julien Cigar's avatar Julien Cigar
Browse files

Fix document.importNode in IE9.

document.importNode exists in IE9 but fails. Just fails. It's not implemented, just says it's there and fails when called *sigh*.
parent fa6f48c0
......@@ -12,7 +12,7 @@
* "THE BEER-WARE LICENSE" (Revision 42):
* <julien.cigar@gmail.com> wrote this file. As long as you retain this notice
* you can do whatever you want with this stuff. If we meet some day, and you
* think this stuff is worth it, you can buy me a beer in return Julien Cigar.
* think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
......@@ -394,72 +394,76 @@
deep = true;
}
return document.importNode ?
document.importNode(node, deep) :
(function(node, deep) {
/* Returns an integer code representing the type of the node. */
var NodeTypes = {
ELEMENT_NODE : 1,
ATTRIBUTE_NODE : 2,
TEXT_NODE : 3,
CDATA_SECTION_NODE : 4,
ENTITY_REFERENCE_NODE : 5,
ENTITY_NODE : 6,
PROCESSING_INSTRUCTION_NODE : 7,
COMMENT_NODE : 8,
DOCUMENT_NODE : 9,
DOCUMENT_TYPE_NODE : 10,
DOCUMENT_FRAGMENT_NODE : 11,
NOTATION_NODE : 12
}
/* Note: document.importNode exists in IE9 but fails. Just fails. It's
* not implemented, just says it's there and fails when called.
*/
try {
return document.importNode(node, deep) :
} catch(e) {
return (function(node, deep) {
/* Returns an integer code representing the type of the node. */
var NodeTypes = {
ELEMENT_NODE : 1,
ATTRIBUTE_NODE : 2,
TEXT_NODE : 3,
CDATA_SECTION_NODE : 4,
ENTITY_REFERENCE_NODE : 5,
ENTITY_NODE : 6,
PROCESSING_INSTRUCTION_NODE : 7,
COMMENT_NODE : 8,
DOCUMENT_NODE : 9,
DOCUMENT_TYPE_NODE : 10,
DOCUMENT_FRAGMENT_NODE : 11,
NOTATION_NODE : 12
}
switch (node.nodeType) {
case NodeTypes.ELEMENT_NODE:
var newNode = document.createElement(node.nodeName);
if (node.attributes && node.attributes.length > 0) {
for (var i=0, _len=node.attributes.length ; i<_len ; i++) {
var attr_name = node.attributes[i].nodeName,
attr_value = node.getAttribute(attr_name)
;
if (attr_name.toLowerCase() == 'style') {
newNode.style.cssText = attr_value;
} else if (attr_name.toLowerCase() == 'class') {
newNode.className = attr_value;
} else if (attr_name.slice(0,2) == 'on') {
// FIXME: slow...
newNode[attr_name] = new Function(attr_value);
} else {
newNode.setAttribute(attr_name, attr_value);
switch (node.nodeType) {
case NodeTypes.ELEMENT_NODE:
var newNode = document.createElement(node.nodeName);
if (node.attributes && node.attributes.length > 0) {
for (var i=0, _len=node.attributes.length ; i<_len ; i++) {
var attr_name = node.attributes[i].nodeName,
attr_value = node.getAttribute(attr_name)
;
if (attr_name.toLowerCase() == 'style') {
newNode.style.cssText = attr_value;
} else if (attr_name.toLowerCase() == 'class') {
newNode.className = attr_value;
} else if (attr_name.slice(0,2) == 'on') {
// FIXME: slow...
newNode[attr_name] = new Function(attr_value);
} else {
newNode.setAttribute(attr_name, attr_value);
}
}
}
}
if (deep && node.childNodes && node.childNodes.length > 0) {
for (var i=0, _len=node.childNodes.length ; i<_len ; i++) {
newNode.appendChild(Yeti.DOM.importNode(node.childNodes[i], deep));
if (deep && node.childNodes && node.childNodes.length > 0) {
for (var i=0, _len=node.childNodes.length ; i<_len ; i++) {
newNode.appendChild(Yeti.DOM.importNode(node.childNodes[i], deep));
}
}
}
return newNode;
break;
return newNode;
break;
case NodeTypes.TEXT_NODE:
return document.createTextNode(node.nodeValue);
break;
case NodeTypes.TEXT_NODE:
return document.createTextNode(node.nodeValue);
break;
case NodeTypes.CDATA_SECTION_NODE:
return document.createCDATASection(node.nodeValue);
break;
case NodeTypes.CDATA_SECTION_NODE:
return document.createCDATASection(node.nodeValue);
break;
case NodeTypes.COMMENT_NODE:
return document.createComment(node.nodeValue);
break;
case NodeTypes.COMMENT_NODE:
return document.createComment(node.nodeValue);
break;
}
})(node, deep);
}
})(node, deep);
}
}
/* Yeti.DOM.firstElementChild
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment