From f9eaad86e4fb742bb834290764e5aa390673aeee Mon Sep 17 00:00:00 2001 From: Guillaume ZAHRA Date: Thu, 8 Nov 2018 21:29:20 +0100 Subject: [PATCH] - Support of Blazor server side on Internet Explorer 11 --- .../package-lock.json | 2 +- src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts | 4 +- .../src/template.js | 600 ++++++++++++++++++ 3 files changed, 604 insertions(+), 2 deletions(-) create mode 100644 src/Daddoon.Blazor.Polyfill.JS/src/template.js diff --git a/src/Daddoon.Blazor.Polyfill.JS/package-lock.json b/src/Daddoon.Blazor.Polyfill.JS/package-lock.json index f332bb3..08e7619 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/package-lock.json +++ b/src/Daddoon.Blazor.Polyfill.JS/package-lock.json @@ -2653,7 +2653,7 @@ }, "whatwg-fetch": { "version": "2.0.4", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "resolved": "http://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" }, "which": { diff --git a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts index 66801a8..e243cab 100644 --- a/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts +++ b/src/Daddoon.Blazor.Polyfill.JS/src/Boot.ts @@ -1,4 +1,4 @@ -/* BLAZOR.POLYFILL Version 0.2.0 */ +/* BLAZOR.POLYFILL Version 0.3.0 */ /** IE9, IE10 and IE11 requires all of the following polyfills. **/ import 'core-js/es6/symbol'; @@ -16,7 +16,9 @@ import 'core-js/es6/map'; import 'core-js/es6/weak-map'; import 'core-js/es6/set'; import 'core-js/es6/promise' +import 'core-js/es6/typed' import 'whatwg-fetch'; +import '../src/template.js' declare var Symbol; declare var document; diff --git a/src/Daddoon.Blazor.Polyfill.JS/src/template.js b/src/Daddoon.Blazor.Polyfill.JS/src/template.js new file mode 100644 index 0000000..a6c4381 --- /dev/null +++ b/src/Daddoon.Blazor.Polyfill.JS/src/template.js @@ -0,0 +1,600 @@ +/** + * @license + * Copyright (c) 2016 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt + * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt + * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt + * Code distributed by Google as part of the polymer project is also + * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt + */ + +// minimal template polyfill +(function() { + 'use strict'; + + var needsTemplate = (typeof HTMLTemplateElement === 'undefined'); + var brokenDocFragment = !(document.createDocumentFragment().cloneNode() instanceof DocumentFragment); + var needsDocFrag = false; + + // NOTE: Replace DocumentFragment to work around IE11 bug that + // causes children of a document fragment modified while + // there is a mutation observer to not have a parentNode, or + // have a broken parentNode (!?!) + if (/Trident/.test(navigator.userAgent)) { + (function() { + + needsDocFrag = true; + + var origCloneNode = Node.prototype.cloneNode; + Node.prototype.cloneNode = function cloneNode(deep) { + var newDom = origCloneNode.call(this, deep); + if (this instanceof DocumentFragment) { + newDom.__proto__ = DocumentFragment.prototype; + } + return newDom; + }; + + // IE's DocumentFragment querySelector code doesn't work when + // called on an element instance + DocumentFragment.prototype.querySelectorAll = HTMLElement.prototype.querySelectorAll; + DocumentFragment.prototype.querySelector = HTMLElement.prototype.querySelector; + + Object.defineProperties(DocumentFragment.prototype, { + 'nodeType': { + get: function () { + return Node.DOCUMENT_FRAGMENT_NODE; + }, + configurable: true + }, + + 'localName': { + get: function () { + return undefined; + }, + configurable: true + }, + + 'nodeName': { + get: function () { + return '#document-fragment'; + }, + configurable: true + } + }); + + var origInsertBefore = Node.prototype.insertBefore; + function insertBefore(newNode, refNode) { + if (newNode instanceof DocumentFragment) { + var child; + while ((child = newNode.firstChild)) { + origInsertBefore.call(this, child, refNode); + } + } else { + origInsertBefore.call(this, newNode, refNode); + } + return newNode; + } + Node.prototype.insertBefore = insertBefore; + + var origAppendChild = Node.prototype.appendChild; + Node.prototype.appendChild = function appendChild(child) { + if (child instanceof DocumentFragment) { + insertBefore.call(this, child, null); + } else { + origAppendChild.call(this, child); + } + return child; + }; + + var origRemoveChild = Node.prototype.removeChild; + var origReplaceChild = Node.prototype.replaceChild; + Node.prototype.replaceChild = function replaceChild(newChild, oldChild) { + if (newChild instanceof DocumentFragment) { + insertBefore.call(this, newChild, oldChild); + origRemoveChild.call(this, oldChild); + } else { + origReplaceChild.call(this, newChild, oldChild); + } + return oldChild; + }; + + Document.prototype.createDocumentFragment = function createDocumentFragment() { + var frag = this.createElement('df'); + frag.__proto__ = DocumentFragment.prototype; + return frag; + }; + + var origImportNode = Document.prototype.importNode; + Document.prototype.importNode = function importNode(impNode, deep) { + deep = deep || false; + var newNode = origImportNode.call(this, impNode, deep); + if (impNode instanceof DocumentFragment) { + newNode.__proto__ = DocumentFragment.prototype; + } + return newNode; + }; + })(); + } + + // NOTE: we rely on this cloneNode not causing element upgrade. + // This means this polyfill must load before the CE polyfill and + // this would need to be re-worked if a browser supports native CE + // but not