Преглед изворни кода

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.
j8
Lyubomir Marinov пре 8 година
родитељ
комит
39483a30b6
1 измењених фајлова са 43 додато и 5 уклоњено
  1. 43
    5
      react/features/base/lib-jitsi-meet/native/polyfills-browser.js

+ 43
- 5
react/features/base/lib-jitsi-meet/native/polyfills-browser.js Прегледај датотеку

143
         const elementPrototype
143
         const elementPrototype
144
             = Object.getPrototypeOf(document.documentElement);
144
             = Object.getPrototypeOf(document.documentElement);
145
 
145
 
146
-        if (elementPrototype
147
-                && typeof elementPrototype.querySelector === 'undefined') {
148
-            elementPrototype.querySelector = function(selectors) {
149
-                return _querySelector(this, selectors);
150
-            };
146
+        if (elementPrototype) {
147
+            if (typeof elementPrototype.querySelector === 'undefined') {
148
+                elementPrototype.querySelector = function(selectors) {
149
+                    return _querySelector(this, selectors);
150
+                };
151
+            }
152
+
153
+            // Element.innerHTML
154
+            //
155
+            // Required by:
156
+            // - jQuery's .append method
157
+            if (!elementPrototype.hasOwnProperty('innerHTML')) {
158
+                Object.defineProperty(elementPrototype, 'innerHTML', {
159
+                    get() {
160
+                        return this.childNodes.toString();
161
+                    },
162
+
163
+                    set(innerHTML) {
164
+                        // MDN says: removes all of element's children, parses
165
+                        // the content string and assigns the resulting nodes as
166
+                        // children of the element.
167
+
168
+                        // Remove all of element's children.
169
+                        this.textContent = '';
170
+
171
+                        // Parse the content string.
172
+                        const d
173
+                            = new DOMParser().parseFromString(
174
+                                    `<div>${innerHTML}</div>`,
175
+                                    'text/xml');
176
+
177
+                        // Assign the resulting nodes as children of the
178
+                        // element.
179
+                        const documentElement = d.documentElement;
180
+                        let child;
181
+
182
+                        // eslint-disable-next-line no-cond-assign
183
+                        while (child = documentElement.firstChild) {
184
+                            this.appendChild(child);
185
+                        }
186
+                    }
187
+                });
188
+            }
151
         }
189
         }
152
 
190
 
153
         // FIXME There is a weird infinite loop related to console.log and
191
         // FIXME There is a weird infinite loop related to console.log and

Loading…
Откажи
Сачувај