/
index.js
84 lines (69 loc) · 2.94 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/* eslint-env browser */
import GLightbox from 'glightbox';
import axios from 'axios';
import 'bootstrap.native/dist/bootstrap-native';
import SyliusRating from './sylius-rating';
import SyliusToggle from './sylius-toggle';
import SyliusAddToCart from './sylius-add-to-cart';
import SyliusRemoveFromCart from './sylius-remove-from-cart';
import SyliusApiToggle from './sylius-api-toggle';
import SyliusApiLogin from './sylius-api-login';
import SyliusVariantsPrices from './sylius-variants-prices';
import SyliusVariantImages from './sylius-variant-images';
import SyliusProvinceField from './sylius-province-field';
import SyliusAddressBook from './sylius-address-book';
import SyliusLoadableForms from './sylius-loadable-forms';
// Global axios settings
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
axios.defaults.headers.post.accept = 'application/json, text/javascript, */*; q=0.01';
axios.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest';
document.addEventListener('DOMContentLoaded', () => {
// Lightbox
const glightbox = GLightbox({ selector: '.glightbox' });
// Add to cart
document.querySelectorAll('[data-js-add-to-cart="form"]')
.forEach(el => SyliusAddToCart(el));
// Remove from cart
document.querySelectorAll('[data-js-remove-from-cart-button]')
.forEach(el => SyliusRemoveFromCart(el));
// Province field
SyliusProvinceField();
// Address book
const syliusShippingAddress = document.querySelector('[data-js-address-book="sylius-shipping-address"]');
if (syliusShippingAddress && syliusShippingAddress.querySelector('.dropdown')) {
SyliusAddressBook(syliusShippingAddress);
}
const syliusBillingAddress = document.querySelector('[data-js-address-book="sylius-billing-address"]');
if (syliusBillingAddress && syliusBillingAddress.querySelector('.dropdown')) {
SyliusAddressBook(syliusBillingAddress);
}
// Variant prices
SyliusVariantsPrices();
// Star rating
document.querySelectorAll('[data-js-rating]').forEach((elem) => {
new SyliusRating(elem, {
onRate(value) {
document.querySelector(`#sylius_product_review_rating_${value - 1}`).checked = true;
},
});
});
// Toggle and login from checkout
if (document.querySelector('[data-js-login]')) {
SyliusApiToggle(document.querySelector('[data-js-login="email"]'));
SyliusApiLogin(document.querySelector('[data-js-login]'));
}
// Toggle billing address on the checkout page
document.querySelectorAll('[data-js-toggle]').forEach(elem => new SyliusToggle(elem));
// Product images for variants
if (document.querySelector('[data-variant-options], [data-variant-code]')) { new SyliusVariantImages(); }
// Loadable forms
SyliusLoadableForms();
});