Skip to content

Commit

Permalink
Try to fix safari mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
spolischook committed Mar 24, 2024
1 parent ea5229f commit 2ba7580
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions layouts/art-works/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,36 @@ <h1 class="text-4xl font-bold pb-2 text-tiger-300">{{ .Title }}</h1>
let unavailableToBuyButton = document.getElementById('unavailable-to-buy-button');
let buyButtonProcess = document.getElementById('buy-button-process');

buyButton.classList.add('hidden');
buyButtonProcess.classList.add('hidden');
// fixed page back from browser cache
window.addEventListener("pageshow",function(event) {
let historyTraversal = event.persisted ||
( typeof window.performance != "undefined" &&
window.performance.navigation.type === 2 );
if (historyTraversal) {
setupBuyButton();
}
});

const productId = '{{ (printf "gid://shopify/Product/%d" .Params.shopifyId) | base64Encode }}';
client.product.fetch(productId).then((product) => {
let available = false;
buyButtonSpinner.classList.add('hidden');
function setupBuyButton() {
buyButton.classList.add('hidden');
buyButtonProcess.classList.add('hidden');
buyButtonSpinner.classList.remove('hidden');
unavailableToBuyButton.classList.add('hidden');

if (!product) { unavailableToBuyButton.classList.remove('hidden'); return; }
if (!product.variants) { unavailableToBuyButton.classList.remove('hidden'); return; }
if (!product.variants[0].available) { unavailableToBuyButton.classList.remove('hidden'); return; }
const productId = '{{ (printf "gid://shopify/Product/%d" .Params.shopifyId) | base64Encode }}';
client.product.fetch(productId).then((product) => {
let available = false;
buyButtonSpinner.classList.add('hidden');

buyButton.classList.remove('hidden');
});
if (!product) { unavailableToBuyButton.classList.remove('hidden'); return; }
if (!product.variants) { unavailableToBuyButton.classList.remove('hidden'); return; }
if (!product.variants[0].available) { unavailableToBuyButton.classList.remove('hidden'); return; }

buyButton.classList.remove('hidden');
});
}

setupBuyButton();

buyButton.addEventListener('click', function() {
buyButton.classList.add('hidden');
Expand Down

0 comments on commit 2ba7580

Please sign in to comment.