Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from MSOpenTech/fixExtraTags
Browse files Browse the repository at this point in the history
Fix #8
  • Loading branch information
xirzec committed Jan 24, 2015
2 parents 61e0064 + 5c0039a commit 1c23c04
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions winstore-jscompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
return isUnsafe;
}

function cleanse(html) {
function cleanse(html, targetElement) {
var cleaner = document.implementation.createHTMLDocument("cleaner");
empty(cleaner.documentElement);
MSApp.execUnsafeLocalFunction(function () {
Expand Down Expand Up @@ -120,7 +120,20 @@
}
cleanseAttributes(cleaner.documentElement);

return Array.prototype.slice.call(document.adoptNode(cleaner.documentElement).childNodes);
var cleanedNodes = [];

if (targetElement.tagName === 'HTML') {
cleanedNodes = Array.prototype.slice.call(document.adoptNode(cleaner.documentElement).childNodes);
} else {
if (cleaner.head) {
cleanedNodes = cleanedNodes.concat(Array.prototype.slice.call(document.adoptNode(cleaner.head).childNodes));
}
if (cleaner.body) {
cleanedNodes = cleanedNodes.concat(Array.prototype.slice.call(document.adoptNode(cleaner.body).childNodes));
}
}

return cleanedNodes;
}

function cleansePropertySetter(property, setter) {
Expand All @@ -133,7 +146,7 @@
originalSetter.call(this, value);
} else {
var that = this;
var nodes = cleanse(value);
var nodes = cleanse(value, that);
MSApp.execUnsafeLocalFunction(function () {
setter(propertyDescriptor, that, nodes);
});
Expand Down

0 comments on commit 1c23c04

Please sign in to comment.