forked from Shopify/dawn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct-model.js
59 lines (50 loc) · 1.32 KB
/
product-model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
if (!customElements.get('product-model')) {
customElements.define(
'product-model',
class ProductModel extends DeferredMedia {
constructor() {
super();
}
loadContent() {
super.loadContent();
Shopify.loadFeatures([
{
name: 'model-viewer-ui',
version: '1.0',
onLoad: this.setupModelViewerUI.bind(this),
},
]);
}
setupModelViewerUI(errors) {
if (errors) return;
this.modelViewerUI = new Shopify.ModelViewerUI(this.querySelector('model-viewer'));
}
}
);
}
window.ProductModel = {
loadShopifyXR() {
Shopify.loadFeatures([
{
name: 'shopify-xr',
version: '1.0',
onLoad: this.setupShopifyXR.bind(this),
},
]);
},
setupShopifyXR(errors) {
if (errors) return;
if (!window.ShopifyXR) {
document.addEventListener('shopify_xr_initialized', () => this.setupShopifyXR());
return;
}
document.querySelectorAll('[id^="ProductJSON-"]').forEach((modelJSON) => {
window.ShopifyXR.addModels(JSON.parse(modelJSON.textContent));
modelJSON.remove();
});
window.ShopifyXR.setupXRElements();
},
};
window.addEventListener('DOMContentLoaded', () => {
if (window.ProductModel) window.ProductModel.loadShopifyXR();
});