(function() {
// Block JetEngine from requesting geolocation on load
let blocked = false;
const originalGeo = navigator.geolocation.getCurrentPosition;
navigator.geolocation.getCurrentPosition = function(success, error, options) {
// Block first auto-call (from JetEngine), allow future ones
if (!blocked) {
blocked = true;
console.log("JetEngine geolocation auto-request blocked.");
return;
}
// Allow manual calls (i.e. after user clicks the button)
originalGeo.call(navigator.geolocation, success, error, options);
};
// Set up manual location trigger
document.addEventListener("DOMContentLoaded", function() {
const btn = document.getElementById("get-location-button");
if (!btn) return;
btn.addEventListener("click", function() {
if (!navigator.geolocation) {
alert("Geolocation is not supported.");
return;
}
navigator.geolocation.getCurrentPosition(function(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
console.log("User location acquired:", lat, lng);
// Store location where JetEngine expects it
window.JetEngineGeoData = {
lat: lat,
lng: lng,
timestamp: Date.now()
};
// Notify JetEngine to update geolocation filters
document.dispatchEvent(new CustomEvent('jet-engine-geolocation-updated', {
detail: {
lat: lat,
lng: lng
}
}));
// Optionally refresh filters if using JetSmartFilters
if (typeof JetSmartFilters !== 'undefined') {
// JetSmartFilters.filters.forEach(filter => filter.applyFilter());
Object.values(JetSmartFilters.filters).forEach(filter => {
if (typeof filter.applyFilter === 'function') {
filter.applyFilter();
}
});
}
}, function() {
alert("Location access denied.");
});
});
});
})();
navigator.geolocation.getCurrentPosition(
function success(position) {
// They allowed location
console.log('Location access granted');
},
function error(err) {
if (err.code === err.PERMISSION_DENIED) {
// This runs after they click "Never" or "Block"
console.log('Location access denied');
window.location.href = '/location-denied.html';
}
}
);