Skip to content

Commit 6626c65

Browse files
author
Avaer Kazmer
committed
Clean up demo page code generation
1 parent e6ca422 commit 6626c65

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

app.html

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,20 @@
152152
orbitControls.enableKeys = false;
153153
orbitControls.update();
154154

155-
// Listen to messages from parent window
155+
const _cleanupRoot = () => {
156+
while (root.firstChild && root.firstChild.nodeType === Node.TEXT_NODE) {
157+
root.removeChild(root.firstChild);
158+
}
159+
for (let el = root.firstChild; el; el = el.nextSibling) {
160+
while (el.nextSibling && el.nextSibling.nodeType === Node.TEXT_NODE) {
161+
el.parentNode.removeChild(el.nextSibling);
162+
}
163+
}
164+
const xrIframes = Array.from(root.childNodes);
165+
for (let i = 0; i < xrIframes.length; i++) {
166+
root.insertBefore(new Text('\n '), xrIframes[i]);
167+
}
168+
};
156169
window.addEventListener('message', e => {
157170
const {data} = e;
158171
const {method} = data;
@@ -173,15 +186,10 @@
173186
const xrIframes = Array.from(root.childNodes).filter(childNode => childNode instanceof XRIFrame);
174187
if (xrIframes.length > 0 && xrIframes[xrIframes.length - 1] === floorXrIframe) {
175188
root.insertBefore(xrIframe, floorXrIframe);
176-
root.insertBefore(new Text('\n '), floorXrIframe);
177189
} else {
178-
root.appendChild(new Text('\n '));
179190
root.appendChild(xrIframe);
180-
if (root.lastChild.nodeType !== Node.TEXT_NODE) {
181-
root.appendChild(new Text('\n'));
182-
}
183191
}
184-
192+
_cleanupRoot();
185193
_postTabs();
186194

187195
break;
@@ -193,10 +201,7 @@
193201
xrIframe.parentNode.removeChild(xrIframe.previousSibling);
194202
}
195203
xrIframe.parentNode.removeChild(xrIframe);
196-
if (!Array.from(root.childNodes).some(childNode => childNode instanceof XRIFrame)) {
197-
root.innerHTML = '';
198-
}
199-
204+
_cleanupRoot();
200205
_postTabs();
201206

202207
break;

0 commit comments

Comments
 (0)