Skip to content

Commit

Permalink
IE7 was importing <style> using the IE6 parser!! To fix this:
Browse files Browse the repository at this point in the history
1. in the decor document move <style> within body to head
2. when importing <style> into the page, set <style>.styleSheet.cssText only after <style> is inserted into the head (was using a document fragment)
  • Loading branch information
shogun70 committed Dec 9, 2011
1 parent 66faee1 commit 4ec43ba
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions source/lib/Meeko/HTMLDecor.js
Expand Up @@ -422,27 +422,29 @@ var copyAttributes = function(node, srcNode) { // implements srcNode.cloneNode(f
return node;
}

var importToFragment = document.importNode ?
function(srcNode, frag) {
frag.appendChild(document.importNode(srcNode, true));
return frag;
var importBefore = document.importNode ?
function(srcNode, marker) {
marker.parentNode.insertBefore(document.importNode(srcNode, true), marker);
} :
function(srcNode, frag) { // document.importNode() NOT available on IE < 9
function(srcNode, marker) { // document.importNode() NOT available on IE < 9
var tagName = srcNode.tagName.toLowerCase();
var node = document.createElement(tagName);
copyAttributes(node, srcNode);
frag.appendChild(node);
switch(tagName) {
case "title":
node.innerText = srcNode.innerHTML;
marker.parentNode.insertBefore(node, marker);
break;
case "style":
marker.parentNode.insertBefore(node, marker);
node.styleSheet.cssText = srcNode.styleSheet.cssText;
break;
case "script":
node.text = srcNode.text;
marker.parentNode.insertBefore(node, marker);
break;
default:
default: // meta, link have no content
marker.parentNode.insertBefore(node, marker);
break;
}
return node;
Expand Down Expand Up @@ -479,7 +481,12 @@ function fixHead() {

var marker = head.firstChild;
var wHead = decorDocument.head || firstChild(decorDocument.documentElement, "head");
var frag = document.createDocumentFragment();
if (isIE && IE_VER <= 7) {
var wBody = decorDocument.body;
forEach($$("style", wBody), function(wNode) {
wHead.appendChild(wNode);
});
}
for (var wNode=wHead.firstChild; wNode=wNode.nextSibling;) {
if (wNode.nodeType != 1) continue;
var tagName = wNode.tagName.toLowerCase();
Expand All @@ -498,9 +505,8 @@ function fixHead() {
case "script": // FIXME no duplicate @src
break;
}
importToFragment(wNode, frag);
importBefore(wNode, marker);
}
head.insertBefore(frag, marker);

// allow scripts to run
forEach($$("script", head), enableScript);
Expand Down

0 comments on commit 4ec43ba

Please sign in to comment.