fb32f28bd4
- Add schema.org JSON-LD to page, service, and location templates (LocalBusiness / Service / FAQPage) - Inject schema_json via _header.php <script type="application/ld+json"> block - Fix sitemap.xml: replace 10 stale .html refs with trailing-slash URLs, add /blog/, update lastmod - nginx: rate-limit /contact/ POST-only via map $request_method (GET no longer hits 429) - Topbar: remove dismiss button, always visible for session; popup close no longer hides topbar Verified: all 17 routes 200, JSON-LD present on home/service/location/contact, sitemap 17 URLs no .html Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
104 lines
3.2 KiB
JavaScript
104 lines
3.2 KiB
JavaScript
(function () {
|
|
var POPUP_KEY = 'flooritPromo2026';
|
|
var DELAY_MS = 5000;
|
|
var EXPIRY_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
function isStored(key) {
|
|
try {
|
|
var val = localStorage.getItem(key);
|
|
return val && Date.now() < parseInt(val, 10);
|
|
} catch (e) { return false; }
|
|
}
|
|
|
|
function store(key) {
|
|
try { localStorage.setItem(key, String(Date.now() + EXPIRY_MS)); } catch (e) {}
|
|
}
|
|
|
|
/* --- Topbar (always visible, no dismiss) --------------- */
|
|
function initTopbar() {
|
|
var bar = document.getElementById('promo-topbar');
|
|
var offerBtn = document.getElementById('promo-topbar-btn');
|
|
if (!bar) return;
|
|
bar.classList.add('visible');
|
|
document.body.classList.add('has-topbar');
|
|
if (offerBtn) offerBtn.addEventListener('click', openPopup);
|
|
}
|
|
|
|
/* --- Popup --------------------------------------------- */
|
|
function openPopup() {
|
|
var overlay = document.getElementById('promo-overlay');
|
|
if (!overlay) return;
|
|
overlay.style.display = 'flex';
|
|
requestAnimationFrame(function () {
|
|
requestAnimationFrame(function () { overlay.classList.add('visible'); });
|
|
});
|
|
}
|
|
|
|
function closePopup() {
|
|
var overlay = document.getElementById('promo-overlay');
|
|
if (overlay) {
|
|
overlay.classList.remove('visible');
|
|
setTimeout(function () { overlay.style.display = 'none'; }, 350);
|
|
}
|
|
store(POPUP_KEY);
|
|
}
|
|
|
|
function initPopup() {
|
|
if (isStored(POPUP_KEY)) return;
|
|
var closeBtn = document.getElementById('promo-close');
|
|
var overlay = document.getElementById('promo-overlay');
|
|
var form = document.getElementById('promo-form');
|
|
var submit = document.getElementById('promo-submit');
|
|
var errEl = document.getElementById('promo-error');
|
|
var success = document.getElementById('promo-success');
|
|
if (!overlay || !form) return;
|
|
|
|
if (closeBtn) closeBtn.addEventListener('click', closePopup);
|
|
overlay.addEventListener('click', function (e) {
|
|
if (e.target === overlay) closePopup();
|
|
});
|
|
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
errEl.style.display = 'none';
|
|
submit.disabled = true;
|
|
submit.textContent = 'Sending...';
|
|
var data = new FormData(form);
|
|
fetch('/promo/', { method: 'POST', body: data })
|
|
.then(function (r) { return r.json(); })
|
|
.then(function (res) {
|
|
if (res.ok) {
|
|
form.style.display = 'none';
|
|
success.style.display = 'block';
|
|
store(POPUP_KEY);
|
|
hideTopbar();
|
|
} else {
|
|
errEl.textContent = res.error || 'Something went wrong.';
|
|
errEl.style.display = 'block';
|
|
submit.disabled = false;
|
|
submit.textContent = 'Claim My Discount';
|
|
}
|
|
})
|
|
.catch(function () {
|
|
errEl.textContent = 'Network error. Please try again.';
|
|
errEl.style.display = 'block';
|
|
submit.disabled = false;
|
|
submit.textContent = 'Claim My Discount';
|
|
});
|
|
});
|
|
|
|
setTimeout(openPopup, DELAY_MS);
|
|
}
|
|
|
|
function init() {
|
|
initTopbar();
|
|
initPopup();
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
} else {
|
|
init();
|
|
}
|
|
})();
|