Skip to content

Commit 5302a41

Browse files
author
Avaer Kazmer
committed
Add xr-engine-template unpack shim for recursive loading
1 parent 8d97034 commit 5302a41

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Window.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,36 @@ const vrPresentState = {
6767
};
6868
GlobalContext.vrPresentState = vrPresentState;
6969

70+
// unpack xr-engine-template in recursive load scenario
71+
class XREngineTemplate extends HTMLTemplateElement {
72+
constructor() {
73+
super();
74+
75+
(async () => {
76+
if (document.readyState !== 'complete') {
77+
await new Promise((accept, reject) => {
78+
document.addEventListener('readystatechange', () => {
79+
if (document.readyState === 'complete') {
80+
accept();
81+
}
82+
});
83+
});
84+
}
85+
const childNodes = Array.from(this.content.childNodes);
86+
for (let i = 0; i < childNodes.length; i++) {
87+
const childNode = childNodes[i];
88+
if (childNode.nodeType === Node.ELEMENT_NODE) {
89+
const xrIframe = document.importNode(childNode, true);
90+
this.insertAdjacentElement('afterend', xrIframe);
91+
}
92+
}
93+
})();
94+
}
95+
}
96+
customElements.define('xr-engine-template', XREngineTemplate, {
97+
extends: 'template',
98+
});
99+
70100
class PaymentRequest {
71101
constructor(methodData, details, options) {
72102
this.methodData = methodData;

0 commit comments

Comments
 (0)