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

Update to remove generate of double body tags #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 14 additions & 8 deletions winstore-jscompat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// JavaScript Dynamic Content shim for Windows Store apps
(function () {

Expand Down Expand Up @@ -44,7 +44,7 @@
function insertAdjacentHTML(element, position, html) {
HTMLElement_insertAdjacentHTMLPropertyDescriptor.value.call(element, position, html);
}

function inUnsafeMode() {
var isUnsafe = true;
try {
Expand All @@ -53,7 +53,7 @@
catch (ex) {
isUnsafe = false;
}

return isUnsafe;
}

Expand Down Expand Up @@ -129,7 +129,7 @@
Object.defineProperty(HTMLElement.prototype, property, {
get: propertyDescriptor.get,
set: function (value) {
if(window.WinJS && window.WinJS._execUnsafe && inUnsafeMode()) {
if (window.WinJS && window.WinJS._execUnsafe && inUnsafeMode()) {
originalSetter.call(this, value);
} else {
var that = this;
Expand All @@ -146,7 +146,15 @@
cleansePropertySetter("innerHTML", function (propertyDescriptor, target, elements) {
empty(target);
for (var i = 0, len = elements.length; i < len; i++) {
target.appendChild(elements[i]);
var current = elements[i];
// Fix for double head / body tags in the document.
if (current.tagName === 'HEAD' || current.tagName === 'BODY') {
for (var j = 0; j < current.childNodes.length; j++) {
target.appendChild(current.childNodes[j]);
}
} else {
target.appendChild(current);
}
}
});
cleansePropertySetter("outerHTML", function (propertyDescriptor, target, elements) {
Expand All @@ -155,7 +163,5 @@
}
target.parentNode.removeChild(target);
});

}

}());
}());