Public Access
Fix 4 console errors: guard old slider code, guard spinner null, guard GSAP empty-grid targets, replace CORS fetch with form-based buyNow
This commit is contained in:
@@ -6,6 +6,7 @@ var si = 0,
|
||||
autoStop = false,
|
||||
autoInterval = 7000;
|
||||
|
||||
if (slides.length > 0 && dots.length > 0) {
|
||||
function show(i, direction) {
|
||||
if (direction === undefined) return;
|
||||
var current = slides[si];
|
||||
@@ -67,20 +68,6 @@ var si = 0,
|
||||
t = setInterval(nextSlide, autoInterval);
|
||||
}
|
||||
|
||||
window.addEventListener("load", function () {
|
||||
var o = document.getElementById("spinner");
|
||||
o.classList.add("hidden");
|
||||
setTimeout(function () {
|
||||
o.style.display = "none";
|
||||
}, 500);
|
||||
});
|
||||
setTimeout(function () {
|
||||
var o = document.getElementById("spinner");
|
||||
o.classList.add("hidden");
|
||||
setTimeout(function () {
|
||||
o.style.display = "none";
|
||||
}, 500);
|
||||
}, 3000);
|
||||
t = setInterval(nextSlide, autoInterval);
|
||||
|
||||
for (var s = 0; s < slides.length; s++) {
|
||||
@@ -90,6 +77,21 @@ var si = 0,
|
||||
t = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* spinner guard */
|
||||
(function() {
|
||||
var sp = document.getElementById("spinner");
|
||||
if (!sp) return;
|
||||
sp.classList.add("hidden");
|
||||
setTimeout(function() { sp.style.display = "none"; }, 500);
|
||||
setTimeout(function() {
|
||||
if (document.getElementById("spinner")) {
|
||||
document.getElementById("spinner").classList.add("hidden");
|
||||
document.getElementById("spinner").style.display = "none";
|
||||
}
|
||||
}, 3000);
|
||||
})();
|
||||
|
||||
document.querySelectorAll(".tab-btn").forEach(function (b) {
|
||||
b.addEventListener("click", function () {
|
||||
@@ -549,6 +551,7 @@ var si = 0,
|
||||
entries.forEach(function (entry) {
|
||||
if (!entry.isIntersecting) return;
|
||||
var grid = entry.target;
|
||||
if (!grid || !grid.children || grid.children.length === 0) return;
|
||||
var key = grid.className || 'anon';
|
||||
if (animated[key]) return;
|
||||
animated[key] = true;
|
||||
@@ -572,7 +575,9 @@ var si = 0,
|
||||
);
|
||||
grids.forEach(function (g) {
|
||||
/* Pre-set children invisible so no flash even before observer fires */
|
||||
gsap.set(g.children, { y: 30, opacity: 0 });
|
||||
if (g.children.length > 0) {
|
||||
gsap.set(g.children, { y: 30, opacity: 0 });
|
||||
}
|
||||
observer.observe(g);
|
||||
});
|
||||
})();
|
||||
@@ -622,15 +627,24 @@ var si = 0,
|
||||
});
|
||||
})();
|
||||
|
||||
/* Buy Now — POST product to Odoo shop basket, open cart in new window */
|
||||
/* Buy Now — POST product to Odoo shop basket via form to avoid CORS, open cart in new window */
|
||||
window.buyNow = function (productId) {
|
||||
fetch('https://ODOO4projects.com/shop/post_basket', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
basket: [{ product_id: productId, qty: 1 }],
|
||||
clear: '1'
|
||||
})
|
||||
}).catch(function () { /* ignore CORS / network errors */ });
|
||||
window.open('https://ODOO4projects.com/shop/cart', '_blank');
|
||||
var form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'https://ODOO4projects.com/shop/cart';
|
||||
form.target = '_blank';
|
||||
form.style.display = 'none';
|
||||
var pid = document.createElement('input');
|
||||
pid.type = 'hidden';
|
||||
pid.name = 'product_id';
|
||||
pid.value = productId;
|
||||
form.appendChild(pid);
|
||||
var qty = document.createElement('input');
|
||||
qty.type = 'hidden';
|
||||
qty.name = 'add_qty';
|
||||
qty.value = '1';
|
||||
form.appendChild(qty);
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
document.body.removeChild(form);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user