From 39483a30b6ec5d8b02c1680e64abee1d203b6c3c Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Wed, 15 Feb 2017 11:04:10 -0600 Subject: [PATCH] Polyfill Element.innerHTML Lib-jitsi-meet uses jQuery's .append method to manipulate Jingle. The method in question invokes the getter and setter of Element.innerHTML. Unfortunately, xmldom which we use in React Native to polyfill DOM does not polyfill Element.innerHTML. So polyfill it ourselves. --- .../native/polyfills-browser.js | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js b/react/features/base/lib-jitsi-meet/native/polyfills-browser.js index 12ef0ade8..381c5a0d8 100644 --- a/react/features/base/lib-jitsi-meet/native/polyfills-browser.js +++ b/react/features/base/lib-jitsi-meet/native/polyfills-browser.js @@ -143,11 +143,49 @@ function _visitNode(node, callback) { const elementPrototype = Object.getPrototypeOf(document.documentElement); - if (elementPrototype - && typeof elementPrototype.querySelector === 'undefined') { - elementPrototype.querySelector = function(selectors) { - return _querySelector(this, selectors); - }; + if (elementPrototype) { + if (typeof elementPrototype.querySelector === 'undefined') { + elementPrototype.querySelector = function(selectors) { + return _querySelector(this, selectors); + }; + } + + // Element.innerHTML + // + // Required by: + // - jQuery's .append method + if (!elementPrototype.hasOwnProperty('innerHTML')) { + Object.defineProperty(elementPrototype, 'innerHTML', { + get() { + return this.childNodes.toString(); + }, + + set(innerHTML) { + // MDN says: removes all of element's children, parses + // the content string and assigns the resulting nodes as + // children of the element. + + // Remove all of element's children. + this.textContent = ''; + + // Parse the content string. + const d + = new DOMParser().parseFromString( + `
${innerHTML}
`, + 'text/xml'); + + // Assign the resulting nodes as children of the + // element. + const documentElement = d.documentElement; + let child; + + // eslint-disable-next-line no-cond-assign + while (child = documentElement.firstChild) { + this.appendChild(child); + } + } + }); + } } // FIXME There is a weird infinite loop related to console.log and