-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.js
65 lines (56 loc) · 2.31 KB
/
product.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
60
61
62
63
64
65
import Updater from '../updater';
import normalizeConfig from '../utils/normalize-config';
const MAX_WIDTH = '950px';
export default class ProductUpdater extends Updater {
updateConfig(config) {
const newConfig = normalizeConfig(config);
if (newConfig.storefrontId || newConfig.storefrontVariantId) {
this.component.storefrontId = newConfig.storefrontId || this.component.storefrontId;
this.component.defaultStorefrontVariantId = newConfig.storefrontVariantId || this.component.defaultStorefrontVariantId;
this.component.init();
return;
}
let layout = this.component.options.layout;
if (config.options && config.options.product) {
if (config.options.product.layout) {
layout = config.options.product.layout;
}
if (this.component.view.iframe) {
if (layout === 'vertical' && this.component.view.iframe.width === MAX_WIDTH) {
this.component.view.iframe.setWidth(this.component.options.width);
}
if (layout === 'horizontal' && this.component.view.iframe.width && this.component.view.iframe.width !== MAX_WIDTH) {
this.component.view.iframe.setWidth(MAX_WIDTH);
}
if (config.options.product.width && layout === 'vertical') {
this.component.view.iframe.setWidth(config.options.product.width);
}
if (config.options.product.layout) {
this.component.view.iframe.el.style.width = '100%';
}
}
}
if (this.component.view.iframe) {
this.component.view.iframe.removeClass(this.component.classes.product.vertical);
this.component.view.iframe.removeClass(this.component.classes.product.horizontal);
this.component.view.iframe.addClass(this.component.classes.product[layout]);
this.component.view.resize();
}
[...this.component.view.wrapper.querySelectorAll('img')].forEach((img) => {
img.addEventListener('load', () => {
this.component.view.resize();
});
});
super.updateConfig(config);
if (this.component.cart) {
this.component.cart.updateConfig(config);
}
if (this.component.modal) {
this.component.modal.updateConfig(Object.assign({}, config, {
options: Object.assign({}, this.component.config, {
product: this.component.modalProductConfig,
}),
}));
}
}
}