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:
2026-08-21 21:59:12 +00:00
parent 284f59f863
commit d58089d194
+39 -25
View File
@@ -6,6 +6,7 @@ var si = 0,
autoStop = false, autoStop = false,
autoInterval = 7000; autoInterval = 7000;
if (slides.length > 0 && dots.length > 0) {
function show(i, direction) { function show(i, direction) {
if (direction === undefined) return; if (direction === undefined) return;
var current = slides[si]; var current = slides[si];
@@ -67,20 +68,6 @@ var si = 0,
t = setInterval(nextSlide, autoInterval); 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); t = setInterval(nextSlide, autoInterval);
for (var s = 0; s < slides.length; s++) { for (var s = 0; s < slides.length; s++) {
@@ -90,6 +77,21 @@ var si = 0,
t = null; 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) { document.querySelectorAll(".tab-btn").forEach(function (b) {
b.addEventListener("click", function () { b.addEventListener("click", function () {
@@ -549,6 +551,7 @@ var si = 0,
entries.forEach(function (entry) { entries.forEach(function (entry) {
if (!entry.isIntersecting) return; if (!entry.isIntersecting) return;
var grid = entry.target; var grid = entry.target;
if (!grid || !grid.children || grid.children.length === 0) return;
var key = grid.className || 'anon'; var key = grid.className || 'anon';
if (animated[key]) return; if (animated[key]) return;
animated[key] = true; animated[key] = true;
@@ -572,7 +575,9 @@ var si = 0,
); );
grids.forEach(function (g) { grids.forEach(function (g) {
/* Pre-set children invisible so no flash even before observer fires */ /* 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); 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) { window.buyNow = function (productId) {
fetch('https://ODOO4projects.com/shop/post_basket', { var form = document.createElement('form');
method: 'POST', form.method = 'POST';
headers: { 'Content-Type': 'application/json' }, form.action = 'https://ODOO4projects.com/shop/cart';
body: JSON.stringify({ form.target = '_blank';
basket: [{ product_id: productId, qty: 1 }], form.style.display = 'none';
clear: '1' var pid = document.createElement('input');
}) pid.type = 'hidden';
}).catch(function () { /* ignore CORS / network errors */ }); pid.name = 'product_id';
window.open('https://ODOO4projects.com/shop/cart', '_blank'); 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);
}; };