Sha256: 00d34fa071295fd39ad8ae5637ee61475e2180599ed18a6f90d9923f18331f03
Contents?: true
Size: 1.55 KB
Versions: 5
Compression:
Stored size: 1.55 KB
Contents
document.addEventListener('turbolinks:load', function(event) { // this condition checks if this is the first initial load of turbolinks application if (!event.data.timing.visitStart) { var currencySelect = document.querySelectorAll('select[name=switch_to_currency]') if (currencySelect.length) { currencySelect.forEach(function (element) { element.addEventListener('change', function () { Spree.showProgressBar() var newCurrency = this.value // we need to make AJAX call here to the backend to set currency in session fetch(Spree.routes.set_currency(newCurrency), { method: 'GET' }).then(function (response) { switch (response.status) { case 200: Spree.setCurrency(newCurrency) document.getElementById('internationalization-options-desktop').classList.remove('show') break } }) }) }) } } }) // fix back button issue with different currency set // invalidate page if cached page has different currency then the current one document.addEventListener('turbolinks:load', function(event) { if (SPREE_CURRENCY === SPREE_DEFAULT_CURRENCY) { var regexAnyCurrency = new RegExp('currency=') if (event.data.url.match(regexAnyCurrency) && !event.data.url.match(SPREE_CURRENCY)) { Spree.setCurrency(SPREE_CURRENCY) } } else { var regex = new RegExp('currency=' + SPREE_CURRENCY) if (!event.data.url.match(regex)) { Spree.setCurrency(SPREE_CURRENCY) } } })
Version data entries
5 entries across 5 versions & 1 rubygems